Boost logo

Boost :

From: John Harris (TT) (john.harris_at_[hidden])
Date: 2002-04-24 07:00:31


I agree that these are acceptable workarounds, and that lack of compiler
support for 'explicit' is a good enough reason not to change it here. I
like method (1)...that's really thinking. Thanks.

john harris
trading technologies

-----Original Message-----
From: Bjorn.Karlsson_at_[hidden] [mailto:Bjorn.Karlsson_at_[hidden]]
Sent: Wednesday, April 24, 2002 5:07 AM
To: boost_at_[hidden]
Subject: RE: [boost] Re: Should boost::any::any() be made explicit?

<snip>

Even without an explicit parameterized constructor for any, there are at
least two solutions (or rather workarounds):

0) Change the declaration to ostream& operator<<(ostream&,boost::any&)
   The removal of const may be enough, but that, of course, depends on
cv-qualification of the instances (if your "real" anys are already const
that'd clearly break this hack).

1) Another level of indirection - the following should solve the problem:
struct any_print {
  any_print(const boost::any& a) : a_(a) {}
  const boost::any& a_;
};
std::ostream& operator<<(std::ostream& o, const any_print& a) {


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