Spec-Zone.ru › C++

std::meta::is_template

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

#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

is_function_template
(C++26)
checks if reflected entity is a function template
(function)
is_variable_template
(C++26)
checks if reflected entity is a variable template
(function)
is_class_template
(C++26)
checks if reflected entity is a class template
(function)
is_alias_template
(C++26)
checks if reflected entity is a alias template
(function)
is_conversion_function_template
(C++26)
checks if reflected entity is a conversion function template
(function)
is_operator_function_template
(C++26)
checks if reflected entity is an operator function template
(function)
is_literal_operator_template
(C++26)
checks if reflected entity is a literal operator template
(function)
is_constructor_template
(C++26)
checks if reflected entity is a constructor template
(function)
is_concept
(C++26)
checks if reflection represents a concept
(function)
has_template_arguments
(C++26)
checks if reflected entity is produced by substituting template arguments into a template
(function)
template_arguments_of
(C++26)
obtains the template arguments of the reflected entity
(function)
template_of
(C++26)
determines the template used to instantiate the reflected entity
(function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/is_template

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API