Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template recursive_wrapper

boost::recursive_wrapper — Solves circular dependencies, enabling recursive types.

Synopsis

// In header: <boost/variant/recursive_wrapper.hpp>

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

  // construct/copy/destruct
  ();
  ();
  ();
  ~();

  // modifiers
   ();
   ();
   ();

  // queries
   ();
   () ;
   ();
   () ;
};

Description

The recursive_wrapper class template has an interface similar to a simple value container, but its content is allocated dynamically. This allows recursive_wrapper to hold types T whose member data leads to a circular dependency (e.g., a data member of T has a data member of type T).

The application of recursive_wrapper is easiest understood in context. See the section called “Recursive types with recursive_wrapper for a demonstration of a common use of the class template.

Notes:

  • Any type specified as the template argument to recursive_wrapper must be capable of construction via operator new. Thus, for instance, references are not supported.

recursive_wrapper public construct/copy/destruct

  1. ();
    Default constructor.

    Initializes *this by default construction of T.

    Requires:

    T must fulfill the requirements of the DefaultConstructible [20.1.4] concept.

    Throws:

    May fail with any exceptions arising from the default constructor of T or, in the event of insufficient memory, with std::bad_alloc.
  2. ( other);
    Copy constructor.

    Copies the content of other into *this.

    Throws:

    May fail with any exceptions arising from the copy constructor of T or, in the event of insufficient memory, with std::bad_alloc.
  3. ( operand);
    Value constructor.

    Copies operand into *this.

    Throws:

    May fail with any exceptions arising from the copy constructor of T or, in the event of insufficient memory, with std::bad_alloc.
  4. ~();
    Destructor.

    Deletes the content of *this.

    Throws:

    Will not throw.

recursive_wrapper modifiers

  1.  ( other);

    Exchanges contents of *this and other.

    Throws:

    Will not throw.
  2.  ( rhs);
    Copy assignment operator.

    Assigns the content of rhs to the content of *this.

    Requires:

    T must fulfill the requirements of the Assignable concept.

    Throws:

    May fail with any exceptions arising from the assignment operator of T.
  3.  ( rhs);
    Value assignment operator.

    Assigns rhs into the content of *this.

    Requires:

    T must fulfill the requirements of the Assignable concept.

    Throws:

    May fail with any exceptions arising from the assignment operator of T.

recursive_wrapper queries

  1.  ();
     () ;

    Returns a reference to the content of *this.

    Throws:

    Will not throw.
  2.  ();
     () ;

    Returns a pointer to the content of *this.

    Throws:

    Will not throw.

PrevUpHomeNext