これは楽しいことでした。ここに私の解決策は次のとおりです。
namespace details {
template <size_t N, class F = size_t()>
struct Function_type_helper {};
template <size_t N, class... Args>
struct Function_type_helper<N, size_t(Args...)> {
using Type = typename Function_type_helper<N - 1, size_t(Args..., size_t)>::Type;
};
template <class... Args>
struct Function_type_helper<0, size_t(Args...)> {
using Type = size_t(Args...);
};
template <size_t N, class F = size_t()>
using Function_type_helper_t = typename Function_type_helper<N, F>::Type;
static_assert(std::is_same_v<Function_type_helper_t<3>, size_t(size_t, size_t, size_t)>);
} // ns details
template<size_t N>
struct A
{
std::function<details::Function_type_helper_t<N>> foo;
};
これは再帰的にインスタンスのタイプにsize_t(size_t, size_t, ..., size_t)
を作成することで動作します。
H<3>::Type == H<3, size_t()>::Type ==
H<2, size_t(size_t)>::Type ==
H<1, size_t(size_t, size_t)>::Type ==
H<0, size_t(size_t, size_t, size_t)>::Type ==
size_t(size_t, size_t, size_t)
優れたソリューションを。私よりもクリーナー。 – bolov
定義を見つけるのに苦労している人のために: 'std :: index_sequence'は、 ''で定義されているヘルパーエイリアスです。[ヘルパーエイリアステンプレート\ [of '' std :: integer_sequence' \ 'std :: size_t'](http://en.cppreference.com/w/cpp/utility/integer_sequence#Helper_templates)です。" –
そしてもう少し一般的には、make_type_wrapper = T;を使って 'templateテンプレートを持つことができます。そのようにして、' size_t'以外のものを署名として使用したい場合は、 –
SirGuy