Freigeben über


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 cv T*; 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 cv T*; or

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

Requirements

Header: <functional>

Namespace: std

See Also

Reference

cref Function

ref Function

Other Resources

<functional> Members