|
|
Boost.dynamic_anyHeader <boost/dynamic_any/any.hpp > |
anyany synopsisany constructors and destructorany operatorsbad_extractbad_extract synopsisextractstatic_extractTemplate class any, operators and related functions defined in this header file.
anyany synopsisnamespace boost { namespace dynamic_any { template<class OperationList = empty_list> class any { public: typedef OperationList operation_list; // Template classanyconstructors and destructor any(); // throw() any(const any& other); template<class T> any(const T& value); ~any(); // throw() bool empty() const; // throw() const std::type_info& type() const; // throw() void swap(any& other); // throw() // Template classanyoperators any& operator=(const any& other); template<class T> any& operator=(const T& value); bool operator!() const; // logical_not any operator-() const; // negate any& operator++(); // increment any operator++(int); any& operator--(); // decrement any operator--(int); Result operator()(Arg1, ..., ArgN) const; // function_call<Result (Arg1, ..., ArgN)> }; // class any // Extract a copy or a reference to some subobject of a value held by ref template<class T, class OperationList> T extract(any<OperationList>& ref); template<class T, class OperationList> T extract(const any<OperationList>& ref); // Extract a pointer to some subobject of a value held by *ptr template<class T, class OperationList> T* extract(any<OperationList>* ptr); template<class T, class OperationList> T* extract(const any<OperationList>* ptr); // Extract a copy or a reference to a value held by ref template<class T, class OperationList> T static_extract(any<OperationList>& ref); template<class T, class OperationList> T static_extract(const any<OperationList>& ref); } } // namespace boost { namespace dynamic_any {
any constructors and destructorany();
this->empty() && this->type() == typeid(void).
any(const any& other);
x of class any<OperationList>
which holds a copy of a value held by other. If other is empty then
x is also empty; otherwise, if other holds a value of type T then
the construction of x is equivalent to the following construction of y:
const T& content = extract<const T&>(other); any<OperationList> y(content);
x.type() == other.type().other content throws
or if there is no memory to make a copy.
template<class T> any(const T& value);
OperationList. { TODO: ConceptName }value.
!this->empty() && this->type() == typeid(T).
value throws
or if there is no memory to make a copy.
~any();
any operatorsany& operator=(const any& other);
other as a new content.
this->type() == other.type().*this.other content throws
or if there is no memory to make a copy.
template<class T> any& operator=(const T& value);
OperationList. { TODO: ConceptName }value as a new content.
!this->empty() && this->type() == typeid(T).
*this.value throws
or if there is no memory to make a copy.
bool operator!() const;
x of class any<OperationList>
expression !x is equivalent to logical_not()(x).!x == !extract<const T&>(x)
if x holds a value of type T.
operator! applied to x content.bad_function_call if x has an empty content.
Otherwise, it doesn't throw unless operator! applied to x content throws.
any operator-() const;
x of class any<OperationList>
expression -x is equivalent to negate()(x). If content of
x has known type T this operator do the same as do_negate function:
any<OperationList> do_negate(const any<OperationList>& x)
{
const T& content = extract<const T&>(x);
// -content and any<OperationList> constructor may throw
return any<OperationList>(-content);
}
extract<R>(-x)
and -extract<T>(x) should return identical objects
if x holds a value of type T and R is a type of
-extract<T>(x) expression.
x holds a value of type T the result is the same
as for do_negate(x) call.
bad_function_call if x has an empty content.
Otherwise, it throws when do_negate(x) call throws.
any& operator++(); any operator++(int);
x of class any<OperationList>
expression ++x is equivalent to increment()(x). If content of
x has known type T the effect is increment of the content:
++extract<T&>(x).
++x returns a reference to x,
expression x++ returns a copy of x taken before increment.
bad_function_call if x has an empty content. Otherwise,
it doesn't throw unless pre-increment operator applied to x content throws.
any& operator--(); any operator--(int);
x of class any<OperationList>
expression --x is equivalent to decrement()(x). If content of
x has known type T the effect is decrement of the content:
--extract<T&>(x).
--x returns a reference to x,
expression x-- returns a copy of x taken before decrement.bad_function_call if x has an empty content. Otherwise,
it doesn't throw unless pre-decrement operator applied to x content throws.
bad_extractException class used to report that extract function call failed.
bad_extract synopsisnamespace boost { namespace dynamic_any { class bad_extract : public std::exception { public: virtual const char * what() const throw() { return "boost.dynamic_any: failed extract"; } }; } } // namespace boost { namespace dynamic_any {
extracttemplate<class T, class OperationList> T extract(any<OperationList>& ref); template<class T, class OperationList> T extract(const any<OperationList>& ref);
ref holds a value of type V,
which, let assume can be accessed through
ref holds a value of type V
and U is a public unambiguous base of V, the return is a reference to subobject of type U
of a value held by ref; otherwise,
T(extract<const T&>(ref));
bad_extract if
T(extract<const T&>(ref)); otherwise, if T is cv V&
and ref holds a value of type Y, reference to that value
if Y and V are same types, or, if V is a public unambiguous base of Y, a reference
to subobject of type V of a value held by ref.
extracttemplate<class T, class OperationList> T* extract(any<OperationList>* ptr); template<class T, class OperationList> T* extract(const any<OperationList>* ptr);
static_extracttemplate<class T, class OperationList> T static_extract(any<OperationList>& ref); template<class T, class OperationList> T static_extract(const any<OperationList>& ref);
Demonstrates how to print
#include <string> #include <iostream> #include <boost/mpl/list.hpp> #include <boost/dynamic_any/any.hpp> #include <boost/dynamic_any/operations.hpp> typedef boost::mpl::list<boost::dynamic_any::to_ostream> print_op; typedef boost::dynamic_any::any<print_op> printable_any; int main() { using boost::dynamic_any::extract; // for broken compilers printable_any a(std::string("Hello")); std::cout << a; a = ','; std::cout << a; char& c = extract<char&>(a); c = ' '; std::cout << a; a = (const char *)"World!"; std::cout << a << '\n'; }
Revised 23 March, 2003
© Copyright Alexander Nasonov 2002-2003. All Rights Reserved.