std::meta::is_template
From cppreference.com
| Defined in header <meta>
|
||
consteval bool is_template( std::meta::info r );
|
(since C++26) | |
Returns true if r represents a function template, class template, variable template, alias template, or concept. Otherwise returns false.
Parameters
| r | - | a reflection value |
Return value
true if r represents a template; otherwise false.
Notes
A template specialization is not a template. For example,
std::meta::is_template(^^std::hive) is true but
std::meta::is_template(^^std::hive<long>) is false.
Example
Run this code
#include <cstddef>
#include <list>
#include <meta>
#include <type_traits>
// function
void fun1();
static_assert(!std::meta::is_template(^^fun1));
// function template
template<int>
void fun2();
static_assert(std::meta::is_template(^^fun2));
// variable
char var1[42]{};
static_assert(!std::meta::is_template(^^var1));
// variable template
template<std::size_t N>
char var2[N]{};
static_assert(std::meta::is_template(^^var2));
// class
struct S1;
static_assert(!std::meta::is_template(^^S1));
// class template
template<class T>
struct S2;
static_assert(std::meta::is_template(^^S2));
// type alias
using Int = int;
static_assert(!std::meta::is_template(^^Int));
// type alias template
template<typename T>
using List = std::list<T>;
static_assert(std::meta::is_template(^^List));
struct S3
{
// conversion function
operator int();
// conversion function template
template<typename T>
operator float();
// operator function
int operator[](int);
// operator function template
template<typename T>
int operator+=(const S3&);
};
static_assert(!std::meta::is_template(^^S3::operator int));
static_assert(std::meta::is_template(^^S3::operator float));
static_assert(!std::meta::is_template(^^S3::operator[]));
static_assert(std::meta::is_template(^^S3::operator+=));
// concept is a template
template<class T, class U>
concept Derived = std::is_base_of<U, T>::value;
static_assert(std::meta::is_template(^^Derived));
int main() {}
See also
(C++26) |
checks if reflected entity is a function template (function) |
(C++26) |
checks if reflected entity is a variable template (function) |
(C++26) |
checks if reflected entity is a class template (function) |
(C++26) |
checks if reflected entity is a alias template (function) |
| checks if reflected entity is a conversion function template (function) | |
| checks if reflected entity is an operator function template (function) | |
(C++26) |
checks if reflected entity is a literal operator template (function) |
(C++26) |
checks if reflected entity is a constructor template (function) |
(C++26) |
checks if reflection represents a concept (function) |
(C++26) |
checks if reflected entity is produced by substituting template arguments into a template (function) |
(C++26) |
obtains the template arguments of the reflected entity (function) |
(C++26) |
determines the template used to instantiate the reflected entity (function) |