Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(Proof-of-concept) C++17 make_array implementation
template <class T = void, class... Args>
constexpr auto make_array(Args&&... t) {
// T is not void: deduced array type is T
if constexpr (!std::is_same<T, void>()) {
return std::array<T, sizeof...(Args)> { std::forward<Args>(t)... };
}
// T is void: deduced array type is U = std::common_type_t<Args...>
using U = std::common_type_t<Args...>;
// T is void and one of the argument is a specialization of std::reference_wrapper<U>: ill-formed
static_assert(!std::disjunction_v<std::is_same<std::reference_wrapper<U>, Args>...>, "reference_wrappers are not allowed");
return std::array<U, sizeof...(Args)> { std::forward<Args>(t)... };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.