# Poco

# class Any

Library: Foundation
Package: Core
Header: Poco/Any.h

## Description

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.

## Member Summary

Member Functions: empty, local, operator =, swap, type

## Constructors

### Any

Any() = default;

Creates an empty any type.

### Any

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

Any(
const Any & other
);

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

### Any

Any(
Any && other
);

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

## Destructor

### ~Any

~Any() = default;

Destructor. Small Object Optimization mode behavior: Invokes the Placeholder destructor, which calls the ValueHolder destructor explicitly (locally held Any), or deletes the ValueHolder heap memory (heap-allocated Any).

## Member Functions

### empty

bool empty() const;

Returns true if the Any is empty.

### local

bool local() const;

Returns true if data is held locally (ie. not allocated on the heap). If POCO_NO_SOO is defined, it always return false. The main purpose of this function is use for testing.

### operator =

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

Assignment operator for all types != Any.

Example:

    Any a = 13;
    Any a = string("12345");

### operator =

Any & operator = (
const Any & rhs
);

Assignment operator for Any.

### operator =

Any & operator = (
Any && rhs
);

Move operator for Any.

### swap

Any & swap(
Any & other
) noexcept;

Swaps the content of the two Anys.

If an exception occurs during swapping, the program execution is aborted.

### type

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.