Bee*_*ope 11 c++ templates c++14
也就是说,将其constexpr std::array<int,2>{1,2}传递给将吐出类型的某些函数或帮助器类std::integer_sequence<int, 1, 2>?
It seems easy to jump from the type world to the "constexpr value" world (e.g., to do the reverse conversion), but hard or impossible to do the reverse.
似乎您可以在C ++ 17中做到这一点,但要在调用站点上引入lambda:
template <size_t N, typename F, size_t... indexes>
constexpr auto make_seq_helper(F f, std::index_sequence<indexes...> is) {
return std::integer_sequence<int, std::get<indexes>(f())...>{};
}
template <typename F>
constexpr auto make_seq(F f) {
constexpr size_t N = f().size();
using indexes = std::make_index_sequence<N>;
return make_seq_helper<N>(f, indexes{});
};
Run Code Online (Sandbox Code Playgroud)
make_seq像这样调用:
constexpr std::array a{7, 15, 28};
auto x = make_seq([](){ return a; });
Run Code Online (Sandbox Code Playgroud)
结果为xwith类型std::integer_sequence<int, 7, 15, 28>。我不确定lambda用法是否可以删除。