Boost logo

Boost Users :

From: Agoston Bejo (gusz1_at_[hidden])
Date: 2004-12-24 07:44:39


It seems to me that eval_if doesn't use lazy evaluation either. The error
message quite obviously refers to an attempt of the compiler to evaluate the
expression on the 'false' branch, whereas the condition (is_arithmetic<int>)
is true to my best knowledge.

Thx,
Agoston

---------------------------------------------------------------------

#include <iostream>
#include <boost/mpl/eval_if.hpp>
#include <boost/type_traits.hpp>
#include <boost/mpl/identity.hpp>
#include <vector>

using namespace std;
using namespace boost;
using namespace mpl;

template<typename T>
struct value_type
{
 typedef typename eval_if< is_arithmetic<T>,
  identity<T>, identity<typename T::value_type> >::type

    // ERROR

 type;
};

int _tmain(int argc, _TCHAR* argv[])
{
 cout << typeid(value_type<int>::type).name() << endl; // ERROR
 cout << typeid(value_type<double>::type).name() << endl;
 cout << typeid(value_type< vector<int> >::type).name() << endl;
 cout << typeid(value_type< vector<double> >::type).name() << endl;
 return 0;
}

---------------------------------------------------------------------
Error:

error C2825: 'T::value_type': cannot form a qualified name
        c:\guszti\prog\vcpp\Boost\xEvalIf\xEvalIf.cpp(27) : see reference to
class

template instantiation 'value_type<T>' being compiled
        with
        [
            T=int
        ]
error C2143: syntax error : missing ',' before 'value_type'
error C2275: 'value_type' : illegal use of this type as an expression

"Robert Ramey" <ramey_at_[hidden]> az alábbiakat írta a következő hírüzenetben:
cqaid5$sp1$1_at_sea.gmane.org...
> 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