Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2002-09-03 03:16:35


Douglas Gregor wrote:
> Why is this a problem? I thought that dynamic_any would use the same names
> as any (e.g., any_cast)

See reply of Dadid Abrahams:
David Abrahams wrote:
> I think we decided that the "right" way to spell this construct was
> "extract<T>(x)..."

Douglas Gregor wrote:
> any/dynamic_any starts losing its usefulness when we add more requirements
> on the types contained in them.

There is no additional requirements for contained types! I wrote about that
in my other post:
http://aspn.activestate.com/ASPN/Mail/Message/1343231

The idea there is to compare any/dynamic_any with some type T:

  // just a sugar
  template<typename T>
  bool operator==(const dynamic_any & a, const T & t)
  {
    if(a.type() != typeid(T))
      return false;
    return t == extract<const T &>(a);
  }

If T is_equal_comparable then it can be compared with any/dynamic_any;
otherwise it can not. No comparison of two any/dynamic_any is available
because it's not required for T to be equal comparable.

Douglas Gregor wrote:
> It would, however, be _extremely_
> interesting if one could extend any/dynamic_any in a way that supported
> user-defined sets of operations on any/dynamic_any objects (e.g., one
> might want !=, ==, *, and ++ defined to make 'any' work on input & forward
> iterators). Might be able to do this by using mixins with virtual
> functions...

How? Using template parameters like this?

  typedef dynamic_any<incrementable, equal_comparable> my_dynamic_any;

Or by throwing operation_not_supported at runtime? To do so I need this:

  is_equal_comparable<T>::value
  is_less_comparable<T>::value
  is_multipliable<T>::value
  is_incrementable<T>::value

I see a problem here. How to invoke binary operation (==, !=, *) if two anys
contain values of different type? Again by throwing?

--
Best regards,
Alexander Nasonov
e-mail account: alnsn
e-mail server:  mail.ru

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