I was working with a templated class which takes a set of integers. The code was like,
template
struct work{ ... };
I'm not entirely sure what you are asking about. I thought the sample you gave was interesting and played a little bit with it.
I came up with an implementation that makes span to be a template alias for indexes, using the trick of type deduction in constexpr functions:
template using span = decltype(expand_span());
Now you can have your cake and eat it:
////////////////////////////////////////////////////////////////
// using indirect template arguments
template struct indirect_work { };
void test_indirect()
{
indirect_work> x;
indirect_work> y;
x = y; // x and y are of identical types
static_assert(std::is_same, span<1,4>>::value, "fact check");
}
But, perhaps more interestingly, you can still have your primary work template take a raw template argument list:
////////////////////////////////////////////////////////////////
// using direct template arguments
template struct direct_work { };
// deduction alias:
template constexpr direct_work deduction_helper(indexes);
template using deduce = decltype(deduction_helper(Idx{}));
void test_direct()
{
direct_work<1,2,3,4> x;
deduce> y;
deduce> z;
static_assert(std::is_same::value, "fact check");
static_assert(std::is_same::value, "fact check");
}
See a complete working demonstration here: gcc on ideone. I compiled it with clang locally.
Code for expand_span duplicated here in case link should go dead:
#include
template struct indexes {};
namespace {
template
constexpr indexes combine(indexes deduce);
template struct expand_span_; // primary
template
struct expand_span_::type> {
static constexpr indexes dispatch();
};
template
struct expand_span_::type> {
static constexpr decltype(combine(expand_span_::dispatch()))
dispatch();
};
template
constexpr auto expand_span() -> decltype(expand_span_::dispatch());
}
template using span = decltype(expand_span());
////////////////////////////////////////////////////////////////
// using indirect template arguments
template struct indirect_work { };
void test_indirect()
{
indirect_work> x;
indirect_work> y;
x = y; // x and y are of identical types
static_assert(std::is_same, span<1,4>>::value, "fact check");
}
////////////////////////////////////////////////////////////////
// using direct template arguments
template struct direct_work { };
// deduction alias:
template constexpr direct_work deduction_helper(indexes);
template using deduce = decltype(deduction_helper(Idx{}));
void test_direct()
{
direct_work<1,2,3,4> x;
deduce> y;
deduce> z;
static_assert(std::is_same::value, "fact check");
static_assert(std::is_same::value, "fact check");
}
int main()
{
test_indirect();
test_direct();
}