-1

I'd like to process some template arguments by using boost::mpl::fold. At the moment, I'm still stuck to the sample provided by Boost as even that does not work for me. I get the following error:

..\src\main.cpp:18:32: error: template argument 2 is invalid
..\src\main.cpp:18:37: error: wrong number of template arguments (4, should be 3)

The following code is taken from http://www.boost.org/doc/libs/1_48_0/libs/mpl/doc/refmanual/fold.html

#include <string>
#include <iostream>

#include <boost/mpl/fold.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/type_traits.hpp>

using namespace std;
using namespace boost;
using namespace boost::mpl;
using namespace boost::type_traits;

typedef vector<long,float,short,double,float,long,long double> types;
typedef fold<
      types
    , int_<0>
    , if_< is_float<_2>,next<_1>,_1 >
    >::type number_of_floats;

BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 );

int main(){
}

I'm running mingw 4.7.0 using the flag "-std=c++11". I found some other examples on the net but have not yet been successful in compiling anything useful. Any suggestions?

Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
user1034081
  • 618
  • 5
  • 21
  • 1
    your example appears to be okay: http://ideone.com/XUom2 (note the version of C++ I linked is the old standard - not 11) – Nim Feb 07 '12 at 17:06

1 Answers1

2

You are messing up the namespaces. Making a lot of symbols ambiguous.

Remove the using and the example works fine for me.

...
using namespace boost;

typedef mpl::vector<long,float,short,double,float,long,long double> types;
typedef mpl::fold<
    types
    , mpl::int_<0>
    , mpl::if_< is_float<boost::mpl::_2>,boost::mpl::next<boost::mpl::_1>,boost::mpl::_1 >
>::type number_of_floats;
...
mkaes
  • 13,781
  • 10
  • 52
  • 72