Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::reference_constructs_from_temporary

      From cppreference.com
      <cpp‎ |types
       
       
      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
       
      Defined in header<type_traits>
      template<class T,class U>
      struct reference_constructs_from_temporary;
      (since C++23)

      LetV bestd::remove_cv_t<U> ifU is a scalar type orcvvoid, orU otherwise. IfT is a reference type, and given a hypothetic expressione such thatdecltype(e) isV, the variable definitionT ref(e); is well-formed andbinds a temporary object toref, then provides the member constantvalue equal totrue. Otherwise,value isfalse.

      IfT is an lvalue reference type to a const- but not volatile-qualified object type or an rvalue reference type, bothstd::remove_reference_t<T> andstd::remove_reference_t<U> shall becomplete types,cvvoid, or anarrays of unknown bound; otherwise the behavior is undefined.

      If an instantiation of a template above depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed, the behavior is undefined.

      If the program adds specializations forstd::reference_constructs_from_temporary orstd::reference_constructs_from_temporary_v, the behavior is undefined.

      Contents

      [edit]Helper variable template

      template<class T,class U>

      inlineconstexprbool reference_constructs_from_temporary_v=

          std::reference_constructs_from_temporary<T, U>::value;
      (since C++23)
      [edit]

      Inherited fromstd::integral_constant

      Member constants

      value
      [static]
      true ifT is a reference type, aU value can be bound toT in direct-initialization, and a temporary object would be bound to the reference,false otherwise
      (public static member constant)

      Member functions

      operator bool
      converts the object tobool, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typebool
      typestd::integral_constant<bool, value>

      [edit]Notes

      std::reference_constructs_from_temporary can be used for rejecting some cases that always produce dangling references.

      It is also possible to use member initializer list to reject binding a temporary object to a reference if the compiler has implementedCWG1696.

      [edit]Example

      Run this code
      #include <type_traits> static_assert(std::reference_constructs_from_temporary_v<int&&,int>==true);static_assert(std::reference_constructs_from_temporary_v<constint&,int>==true);static_assert(std::reference_constructs_from_temporary_v<int&&,int&&>==false);static_assert(std::reference_constructs_from_temporary_v<constint&,int&&>==false);static_assert(std::reference_constructs_from_temporary_v<int&&,long&&>==true);static_assert(std::reference_constructs_from_temporary_v<int&&,long>==true); int main(){}

      [edit]See also

      checks if a type has a constructor for specific arguments
      (class template)[edit]
      constructs a newtuple
      (public member function ofstd::tuple<Types...>)[edit]
      constructs newpair
      (public member function ofstd::pair<T1,T2>)[edit]
      construct an object with a tuple of arguments
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/reference_constructs_from_temporary&oldid=161357"

      [8]ページ先頭

      ©2009-2025 Movatter.jp