src: Robust make_array implementation

This is meant to be used for ints, but unfortunately std::forward is
not constexpr in C++11.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-09-24 23:37:25 +09:00
parent 1e96a2d357
commit bff59e09dc
1 changed files with 9 additions and 4 deletions

View File

@ -45,10 +45,15 @@ make_unique(size_t size) {
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
}
template <typename T, typename... Rest>
std::array<T, sizeof...(Rest)+1> make_array(T &&t, Rest &&... rest) {
return std::array<T, sizeof...(Rest)+1>{
{std::forward<T>(t), std::forward<Rest>(rest)...}};
// std::forward is conexpr since C++14
template <typename... T>
constexpr std::array<
typename std::decay<typename std::common_type<T...>::type>::type,
sizeof...(T)>
make_array(T &&... t) {
return std::array<
typename std::decay<typename std::common_type<T...>::type>::type,
sizeof...(T)>{{std::forward<T>(t)...}};
}
template <typename T, size_t N> constexpr size_t array_size(T (&)[N]) {