non-type template template arguments?

75 views
Skip to first unread message

swa...@gmail.com

unread,
Jul 26, 2017, 11:42:24 AM7/26/17
to ISO C++ Standard - Discussion
Hi.

So I was wondering why template template argument are only allowed to be "typename" or "class" as since C++14's we have templated global/static variables.
It would allow for things like this.
template <class T>
static constexpr int value = someFunc<T>();

template<template<class> int>
struct Smthg
{
   
...
};

int main()
{
   
Smthg<value> t;
}

Or even things like this with use of C++17's auto non-type template parameter.
struct holder
{
     
...
     
template <template<class> auto& Func>
     
constexpr auto visit() { ... }
     
...
};

template <class T>
void printType() { ... }

template <class T>
static constexpr size_t size_of = []() {
     
return sizeof(T);
};

int main()
{
   
auto t = returns_holder();
    t
.visit<printType>();
    std
::cout << t << t.visit<sizeo_of>() << std::endl;
}

jakob....@gmail.com

unread,
Oct 19, 2017, 4:34:37 AM10/19/17
to ISO C++ Standard - Discussion, swa...@gmail.com
+1, I like this idea.

Jakob

tko...@google.com

unread,
Oct 19, 2017, 7:16:04 PM10/19/17
to ISO C++ Standard - Discussion, swa...@gmail.com
If you want to allow variable templates as template template parameters, why not also allow function templates?
Reply all
Reply to author
Forward
0 new messages