Namespaces
Variants
Views
Actions

std::basic_common_reference<std::reference_wrapper>

From cppreference.com
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
(C++26)
Three-way comparison
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)

 
Function objects
Function invocation
(C++17)(C++23)
Identity function object
(C++20)
Transparent operator wrappers
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

Old binders and adaptors
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)  
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)

(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
 
 
Defined in header <functional>
template< class R, class T,

          template<class> RQual, template<class> TQual >
    requires (/*ref-wrap-common-reference-exists-with*/<R, T, RQual<R>, TQual<T>> &&
              !/*ref-wrap-common-reference-exists-with*/<T, R, TQual<T>, RQual<R>>)

struct basic_common_reference<R, T, RQual, TQual>;
(1) (since C++23)
template< class T, class R,

          template<class> TQual, template<class> RQual >
    requires (/*ref-wrap-common-reference-exists-with*/<R, T, RQual<R>, TQual<T>> &&
              !/*ref-wrap-common-reference-exists-with*/<T, R, TQual<T>, RQual<R>>)

struct basic_common_reference<T, R, TQual, RQual>;
(2) (since C++23)
Helper concepts
template< class R, class T, class RQ, class TQ >

concept /*ref-wrap-common-reference-exists-with*/ =
    /*is-ref-wrapper*/<R> &&
    requires { typename std::common_reference_t<typename R::type&, TQ>; } &&

    std::convertible<RQ, std::common_reference_t<typename R::type&, TQ>>;
(3) (exposition only*)

The common reference type of a reference_wrapper (denoted as R) and a type T, correspondingly applied with cv and reference qualifiers (denoted as RQ and TQ respectively), is equivalent to a common reference type of underlying type of R applied with lvalue reference and the TQ.

The common reference type is defined only if R is the only reference_wrapper, the underlying type of R applied with lvalue reference and the TQ have a common reference type to which RQ must be convertible.

The exposition-only constant /*is-ref-wrapper*/<R> is true if and only if R is a specialization of std::reference_wrapper.

Contents

[edit] Member types

Member type Definition
type std::common_reference_t<typename R::type&, TQual<T>> (1,2)

[edit] Notes

Feature-test macro Value Std Feature
__cpp_lib_common_reference_wrapper 202302L (C++23) Make std::common_reference_t of std::reference_wrapper a reference type

[edit] Example

#include <concepts>
#include <functional>
 
static_assert(std::same_as<std::common_reference_t<int&,
                                                   std::reference_wrapper<int>>,
                                                   int&>);
static_assert(std::same_as<std::common_reference_t<std::reference_wrapper<int>&,
                                                   int&>,
                                                   int&>);
static_assert(std::same_as<std::common_reference_t<int&,
                                                   const std::reference_wrapper<int>&>,
                                                   int&>);
int main() {}

[edit] See also

determines the common reference type of a group of types
(class template) [edit]