Skip to content

Commit 1755aab

Browse files
committed
enable implicit conversion when List can be constructed from U
1 parent 76b0b98 commit 1755aab

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎inst/include/Rcpp/vector/ListOf.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ class ListOf
4040
std::transform(list.begin(), list.end(), list.begin(), as<T>);
4141
}
4242

43-
template <typename U,
44-
typename std::enable_if<std::is_convertible<U, SEXP>::value, int>::type = 0>
45-
ListOf(const U& data_): ListOf(static_cast<SEXP>(data_)) {}
43+
// enabled only when List itself can be constructed from data_, so this
44+
// does not compete with a converting operator T() offered by data_'s own
45+
// type while preserving every constructor List/Vector accepts
46+
// (SEXP, size, Dimension, wrap()-able third-party types, ...)
47+
template <typename U, typename = decltype(List(std::declval<const U&>()))>
48+
ListOf(const U& data_): list(data_) {
49+
std::transform(list.begin(), list.end(), list.begin(), as<T>);
50+
}
4651

4752
ListOf(const ListOf& other): list(other.list) {}
4853

0 commit comments

Comments
 (0)