|
Boost : |
From: Eric Friedman (ebf_at_[hidden])
Date: 2003-04-03 20:31:23
Gennadiy Rozental:
> > > 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?
>
> Try to compile and run this:
> #include <iostream>
>
> template<typename T>
> void
> foo( T const& )
> {
> std::cout << typeid(T).name() << std::endl;
> }
>
> template<typename T>
> struct get {
> operator T&() { return m_t; }
>
> T m_t;
> };
>
>
> int main()
> {
> foo( get<int>() );
> }
Sorry, I now understand. While I had planned to abandon this approach due to
MSVC conformance problems, I see now it must be abandoned for a more
significant reason.
Thanks,
Eric
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk