Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-04-02 20:25:21


Gennadiy Rozental wrote:
> > > Also I think we need free function form of value
> > > extraction. In other case it would be difficult to place extract
> > > in context where template parameter is deduced. And check function
> > > is not that important in most cases.
> >
> > While I am again considering a free function, I'm not sure what
> > difference it makes. Please elaborate.
>
> template<typename T>
> void foo( T const& )
> {
> ....
> }
>
> int main()
> {
> boost::variant<int,.....> v = 5;
>
> // Here I want to pass const reference to integer value of variant to
> function foo
> // foo( get<int>( v ) ); - type T is incorrect
> foo( ??? );
> }

I don't see why this wouldn't work. What is "incorrect" regarding type T?
The current boost::extract<T> contains an implicit-cast operator to T.
Please explain.

(Note, however, that the implicit-cast doesn't work on MSVC, so I am likely
to seek a new approach altogether anyhow.)

> > Also, I think the functionality offered in extract::check is quite
> > important. Unlike visitation, extract (or get, or whatever) handles
> > only one of several possible states of the given variant object.
>
> But you are calling check inside access method and throw an exception in
> case of error. It should be enough in most cases IMO. Did I get you wrong.

I see it as the difference between dynamic_cast with a reference type versus
a pointer type. That is, the reference-based dynamic_cast throws, which as
you note, works fine. But the pointer-based dynamic_cast provides a
non-throwing mechanism as well (returns a null pointer). Thus,
extract::check is the non-throwing analogue for extract.

Let me know what you think.

Thanks,
Eric


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