Boost logo

Boost :

Subject: Re: [boost] [any] boost::get style accessors
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-04-28 14:00:25


Stefan wrote:
> Stefan wrote:
> > Christoph Heindl wrote:
> >>
> >> I couldn't find any boost::get<T> style accessors for
> >> boost::any, so I

[snip]

> > Also, for making them usable interchangeably via boost::get,
> > you need them to throw the same exception. Therefore, in
> > case you are
> > using boost::any, you probably want to rethrow bad_any_cast
> > to bad_get.
> >
> > namespace boost {
> > template<class T>
> > typename boost::call_traits<T>::reference get(any &a) {
> > try {
> > return boost::any_cast<typename
> > boost::call_traits<T>::reference>(a);
> > } catch (boost::bad_any_cast const &) {
> throw(boost::bad_get()); }
> > }
> >
> > template<class T>
> > typename boost::call_traits<T>::const_reference get(const
> any &a) {
> > try {
> > return boost::any_cast<typename
> > boost::call_traits<T>::const_reference>(a);
> > } catch (boost::bad_any_cast const &) {
> throw(boost::bad_get()); }
> > }

At that point, I think they should be on par with any_cast rather than built on any_cast so that exceptions needn't be translated. Exception handling overhead is too costly to do it twice when it isn't necessary.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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