class Poco::Any

Overview

An Any class represents a general type and is capable of storing any type, supporting type-safe extraction of the internally stored data. Moreā€¦

#include <Any.h>

class Any
{
public:
    // classes

    template <typename ValueType>
    class Holder;

    class ValueHolder;

    // construction

    Any();

    template <typename ValueType>
    Any(const ValueType& value);

    Any(const Any& other);

    // methods

    Any&
    swap(Any& other);

    template <typename ValueType>
    Any&
    operator=(const ValueType& rhs);

    Any&
    operator=(const Any& rhs);

    bool
    empty() const;

    const std::type_info&
    type() const;
};

Detailed Documentation

An Any class represents a general type and is capable of storing any type, supporting type-safe extraction of the internally stored data.

Code taken from the Boost 1.33.1 library. Original copyright by Kevlin Henney. Modified for Poco by Applied Informatics.

Modified for small object optimization support (optionally supported through conditional compilation) by Alex Fabijanic.

Construction

Any()

Creates an empty any type.

template <typename ValueType>
Any(const ValueType& value)

Creates an any which stores the init parameter inside.

Example:

Any a(13);
Any a(string("12345"));
Any(const Any& other)

Copy constructor, works with both empty and initialized Any values.

Methods

Any&
swap(Any& other)

Swaps the content of the two Anys.

When small object optimizaton is enabled, swap only has no-throw guarantee when both (*this and other) objects are allocated on the heap.

template <typename ValueType>
Any&
operator=(const ValueType& rhs)

Assignment operator for all types != Any.

Example:

Any a = 13;
Any a = string("12345");
Any&
operator=(const Any& rhs)

Assignment operator for Any.

bool
empty() const

Returns true if the Any is empty.

const std::type_info&
type() const

Returns the type information of the stored content.

If the Any is empty typeid(void) is returned. It is recommended to always query an Any for its type info before trying to extract data via an AnyCast/RefAnyCast.