Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::reference_converts_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_converts_from_temporary;
      (since C++23)

      LetV bestd::remove_cv_t<U> ifU is a scalar type orcv void, orU otherwise. IfT is a reference type, and given a hypothetical 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_converts_from_temporary orstd::reference_converts_from_temporary_v, the behavior is undefined.

      Contents

      [edit]Helper variable template

      template<class T,class U>

      inlineconstexprbool reference_converts_from_temporary_v=

          std::reference_converts_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 copy-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_converts_from_temporary can be used for rejecting some cases that always produce dangling references.

      [edit]Example

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

      [edit]See also

      checks if a type can be converted to the other type
      (class template)[edit]
      (C++17)(C++23)
      invokes anyCallable object with given argumentsand possibility to specify return type(since C++23)
      (function template)[edit]
      (C++11)
      binds one or more arguments to a function object
      (function template)[edit]
      (C++17)
      calls the provided functor with the arguments held by one or morevariants
      (function template)[edit]
      constructs a newstd::function instance
      (public member function ofstd::function<R(Args...)>)[edit]
      constructs a newstd::move_only_function object
      (public member function ofstd::move_only_function)[edit]
      constructs the task object
      (public member function ofstd::packaged_task<R(Args...)>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/reference_converts_from_temporary&oldid=178627"

      [8]ページ先頭

      ©2009-2026 Movatter.jp