Module: Essential Tools Module Group: Miscellaneous Classes
Does not inherit
#include <rw/any.h> RWAny a;
RWAny encapsulates an object of an arbitrary type; it can:
store objects of arbitrary types (by value or by pointer)
retrieve the original object in a "type-safe" manner
swap the object with another RWAny
assign objects of type RWAny
Requirements for types held by RWAny are:
the type must be complete
the type must be copy constructible
the type must be assignable
None
RWAny()
Default constructor. Creates an empty object. Post-condition: for any T, (address<T>() == 0).
RWAny(const RWAny& ref)
Copy constructor. Creates a deep copy of the argument.
template<class T> RWAny<T>(const T& ref);
Template constructor for type any holding T. Creates RWAny object holding a deep copy of argument ref.
RWAny& operator=(const RWAny& ref);
Assignment operator. Deep-copies the argument. Returns reference to self.
RWAny& swap(RWAny& ref);
Implements a swap operation. After the swap, this object will contain the old content of the argument and vice versa.
const STD::type_info* type() const;
Implements type retrieval. Returns &typeid (T) if any holds object of type T or 0 otherwise.
template<class T> T& get(); template<class T> const T& get() const;
Implements value retrieval. Returns *address<T>() if T is the type of the object stored in any or throws an exception of type (or derived of), bad_cast, otherwise.
template<class T> T* address(); template<class T> const T* address() const;
Implements address retrieval. Returns the address of the object held in any or 0 if the object is not of the type requested.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.