std::is_structural
Defined in header <type_traits> | ||
|---|---|---|
template< class T > struct is_structural; | (since C++26) |
std::is_structural is a UnaryTypeTrait.
If T is a structural type, provides the member constant value equal true. For any other type, value is false.
If the program adds specializations for std::is_structural or std::is_structural_v, the behavior is undefined.
Template parameters
| T | - | a type to check |
Helper variable template
template< class T > constexpr bool is_structural_v = is_structural<T>::value; | (since C++26) |
Inherited from std::integral_constant
Member constants
|
value
[static] |
true if T is a structural type, false otherwise (public static member constant) |
Member functions
|
operator bool | converts the object to bool, returns value (public member function) |
|
operator()
(C++14) | returns value (public member function) |
Member types
| Type | Definition |
|---|---|
value_type | bool |
type | std::integral_constant<bool,value> |
Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_is_structural | 202603L | (C++26) |
std::is_structural |
Example
#include <type_traits>
struct S { int x; };
class Bad1 { int x; };
struct Bad2 { mutable int x; };
struct A { int a[2][3]; };
struct B : public S {}; // OK: public base of structural type
struct C : private S {}; // not structural: private base
auto L = [](int n){ return -n; }; // captureless lambda
static_assert( std::is_structural_v<int>); // scalar
static_assert( std::is_structural_v<int&>); // lvalue ref
static_assert(!std::is_structural_v<int&&>); // rvalue ref
static_assert( std::is_structural_v<S>);
static_assert(!std::is_structural_v<Bad1>);
static_assert(!std::is_structural_v<Bad2>);
static_assert( std::is_structural_v<A>);
static_assert( std::is_structural_v<B>);
static_assert(!std::is_structural_v<C>);
static_assert( std::is_structural_v<decltype(L)>);
int main() { }
See also
|
(C++26) | checks if reflected type is a structural type (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/types/is_structural