Boost logo

Boost :

From: Michael D. Borghardt (michael_at_[hidden])
Date: 2004-01-13 15:52:52


I am trying to get the numeric_cast to work and have found the following.

I am trying to understand the code below. I am using MVC 7.0 on windfows
2000.

The first temple function, foo, does not compile, even when not instantiated
so it is a syntatic problem(right?)

The second template function, bar, does compile, even when instantiated. It
even executes.

What I do not understand is how is the parsing and deduction of the return
type of foo different from the parsing and deduction of the initialization
of r in bar.

#include <boost/type.hpp>
#include <boost/numeric/converter.hpp>

// This does not compile
template<typename Target, typename Source>
inline typename boost::numeric::converter<Target,Source>::result_type
foo(Source arg )
{
    typedef boost::numeric::converter<Target,Source> Converter ;
    boost::numeric::converter<Target,Source>::result_type r =
Converter::convert(arg);
}

// This does compile
template<typename Target, typename Source>
inline void bar(Source arg )
{
    typedef boost::numeric::converter<Target,Source> Converter ;
    boost::numeric::converter<Target,Source>::result_type r =
Converter::convert(arg);
}

int main(int argc, char* argv[])
{
    bar<int>(5);
}


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