Namespaces
Variants

std::meta::is_value

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval bool is_value( std::meta::info r );
(since C++26)

Returns true if r represents a (scalar) value. Otherwise returns false.

Parameters

r - a reflection value

Return value

true if r represents a (scalar) value; otherwise false.

Example

#include <meta>
#include <vector>

int global_var = 100;

struct Game { int score{}; };
constexpr Game game_instance{42};

// A template to capture different kinds of template arguments
template <int Value, int& Ref, Game Obj, class T>
struct Inspector
{
    static consteval void operator()()
    {
        // Get reflections of the template arguments
        constexpr auto args = std::meta::template_arguments_of(^^Inspector);

        static_assert
        (
            // Value (integer scalar literal 42)
            std::meta::is_value(args[0]) and
            !std::meta::is_object(args[0]) and

            // Reference to global_var
            std::meta::is_value(args[1]) and
            std::meta::is_object(args[1]) and

            // Class-type template parameter object (copy of game_instance)
            std::meta::is_value(args[2]) and
            std::meta::is_object(args[2]) and
        
            // Class-type template parameter Game
            !std::meta::is_value(args[3]) and
            !std::meta::is_object(args[3])
        );
    }
};

int main()
{
    Inspector<42, global_var, game_instance, Game>();
}

See also

(C++26)
checks if reflection represents a static object
(function) [edit]