Boost logo

Boost :

From: Remy Blank (remy.blank_REMOVE_THIS_at_[hidden])
Date: 2002-11-25 20:09:47


Alexander Nasonov wrote:
> You can create your own framework for dynamic_any using
> dynamic_any::function. In a combination with simple and typesafe interface
> it could make great library. Basic idea is here:
>
> namespace your_framework
> {
> // ...
> namespace detail
> {
> // ...
> struct raw_convert
> : boost::dynamic_any::function
> <
> convert,
> void * (boost::dynamic_any::arg &)
> >

I checked out dynamic_any from CVS but the function<...> syntax seems to be
missing, so I replaced it by function1<...>. Is there something missing in
the repository?

> {
> raw_convert(const std::type_info & convert_to);
>
> template<typename T>
> void * call(T & content)
> {
> const std::type_info & convert_from = typeid(T);
> convert_function fun =
> lookup_convert_function(convert_from, convert_to_);
> return fun(&content);
> }
> // ...
> };
>
> } // namespace detail
>
> typedef boost::dynamic_any::any<
> boost::mpl::list<detail::raw_convert>
> > any;
>
> template<typename T>
> T extract(any & a)
> {
> const std::type_info & convert_to = typeid(T):
> void * raw_ptr = detail::raw_convert(convert_to)(a);
> // ... (various checks)
> T * ptr = (T *) raw_ptr;
> return *ptr;
> }
>
> }

After some trimming, this works perfectly!
dynamic_any is truly awesome!

Thanks for the advice.
Best regards.
--Remy

Remove anti-spam sequence in reply address for a timely response.


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