template <class D, class...>
struct return_type_helper
{
using type = D;
};
template <class... Types>
struct return_type_helper<void, Types...> : std::common_type<Types...>
{
static_assert(
// why can't I use reference wrappers?
std::conjunction_v<not_ref_wrapper<Types>...>,
"Types cannot contain reference_wrappers when D is void"
);
};
template <class D = void, class... Types>
constexpr std::array<typename return_type_helper<D, Types...>::type, sizeof...(Types)> make_array(Types&&... t)
{
return {std::forward<Types>(t)...};
}
void foo()
{
int x = 7355608;
auto arr = make_array(std::ref(x)); // does not compile
}
Why does std::experimental::make_array() have a static_assert() that disallows use of std::reference_wrapper when the type of the array is automatically deduced? Creating an array of reference wrappers is otherwise perfectly legal, that is the compiler has no problem with
auto arr2 = std::array<decltype(std::ref(x)),1>{std::ref(x)};