加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – BOOST MPL添加两个list_c对象会导致意外行为

发布时间:2020-12-16 07:33:50 所属栏目:百科 来源:网络整理
导读:我有以下代码: #include boost/mpl/list_c.hpp#include boost/mpl/transform.hpp#include boost/mpl/plus.hpp#include boost/mpl/equal.hpp#include boost/mpl/equal_to.hpp#include boost/mpl/assert.hpp#include iostream#include typeinfo#include asser
我有以下代码:

#include <boost/mpl/list_c.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/assert.hpp>
#include <iostream>
#include <typeinfo>
#include <assert.h>

using namespace boost::mpl;

typedef list_c<long,2,4,6,8,10> evens;
typedef list_c<long,3,5,7,11,13> primes;
typedef list_c<long,9,13,19,23> sums;

typedef transform< evens,primes,plus<> >::type result;
BOOST_MPL_ASSERT(( equal< result,sums,equal_to<_1,_2> > ));

int main()
{
    std::cout << typeid(sums).name() << std::endl << typeid(result).name() << std::endl;
    assert(typeid(sums) == typeid(result));
}

它编译,所以BOOST_MPL_ASSERT成立.但是,在运行它时,main函数中的断言失败.这是什么意思?不应该两个list_c的东西(我似乎缺少正确的单词)包含相同的元素定义相同的类型?

谢谢您的帮助.

解决方法

MPL不对MPL算法产生的确切类型做出任何保证.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读