dbp::any Class Reference

Any container class. More...

#include <any.h>

List of all members.

Public Member Functions

 any ()
 Constructor.
 any (const any &other)
 Copy constructor.
template<class T >
 any (const T &other)
 Copy constructor for template value type.
const anyoperator= (const any &other)
 Assignment operator.
virtual ~any ()
 Destructor.
void clear ()
 Clear value.
bool empty () const
 Check for empty value.
const std::type_info & type () const
 Determine the value type.
std::string str () const
 Convert value to a string.
template<typename T >
const T cast ()
 Cast to another type.
bool operator== (const any &rhs) const
 Equality operator.

Friends

std::ostream & operator<< (std::ostream &str, const any &value)
 Convert value to a string and put it into a stream.

Detailed Description

Any container class.

The any container class is a holder for value of any type. It is useful to store objects of different types in the single STL container, for example. Moreover, you can cast one type to another with this class.


Member Function Documentation

template<typename T >
const T dbp::any::cast (  )  [inline]

Cast to another type.

The cast() template method helps to cast value to the other type. If the native value type and the type requested are differs the safe conversion via string representation is occured. The first cast to the different type is a slow operation (3200 double/int casts per second @ one core of Athlon 64 X2 5200+), but future calls are ~300 times faster.

bool dbp::any::empty (  )  const [inline]

Check for empty value.

Returns:
true, if the value is not defined and false otherwise.
std::string dbp::any::str (  )  const [inline]

Convert value to a string.

Returns:
the string representation of the value.
const std::type_info& dbp::any::type (  )  const [inline]

Determine the value type.

Returns:
typeid(void) if the value is not defined, or the value type otherwise.

The documentation for this class was generated from the following file:

 
Support This Project
SourceForge.net Logo