Spec-Zone.ru › C++

std::meta::can_substitute

Defined in header <meta>
template< std::meta::reflection_range R = std::initializer_list<std::meta::info> >
consteval bool can_substitute( std::meta::info templ, R&& arguments );
(since C++26)

Let Z denote the template represented by templ, Args... denote the values, types, or templates represented by successive elements of arguments, determines whether Z<Args...> is a valid template-id.

Returns true if Z<Args...> is valid and does not name a function with undeduced placeholder return type; otherwise returns false.

Parameters

templ - a reflection of template
arguments - a range of reflections

Return value

A boolean value indicating whether substitution is valid.

Exceptions

Throws std::meta::exception unless templ represents a template, and each element of arguments represents a construct suitable as a template argument.

Notes

If forming Z<Args...> leads to a failure outside of the immediate context, the program is ill-formed.

Example

#include <meta>
#include <tuple>

static_assert(std::meta::can_substitute(^^std::tuple, {^^void}));
static_assert(can_substitute(^^std::tuple, {^^int, ^^int})); // using argument-dependent lookup
static_assert(!can_substitute(^^std::tuple, {std::meta::reflect_constant(42)}));

consteval
{
    try
    {
        can_substitute(^^std::tuple, {^^::}); // Throws std::meta::exception
                                              // the global namespace cannot be a template arg
    } catch (std::meta::exception&) {}
}

int main() {}

See also

substitute
(C++26)
substitutes reflected arguments in the reflected template
(function template)
reflect_constant
(C++26)
returns a reflection representing a value or template parameter object, suitable for use as a constant template argument
(function template)
reflect_object
(C++26)
returns a reflection representing an object, suitable for use as a constant template argument
(function template)
reflect_function
(C++26)
returns a reflection representing a function, suitable for use as a constant template argument
(function template)

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

Spec-Zone.ru

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