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 for the latest Boost documentation.
Class template reference_wrapper
c++boost.gif (8819 bytes)HomeLibrariesPeopleFAQMore

Class template reference_wrapper

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

Synopsis

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

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

  // access
  operator T&() const;
  T& get() const;
  T* get_pointer() const;
};

// constructors
reference_wrapper<T> ref(T&);
reference_wrapper<T const> cref(T 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 construct/copy/destruct

  1. explicit reference_wrapper(T& t);

    Effects: Constructs a reference_wrapper object that stores a reference to t.
    Throws: Does not throw.

reference_wrapper access

  1. operator T&() const;

    Returns: The stored reference.
    Throws: Does not throw.

  2. T& get() const;

    Returns: The stored reference.
    Throws: Does not throw.

  3. T* get_pointer() const;

    Returns: A pointer to the object referenced by the stored reference.
    Throws: Does not throw.

reference_wrapper constructors

  1. reference_wrapper<T> ref(T& t);

    Returns: reference_wrapper<T>(t)
    Throws: Does not throw.

  2. reference_wrapper<T const> cref(T const& t);

    Returns: reference_wrapper<T const>(t)
    Throws: Does not throw.

Last revised: , at GMTCopyright © 1999, 2000 Jaakko Järvi
Copyright © 2001, 2002 Peter Dimov
Copyright © 2002 David Abrahams