Created
September 2, 2017 14:09
-
-
Save stevefan1999-personal/a5067006cbe7e425f737da5c84b30034 to your computer and use it in GitHub Desktop.
(Proof-of-concept) C++17 make_array implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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