[英]C++1y/C++14: Converting static constexpr array to non-type template parameter pack?
假設我有一個靜態存儲持續時間的constexpr數組(已知綁定):
constexpr T input[] = /* ... */;
我有一個需要包的輸出類模板:
template<T...> struct output_template;
我想實例化output_template
如:
using output = output_template<input[0], input[1], ..., input[n-1]>;
一種方法是:
template<size_t n, const T (&a)[n]>
struct make_output_template
{
template<size_t... i> static constexpr
output_template<a[i]...> f(std::index_sequence<i...>)
{ return {}; };
using type = decltype(f(std::make_index_sequence<n>()));
};
using output = make_output_template<std::extent_v<decltype(input)>, input>::type;
我缺少更清潔或更簡單的解決方案嗎?
也許你認為這更清潔:
template< const T* a, typename >
struct make_output_template;
template< const T* a, std::size_t... i >
struct make_output_template< a, std::index_sequence< i... > >
{
using type = output_template< a[ i ]... >;
};
同
using output = make_output_template<
input,
std::make_index_sequence< std::extent_v< decltype( input ) > >
>::type;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.