Partager via


reference_wrapper Class

Wraps a reference.

template<class Ty>
    class reference_wrapper
    : public unary_function<T1, Ret>        // see below
    : public binary_function<T1, T2, Ret>   // see below
    {
public:
    typedef Ty type;
    typedef T0 result_type;                 // see below

    reference_wrapper(Ty&);

    Ty& get() const;
    operator Ty&() const;
    template<class T1, class T2, ..., class TN>
        typename result_of<T(T1, T2, ..., TN)>::type
        operator()(T1&, T2&, ..., TN&);

private:
    Ty *ptr; // exposition only
    };

Remarks

A reference_wrapper<Ty> is copy constructible and assignable, and holds a pointer that points to an object of type Ty.

A specialization reference_wrapper<Ty> is derived from std::unary_function<T1, Ret> (hence defining the nested type result_type as a synonym for Ret and the nested type argument_type as a synonym for T1) only if the type Ty is:

a function type or pointer to function type taking one argument of type T1 and returning Ret; or

a pointer to a member function Ret T::f() cv, where cv represents the member function's cv-qualifiers; the type T1 is cvT*; or

a class type that is derived from unary_function<T1, Ret>.

A specialization reference_wrapper<Ty> is derived from std::binary_function<T1, T2, Ret> (hence defining the nested type result_type as a synonym for Ret, the nested type first_argument_type as a synonym for T1, and the nested type second_argument_type as a synonym for T2) only if the type Ty is:

a function type or pointer to function type taking two arguments of types T1 and T2 and returning Ret; or

a pointer to a member function Ret T::f(T2) cv, where cv represents the member function's cv-qualifiers; the type T1 is cvT*; or

a class type that is derived from binary_function<T1, T2, Ret>.

Constructors

reference_wrapper::reference_wrapper

Constructs a reference_wrapper.

Typedefs

reference_wrapper::result_type

The weak result type of the wrapped reference.

reference_wrapper::type

The type of the wrapped reference.

Member Functions

reference_wrapper::get

Obtains the wrapped reference.

Operators

reference_wrapper::operator Ty&

Gets a pointer to the wrapped reference.

reference_wrapper::operator()

Calls the wrapped reference.

Requirements

Header: <functional>

Namespace: std

See Also

Reference

cref Function

ref Function