Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Metaprogramming library(since C++11)

      From cppreference.com
      <cpp
       
       
      Metaprogramming library
      Type traits
      Type categories
      (C++11)
      (C++11)(DR*)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11) 
      Type properties
      (C++11)
      (C++11)
      (C++14)
      (C++11)(deprecated in C++26)
      (C++11)(until C++20*)
      (C++11)(deprecated in C++20)
      (C++11)
      Type trait constants
      Metafunctions
      (C++17)
      Supported operations
      Relationships and property queries
      Type modifications
      Type transformations
      (C++11)(deprecated in C++23)
      (C++11)(deprecated in C++23)
      (C++11)
      (C++11)(until C++20*)(C++17)

      Compile-time rational arithmetic
      Compile-time integer sequences
       

      C++ provides metaprogramming facilities, such as type traits, compile-time rational arithmetic, and compile-time integer sequences.

      Contents

      [edit]Definitions

      The following types are collectively calledreferenceable types:

      For any referenceable typeT, a reference to it can be created[1].

      1. For reference types, this can be done viareference collapsing.

      [edit]Type traits

      Type traits define compile-time template-based interfaces to query the properties of types.

      Attempting to specialize a template defined in the<type_traits> header and listed in this page results in undefined behavior, except thatstd::common_typeandstd::basic_common_reference(since C++20) may be specialized as required in description.

      A template defined in the<type_traits> header may be instantiated with an incomplete type unless otherwise specified, notwithstanding the general prohibition against instantiating standard library templates with incomplete types.

      [edit]Base classes

      Most of non-transforming type traits need to be publicly and unambiguously derived fromstd::integral_constant in order to satisfy the requirements ofUnaryTypeTrait orBinaryTypeTrait.

      Defined in header<type_traits>
      compile-time constant of specified type with specified value
      (class template)[edit]

      Two specializations ofstd::integral_constant for the typebool are provided:

      Defined in header<type_traits>
      Type Definition
      true_typestd::integral_constant<bool,true>
      false_typestd::integral_constant<bool,false>

      [edit]Unary type traits

      Unary type traits can be used to query the boolean properties of a type at compile time.

      All these type traits satisfyUnaryTypeTrait, the base characteristic of each type trait is eitherstd::true_type orstd::false_type, depending on whether the corresponding condition is met.

      Primary type categories
      Defined in header<type_traits>
      (C++11)
      checks if a type isvoid
      (class template)[edit]
      (C++11)(DR*)
      checks if a type isstd::nullptr_t
      (class template)[edit]
      checks if a type is an integral type
      (class template)[edit]
      checks if a type is a floating-point type
      (class template)[edit]
      (C++11)
      checks if a type is an array type
      (class template)[edit]
      (C++11)
      checks if a type is an enumeration type
      (class template)[edit]
      (C++11)
      checks if a type is a union type
      (class template)[edit]
      (C++11)
      checks if a type is a non-union class type
      (class template)[edit]
      checks if a type is a function type
      (class template)[edit]
      (C++11)
      checks if a type is a pointer type
      (class template)[edit]
      checks if a type is anlvalue reference
      (class template)[edit]
      checks if a type is anrvalue reference
      (class template)[edit]
      checks if a type is a non-static member object pointer
      (class template)[edit]
      checks if a type is a non-static member function pointer
      (class template)[edit]
      Composite type categories
      Defined in header<type_traits>
      checks if a type is a fundamental type
      (class template)[edit]
      checks if a type is an arithmetic type
      (class template)[edit]
      (C++11)
      checks if a type is a scalar type
      (class template)[edit]
      (C++11)
      checks if a type is an object type
      (class template)[edit]
      checks if a type is a compound type
      (class template)[edit]
      checks if a type is either anlvalue reference orrvalue reference
      (class template)[edit]
      checks if a type is a pointer to a non-static member function or object
      (class template)[edit]
      Type properties
      Defined in header<type_traits>
      (C++11)
      checks if a type is const-qualified
      (class template)[edit]
      checks if a type is volatile-qualified
      (class template)[edit]
      (C++11)(deprecated in C++26)
      checks if a type is trivial
      (class template)[edit]
      checks if a type is trivially copyable
      (class template)[edit]
      checks if a type is astandard-layout type
      (class template)[edit]
      (C++11)(deprecated in C++20)
      checks if a type is a plain-old data (POD) type
      (class template)[edit]
      (C++11)(deprecated in C++17)(removed in C++20)
      checks if a type is a literal type
      (class template)[edit]
      checks if every bit in the type's object representation contributes to its value
      (class template)[edit]
      (C++11)
      checks if a type is a class (but not union) type and has no non-static data members
      (class template)[edit]
      checks if a type is a polymorphic class type
      (class template)[edit]
      checks if a type is an abstract class type
      (class template)[edit]
      (C++14)
      checks if a type is a final class type
      (class template)[edit]
      checks if a type is an aggregate type
      (class template)[edit]
      checks if a type is an implicit-lifetime type
      (class template)[edit]
      (C++11)
      checks if a type is a signed arithmetic type
      (class template)[edit]
      checks if a type is an unsigned arithmetic type
      (class template)[edit]
      checks if a type is an array type of known bound
      (class template)[edit]
      checks if a type is an array type of unknown bound
      (class template)[edit]
      checks if a type is a scoped enumeration type
      (class template)[edit]
      Supported operations
      Defined in header<type_traits>
      checks if a type has a constructor for specific arguments
      (class template)[edit]
      checks if a type has a default constructor
      (class template)[edit]
      checks if a type has a copy constructor
      (class template)[edit]
      checks if a type can be constructed from an rvalue reference
      (class template)[edit]
      checks if a type has an assignment operator for a specific argument
      (class template)[edit]
      checks if a type has a copy assignment operator
      (class template)[edit]
      checks if a type has a move assignment operator
      (class template)[edit]
      checks if a type has a non-deleted destructor
      (class template)[edit]
      checks if a type has a virtual destructor
      (class template)[edit]
      checks if objects of a type can be swapped with objects of same or different type
      (class template)[edit]
      checks if a reference is bound to a temporary in direct-initialization
      (class template)[edit]
      checks if a reference is bound to a temporary in copy-initialization
      (class template)[edit]

      [edit]Property queries

      Property query traits can be used to query the integral properties of a type at compile time.

      All these type traits satisfyUnaryTypeTrait, the base characteristic of each type trait isstd::integral_constant<std::size_t, Value>, whereValue is the query result of the corresponding property.

      Defined in header<type_traits>
      obtains the type's alignment requirements
      (class template)[edit]
      (C++11)
      obtains the number of dimensions of an array type
      (class template)[edit]
      (C++11)
      obtains the size of an array type along a specified dimension
      (class template)[edit]

      [edit]Type relationships

      Type relationship traits can be used to query relationships between types at compile time.

      All these type traits satisfyBinaryTypeTrait, the base characteristic of each type trait is eitherstd::true_type orstd::false_type, depending on whether the corresponding condition is met.

      Defined in header<type_traits>
      (C++11)
      checks if two types are the same
      (class template)[edit]
      (C++11)
      checks if a type is a base of the other type
      (class template)[edit]
      checks if a type is a virtual base of the other type
      (class template)[edit]
      checks if a type can be converted to the other type
      (class template)[edit]
      checks if two types arelayout-compatible
      (class template)[edit]
      checks if a type is apointer-interconvertible (initial) base of another type
      (class template)[edit]
      checks if a type can be invoked (as if bystd::invoke) with the given argument types
      (class template)[edit]

      [edit]Type transformations

      Type transformation traits transform one type to another following some predefined rules.

      All these type traits satisfyTransformationTrait.

      Const-volatility specifiers
      Defined in header<type_traits>
      removesconst and/orvolatile specifiers from the given type
      (class template)[edit]
      (C++11)(C++11)(C++11)
      addsconst and/orvolatile specifiers to the given type
      (class template)[edit]
      References
      Defined in header<type_traits>
      removes a reference from the given type
      (class template)[edit]
      adds anlvalue orrvalue reference to the given type
      (class template)[edit]
      Sign modifiers
      Defined in header<type_traits>
      obtains the corresponding signed type for the given integral type
      (class template)[edit]
      obtains the corresponding signed type for the given integral type
      (class template)[edit]
      Arrays
      Defined in header<type_traits>
      removes one extent from the given array type
      (class template)[edit]
      removes all extents from the given array type
      (class template)[edit]
      Pointers
      Defined in header<type_traits>
      removes a pointer from the given type
      (class template)[edit]
      adds a pointer to the given type
      (class template)[edit]
      Other transformations
      Defined in header<type_traits>
      (since C++11)(deprecated in C++23)
      defines the type suitable for use as uninitialized storage for types of given size
      (class template)[edit]
      (since C++11)(deprecated in C++23)
      defines the type suitable for use as uninitialized storage for all given types
      (class template)[edit]
      (C++11)
      applies type transformations as when passing a function argument by value
      (class template)[edit]
      combinesstd::remove_cv andstd::remove_reference
      (class template)[edit]
      (C++11)
      conditionallyremoves a function overload or template specialization from overload resolution
      (class template)[edit]
      chooses one type or another based on compile-time boolean
      (class template)[edit]
      determines the common type of a group of types
      (class template)[edit]
      determines the common reference type of a group of types
      (class template)[edit]
      obtains the underlying integer type for a given enumeration type
      (class template)[edit]
      (C++11)(removed in C++20)(C++17)
      deduces the result type of invoking a callable object with a set of arguments
      (class template)[edit]
      (C++17)
      void variadic alias template
      (alias template)[edit]
      returns the type argument unchanged
      (class template)[edit]

      [edit]Logical operations(since C++17)

      Logical operator traits apply logical operators to other type traits.

      Defined in header<type_traits>
      variadic logical AND metafunction
      (class template)[edit]
      variadic logical OR metafunction
      (class template)[edit]
      (C++17)
      logical NOT metafunction
      (class template)[edit]

      [edit]Member relationships(since C++20)

      Defined in header<type_traits>
      checks if objects of a type arepointer-interconvertible with the specified subobject of that type
      (function template)[edit]
      checks if two specified members correspond to each other in the common initial subsequence of two specified types
      (function template)[edit]

      [edit]Compile-time rational arithmetic

      The header<ratio> providestypes and functions for manipulating and storing compile-time ratios.

      [edit]Compile-time integer sequences(since C++14)

      Defined in header<utility>
      implements compile-time sequence of integers
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/meta&oldid=179895"

      [8]ページ先頭

      ©2009-2025 Movatter.jp