Boost logo

Boost :

Subject: Re: [boost] [any] boost::get style accessors
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-04-27 19:20:27


----- Original Message -----
From: "Christoph Heindl" <christoph.heindl_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, April 27, 2010 7:15 PM
Subject: [boost] [any] boost::get style accessors

>
> Hi all,
>
> I couldn't find any boost::get<T> style accessors for boost::any, so I
> came up with an implementation that looks something along the
> following lines.
<snip>
> In case it cannot be converted to the desired destination type a
> bad_any_cast exception is thrown.
>
> The above code enables boost.any and boost.variant to be used
> interchangeably as far as boost::get<T> is concerned.
>
> Any thoughts?

Doesn't any_cast do what you are looking for?
  template<typename T> T any_cast(any &);
  template<typename T> T any_cast(const any &);
  template<typename ValueType> const ValueType * any_cast(const any *);
  template<typename ValueType> ValueType * any_cast(any *);

Best,
_____________________
Vicente Juan Botet Escribá
http://viboes.blogspot.com/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk