| Home | Libraries | People | FAQ | More

## Function any_cast

boost::any_cast —

Custom keyword cast for extracting a value of a given type from an `any`.

## Synopsis

    template<typename T> T any_cast(any & operand);
    template<typename T> T any_cast(const any & operand);
    template<typename ValueType> const ValueType * any_cast(const any * operand);
    template<typename ValueType> ValueType * any_cast(any * operand);

## Description

Returns: If passed a pointer, it returns a similarly qualified pointer to the value content if successful, otherwise null is returned. If T is ValueType, it returns a copy of the held value, otherwise, if T is a reference to (possibly const qualified) ValueType, it returns a reference to the held value.
Throws: Overloads taking an `any` pointer do not throw; overloads taking an `any` value or reference throws `bad_any_cast` if unsuccessful.

| Copyright © 2001 Kevlin Henney