Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class template reference_wrapper

boost::reference_wrapper — Contains a reference to an object of type T.

Synopsis

// In header: <boost/core/ref.hpp>

template<typename T> 
class reference_wrapper {
public:
  // types
  typedef T type;

  // construct/copy/destruct
  explicit reference_wrapper(T &);
  reference_wrapper(T &&) = delete;

  // public member functions
  operator T &() const;
  T & get() const;
  T * get_pointer() const;
};

Description

reference_wrapper is primarily used to "feed" references to function templates (algorithms) that take their parameter by value. It provides an implicit conversion to T&, which usually allows the function templates to work on references unmodified.

reference_wrapper public types

  1. typedef T type;

    Type T.

reference_wrapper public construct/copy/destruct

  1. explicit reference_wrapper(T & t);

    Constructs a reference_wrapper object that stores a reference to t.

    Does not throw.

  2. reference_wrapper(T && t) = delete;

    Construction from a temporary object is disabled.

reference_wrapper public member functions

  1. operator T &() const;

    Does not throw.

    Returns:

    The stored reference.

  2. T & get() const;

    Does not throw.

    Returns:

    The stored reference.

  3. T * get_pointer() const;

    Does not throw.

    Returns:

    A pointer to the object referenced by the stored reference.


PrevUpHomeNext