struct cvflann::any

Overview

#include <any.h>

struct any
{
    // construction

    template <typename T>
    any(const T& x);

    any();
    any(const char* x);
    any(const any& x);

    // methods

    any&
    assign(const any& x);

    template <typename T>
    any&
    assign(const T& x);

    template <typename T>
    T&
    cast();

    template <typename T>
    const T&
    cast() const;

    bool
    compatible(const any& x) const;

    bool
    empty() const;

    template <typename T>
    bool
    has_type();

    template <typename T>
    any&
    operator=(const T& x);

    any&
    operator=(const any& x);

    any&
    operator=(const char* x);

    void
    reset();

    any&
    swap(any& x);

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

Detailed Documentation

Construction

template <typename T>
any(const T& x)

Initializing constructor.

any()

Empty constructor.

any(const char* x)

Special initializing constructor for string literals.

any(const any& x)

Copy constructor.

Methods

any&
assign(const any& x)

Assignment function from another any.

template <typename T>
any&
assign(const T& x)

Assignment function.

template <typename T>
T&
cast()

Cast operator. You can only cast to the original type.

template <typename T>
const T&
cast() const

Cast operator. You can only cast to the original type.

bool
compatible(const any& x) const

Returns true if the two types are the same.

bool
empty() const

Returns true if the any contains no value.

template <typename T>
bool
has_type()

Returns if the type is compatible with the policy.

template <typename T>
any&
operator=(const T& x)

Assignment operator.

any&
operator=(const any& x)

Assignment operator. Template-based version above doesn’t work as expected. We need regular assignment operator here.

any&
operator=(const char* x)

Assignment operator, specialed for literal strings. They have types like const char [6] which don’t work as expected.

void
reset()

Frees any allocated memory, and sets the value to NULL.

any&
swap(any& x)

Utility functions.