如何获得boost :: mpl :: map的*任何*示例工作? [英] How to get *any* example of boost::mpl::map working?

查看:72
本文介绍了如何获得boost :: mpl :: map的*任何*示例工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的示例代码.有人可以帮我吗?

Here is my sample code. Can someone please help me with it?

#include <string>
#include <utility> //Not strictly necessary (gets imported implicitely anyway)
#include <boost/mpl/map.hpp>
#include <boost/mpl/size.hpp>
#include <boost/type_traits/is_same.hpp>

typedef boost::mpl::map<
      std::pair<int,unsigned>
    , std::pair<char,unsigned char>
    > m;

int main()
{
    std::pair<int,unsigned> b(10,10); //this works
    int a = boost::mpl::size<m>::value; //this doesn't
}

错误消息:

In file included from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/include_preprocessed.hpp:47:0,
                 from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/map10.hpp:28,
                 from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/map20.hpp:19,
                 from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map.hpp:36,
                 from /home/adam/c++/tests/simple_test/test2.cpp:3:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/preprocessed/typeof_based/map10.hpp: In instantiation of ‘struct boost::mpl::map2<std::pair<int, unsigned int>, std::pair<char, unsigned char> >’:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/preprocessed/gcc/map.hpp:51:8:   required from ‘struct boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1:   required by substitution of ‘template<class U> static char (& boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >::gcc_3_2_wknd::test<U>(const volatile boost::mpl::aux::type_wrapper<T>*, boost::mpl::aux::type_wrapper<typename U::tag>*))[2] [with U = boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >]’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1:   required from ‘const bool boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >::value’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1:   required from ‘struct boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/sequence_tag.hpp:110:8:   required from ‘struct boost::mpl::sequence_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp:29:8:   required from ‘struct boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
/home/adam/c++/tests/simple_test/test2.cpp:15:29:   required from here
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/preprocessed/typeof_based/map10.hpp:31:8: error: no type named ‘first’ in ‘struct std::pair<char, unsigned char>’
 struct map2
        ^~~~
In file included from /home/adam/c++/tests/simple_test/test2.cpp:4:0:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp: In instantiation of ‘struct boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’:
/home/adam/c++/tests/simple_test/test2.cpp:15:29:   required from here
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp:29:8: error: no class template named ‘apply’ in ‘struct boost::mpl::size_impl<boost::mpl::non_sequence_tag>’
 struct size
        ^~~~
/home/adam/c++/tests/simple_test/test2.cpp: In function ‘int main()’:
/home/adam/c++/tests/simple_test/test2.cpp:15:31: error: ‘value’ is not a member of ‘boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
  int a = boost::mpl::size<m>::value; //this doesn't
                               ^~~~~
/home/adam/c++/tests/simple_test/test2.cpp:15:6: warning: unused variable ‘a’ [-Wunused-variable]
  int a = boost::mpl::size<m>::value; //this doesn't
      ^
CMakeFiles/libsimple_test.dir/build.make:62: recipe for target 'CMakeFiles/libsimple_test.dir/test2.cpp.o' failed
make[2]: *** [CMakeFiles/libsimple_test.dir/test2.cpp.o] Error 1
CMakeFiles/Makefile2:142: recipe for target 'CMakeFiles/libsimple_test.dir/all' failed
make[1]: *** [CMakeFiles/libsimple_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

我在GCC 7.3.0上使用C ++ 11,在Ubuntu 16.04 64位上使用libboost 1.67.0.

I use C++11 on GCC 7.3.0 and libboost 1.67.0 on Ubuntu 16.04 64bit.

推荐答案

我偶然发现了一个解决方案:不要使用标准的std::pair,而要使用重新发明的boost::mpl::pair.将std::pair简单替换为boost::mpl::pair后,示例代码将编译并正常运行...这导致了另一个问题.

By chance I found a solution: Don't use the standard std::pair, but rather use the re-invented boost::mpl::pair. After simple replacing std::pair into boost::mpl::pair the sample code compiles and runs properly... which leads to another question.

这篇关于如何获得boost :: mpl :: map的*任何*示例工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆