以下示例说明了我的意思:
#include <boost/mpl/map.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/insert.hpp>
#include <iostream>
using namespace boost::mpl;
template <int n1, int n2>
struct entry
{
typedef pair<int_<n1>, int_<n2> > type;
};
typedef map<entry<1,1>::type> entries;
typedef insert<
entries, entry<4,4>::type>::type update;
typedef insert<
update,
entry<5,5>::type>::type update2;
struct print_values
{
template <class I>
void operator()(I)
{
std::cout << first<I>::type::value << ", "
<< second<I>::type::value << std::endl;
}
};
int main()
{
for_each<update2>(print_values());
std::cout << "Next:" << std::endl;
for_each<update2::type>(print_values());
}
输出:
1, 1
4, 4
5, 5
Next:
1, 1
当我update2
通过访问update2::type
我插入的项目进行评估时消失。
为什么会发生这种情况,我该怎么做才能确保评估update2
不会删除插入的元素?