From bff59e09dcb088c57212c01021dad2d2927ea267 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 24 Sep 2015 23:37:25 +0900 Subject: [PATCH] src: Robust make_array implementation This is meant to be used for ints, but unfortunately std::forward is not constexpr in C++11. --- src/template.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/template.h b/src/template.h index 7a9c3623..26ebc444 100644 --- a/src/template.h +++ b/src/template.h @@ -45,10 +45,15 @@ make_unique(size_t size) { return std::unique_ptr(new typename std::remove_extent::type[size]()); } -template -std::array make_array(T &&t, Rest &&... rest) { - return std::array{ - {std::forward(t), std::forward(rest)...}}; +// std::forward is conexpr since C++14 +template +constexpr std::array< + typename std::decay::type>::type, + sizeof...(T)> +make_array(T &&... t) { + return std::array< + typename std::decay::type>::type, + sizeof...(T)>{{std::forward(t)...}}; } template constexpr size_t array_size(T (&)[N]) {