Adrian
Adrian

Reputation: 10911

Compiling Boost MPL samples on MSVC 2013

Well, I successfully built the test programme:

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}

but when I tried the one for boost::mpl::map, it barfed:

#include <boost/mpl/map.hpp>
#include <boost/mpl/assert.hpp>

int main()
{
    using std::is_same;
    using boost::mpl::at;
    using boost::mpl::long_;
    using boost::mpl::void_;
    using boost::mpl::map;
    using boost::mpl::pair;
    //using namespace boost::mpl;
    typedef map <
        pair<int, unsigned>
        , pair<char, unsigned char>
        , pair<long_<5>, char[17]>
        , pair < int[42], bool >
    > m;

    BOOST_MPL_ASSERT_RELATION(size<m>::value, == , 4);
    BOOST_MPL_ASSERT_NOT((empty<m>));

    BOOST_MPL_ASSERT((is_same< at<m, int>::type, unsigned >));
    BOOST_MPL_ASSERT((is_same< at<m, long_<5> >::type, char[17] >));
    BOOST_MPL_ASSERT((is_same< at<m, int[42]>::type, bool >));
    BOOST_MPL_ASSERT((is_same< at<m, long>::type, void_ >));

    return 0;
}

This is the compiler output:

1>------ Build started: Project: example, Configuration: Debug Win32 ------
1>  example.cpp
1>c:\projects\example\example\example.cpp(22): error C2027: use of undefined type 'boost::mpl::size<m>'
1>c:\projects\example\example\example.cpp(22): error C2065: 'value' : undeclared identifier
1>c:\projects\example\example\example.cpp(22): error C2975: 'x' : invalid template argument for 'boost::mpl::assert_relation', expected compile-time constant expression
1>          c:\boost_1_57_0\boost\mpl\assert.hpp(120) : see declaration of 'x'
1>c:\projects\example\example\example.cpp(22): error C2664: 'int boost::mpl::assertion_failed<0>(boost::mpl::assert<false>::type)' : cannot convert argument 1 from 'boost::mpl::failed ************boost::mpl::assert_relation<0,4,bool boost::mpl::operator ==(boost::mpl::failed,boost::mpl::failed)>::* ***********' to 'boost::mpl::assert<false>::type'
1>          No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\boost_1_57_0\boost\mpl\assert.hpp(176): error C2027: use of undefined type 'boost::mpl::empty<m>'
1>          c:\projects\example\example\example.cpp(23) : see reference to class template instantiation 'boost::mpl::assert_arg_pred<boost::mpl::empty<m>>' being compiled
1>c:\boost_1_57_0\boost\mpl\assert.hpp(176): error C2146: syntax error : missing ';' before identifier 'p_type'
1>c:\boost_1_57_0\boost\mpl\assert.hpp(176): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost_1_57_0\boost\mpl\assert.hpp(177): error C2653: 'p_type' : is not a class or namespace name
1>c:\boost_1_57_0\boost\mpl\assert.hpp(177): error C2065: 'value' : undeclared identifier
1>c:\boost_1_57_0\boost\mpl\assert.hpp(177): error C2975: 'unnamed-parameter' : invalid template argument for 'boost::mpl::assert_arg_pred_impl', expected compile-time constant expression
1>          c:\boost_1_57_0\boost\mpl\assert.hpp(171) : see declaration of 'unnamed-parameter'
1>c:\boost_1_57_0\boost\mpl\assert.hpp(182): error C2027: use of undefined type 'boost::mpl::empty<m>'
1>          c:\projects\example\example\example.cpp(23) : see reference to class template instantiation 'boost::mpl::assert_arg_pred_not<boost::mpl::empty<m>>' being compiled
1>c:\boost_1_57_0\boost\mpl\assert.hpp(182): error C2146: syntax error : missing ';' before identifier 'p_type'
1>c:\boost_1_57_0\boost\mpl\assert.hpp(182): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost_1_57_0\boost\mpl\assert.hpp(183): error C2653: 'p_type' : is not a class or namespace name
1>c:\boost_1_57_0\boost\mpl\assert.hpp(183): error C2065: 'value' : undeclared identifier
1>c:\boost_1_57_0\boost\mpl\assert.hpp(183): error C2057: expected constant expression
1>c:\boost_1_57_0\boost\mpl\assert.hpp(184): error C2975: 'unnamed-parameter' : invalid template argument for 'boost::mpl::assert_arg_pred_impl', expected compile-time constant expression
1>          c:\boost_1_57_0\boost\mpl\assert.hpp(171) : see declaration of 'unnamed-parameter'
1>c:\projects\example\example\example.cpp(23): error C2668: 'boost::mpl::assert_not_arg' : ambiguous call to overloaded function
1>          c:\boost_1_57_0\boost\mpl\assert.hpp(203): could be 'boost::mpl::assert<false> boost::mpl::assert_not_arg<boost::mpl::empty<m>>(void (__cdecl *)(Pred),int)'
1>          with
1>          [
1>              Pred=boost::mpl::empty<m>
1>          ]
1>          c:\boost_1_57_0\boost\mpl\assert.hpp(194): or       'boost::mpl::failed ************boost::mpl::not_<boost::mpl::empty<m>>::* ***********boost::mpl::assert_not_arg<boost::mpl::empty<m>>(void (__cdecl *)(Pred),int)'
1>          with
1>          [
1>              Pred=boost::mpl::empty<m>
1>          ]
1>          while trying to match the argument list '(void (__cdecl *)(boost::mpl::empty<m>), int)'
1>c:\projects\example\example\example.cpp(25): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Even doing the following:

#include <boost/mpl/map.hpp>

int main()
{
    using std::is_same;
    using boost::mpl::at;
    using boost::mpl::long_;
    using boost::mpl::map;
    using boost::mpl::pair;
    typedef map <
        pair<int, unsigned>
        , pair<char, unsigned char>
        , pair<long_<5>, char[17]>
        , pair < int[42], bool >
    > m;

    at<m, int>::type a;
    return 0;
}

fails:

1>------ Build started: Project: example, Configuration: Debug Win32 ------
1>  example.cpp
1>c:\projects\example\example\example.cpp(18): error C2027: use of undefined type 'boost::mpl::at<m,int>'
1>c:\projects\example\example\example.cpp(18): error C2065: 'type' : undeclared identifier
1>c:\projects\example\example\example.cpp(18): error C2146: syntax error : missing ';' before identifier 'a'
1>c:\projects\example\example\example.cpp(18): error C2065: 'a' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I've installed VS Community 2013 Update 4. Am I using this incorrectly or is this a failure with the version I've installed? Release notes for 1.57.0 doesn't reference anything, nor does their bug system.

Upvotes: 2

Views: 978

Answers (1)

sehe
sehe

Reputation: 392931

Basically there's a whole slew of missing headers. The last, simplest, one just misses

#include <boost/mpl/at.hpp>
#include <type_traits>

(that's on GCC, so MSVC might require some more due to implementation defined indirect header includes).

The full map sample needs at least

#include <boost/mpl/assert.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/size.hpp>
#include <type_traits>

And some more usings:

using boost::mpl::empty;
using boost::mpl::size;

Upvotes: 3

Related Questions