std::refere...m_temporary(3)
π std::reference_constructs_from_temporary π
okay so this page is from the C++ Standard Libary manual, and the main character is std::reference_constructs_from_temporary β yes, the whole name, no nickname, we respect the icon era. π
πΈ NAME πΈ
std::reference_constructs_from_temporary β std::reference_constructs_from_temporary. That's it, that's the name, and yes it's a long queen of a name, we love that for her. π
β¨ Synopsis β¨
Defined in header <type_traits>
template< class T, class U > (since C++23)
struct reference_constructs_from_temporary;
Let V be std::remove_cv_t<U> if U is a scalar type or cv void, or U otherwise. If T is a reference type, and given a hypothetic expression e such that decltype(e) is V, the variable definition T ref(e); is well-formed and binds a temporary object to ref, then it provides the member constant value equal to true. Otherwise, value is false. π¦
If T is an lvalue reference type to a const- but not volatile-qualified object type or an rvalue reference type, both std::remove_reference_t<T> and std::remove_reference_t<U> shall be complete types, cv void, or an arrays of unknown bound; otherwise the behavior is undefined. (Yes, βan arraysβ is literally in here β we keep every detail, bestie. π)
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 for std::reference_constructs_from_temporary or std::reference_constructs_from_temporary_v, the behavior is undefined. Do not do that. Periodt. π
π Member constants
valueβtrueifTis a reference type, aUvalue can be bound toTin direct-initialization, and a temporary object would be bound to the[static]reference;falseotherwise. It's apublic static member constant. πΈ
π Member functions
operator boolβ converts the object tobool, returnsvalue(public member function) β¨operator()β returnsvalue(C++14) (public member function) π
π Member types
TypeβDefinitionvalue_typeβbooltypeβstd::integral_constant<bool, value>π¦
π Notes
std::reference_constructs_from_temporary can be used for rejecting some cases that always produce dangling references. That's the whole point, bestie β no dangling-ref heartbreak on our watch. π
It is also possible to use member initializer list to reject binding a temporary object to a reference if the compiler has implemented CWG1696. Noted, iconic compiler behavior. π«Ά
π₯ 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<const int&, int> == true);
static_assert(std::reference_constructs_from_temporary_v<int&&, int&&> == false);
static_assert(std::reference_constructs_from_temporary_v<const int&, 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() {}
π See also
is_constructibleβ checks if a type has a constructor for specific arguments (C++11) (class template) πΈis_trivially_constructibleβ checks if a type has a constructor for specific arguments (C++11) (class template) πΈis_nothrow_constructibleβ checks if a type has a constructor for specific arguments (C++11) (class template) πΈconstructorβ constructs a new tuple (public member function of std::tuple<Types...>) πconstructorβ constructs new pair (public member function of std::pair<T1,T2>) πmake_from_tupleβ construct an object with a tuple of arguments (C++17) (function template) π¦
π xoxo, this page came from http://cppreference.com, version/date 2024.06.10, and the page tag is std::refere...m_temporary(3). Stay slay, bestie. π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms