Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-12-21 20:24:58


Look in the mpl documentation under eval_if

Robert Ramey

Agoston Bejo wrote:
> Hi!
> I'm looking for some "lazy" version of boost::mpl::if_. I'm not very
> much into MPL, so I
>
> don't really know either if such a function exists in boost or
> whether it can be easily
>
> constructed.
> Platform: VC++7.1
>
> Thx in advance,
> Agoston
>
>
> This example shows you how it may cause problems that both "branches"
> of if_ get evaluated:
>
> //------------------------------------------------------------
> #include <iostream>
> #include <vector>
> #include <boost/mpl/if.hpp>
> #include <boost/type_traits.hpp>
>
> using namespace std;
> using namespace boost;
> using namespace mpl;
>
> template<typename T>
> struct t_type
> {
> typedef typename if_<
> is_arithmetic<T>,
> T, typename T::value_type>::type // ERROR!
> type;
> };
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> cout << typeid(t_type<int>::type).name() << endl; // 'int'
> cout << typeid(t_type<vector<double> >::type).name()
> << endl; // 'double'
> return 0;
> }
>
> //------------------------------------------------------------
> Error message:
>
> error C2825: 'T::value_type': cannot form a qualified name
> see reference to class template instantiation 't_type<T>' being
> compiled with
> [
> T=int
> ]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net