std::meta::can_substitute
From cppreference.com
| 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
Run this code
#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() {}
