次の例は、私が何を意味するかを示しています。
#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
によって挿入された要素が削除されないようにするにはどうすればよいですか?