Boost MPL 文档指出 boost::map::equal
“如果两个序列 Seq1 和 Seq2 在 _element_ 与 _element_ 比较时相同,则返回一个真值积分常数。
但似乎没有检查关联序列映射的相等元素_明智_:
下面的演示将显示这一点: Map2 应该等于 Map3,它们都在 'key' 处增加 'int_<1>' value_type。查看定义 Map3 的 typedef。大小和唯一的元素在演示中被转储:
#include<iostream>
#include<boost/mpl/map.hpp>
#include<boost/mpl/at.hpp>
#include<boost/mpl/insert.hpp>
#include<boost/mpl/erase_key.hpp>
#include<boost/mpl/pair.hpp>
#include<boost/mpl/int.hpp>
#include<boost/mpl/plus.hpp>
#include<boost/mpl/equal.hpp>
#include<boost/mpl/size.hpp>
#include<boost/mpl/front.hpp>
namespace mpl = boost::mpl;
using mpl::int_;
using std::cout;
using std::endl;
using std::is_same;
int main(int argc, char *argv[])
{
typedef int key;
typedef typename mpl::map<mpl::pair<key, int_<1>>> Map;
typedef typename mpl::map<mpl::pair<key, int_<2>>> Map2;
typedef typename mpl::insert<
typename mpl::erase_key<Map,
key>::type,
mpl::pair<key,
typename mpl::plus<int_<1>,
typename mpl::at<Map, key>::type>::type
>::type
>::type Map3;
cout << "equal? " << mpl::equal<Map2,Map3>::type::value << endl;
cout << "size? " << mpl::size<Map3>::value << endl;
cout << "key type at front? " << typeid(mpl::front<Map3>::type::first).name() << endl;
cout << "value type at front? " << mpl::front<Map3>::type::second::value << endl;
cout << "expected size? " << mpl::size<Map2>::value << endl;
cout << "expected key type at front? " << typeid(mpl::front<Map2>::type::first).name() << endl;
cout << "expected value type at front? " << mpl::front<Map2>::type::second::value << endl;
return 0;
}
我正在使用带有 boost 1.51 的 gcc 4.8.1