【发布时间】:2011-10-20 07:17:33
【问题描述】:
我有一个关于享元选项的问题,给出下面的定义,基于http://www.boost.org/doc/libs/1_40_0/libs/flyweight/test/test_basic.cpp
typedef boost::flyweights::flyweight<
std::string,
boost::flyweights::tag<int>,
boost::flyweights::static_holder_class<boost::mpl::_1>,
boost::flyweights::hashed_factory_class<
boost::mpl::_1,
boost::mpl::_2,
boost::hash<boost::mpl::_2>,
std::equal_to<boost::mpl::_2>,
std::allocator<boost::mpl::_1>
>,
boost::flyweights::simple_locking,
boost::flyweights::refcounted
> StringFlyweight;
StringFlyweight test1("Hello World");
boost::mpl::_1 和 boost::mpl::_2 有什么价值?什么时候分配?
boost::mpl::_1 很可能是std::string。 boost::mpl::_2 应该是 size_t 吗?如果属实,如何扣除?
我不明白 key_type 是如何选择的。
我已经阅读了http://www.boost.org/doc/libs/1_41_0/libs/flyweight/doc/tutorial/lambda_expressions.html,但这是我第一次接触 Boost.MPL,还不够:)
【问题讨论】:
标签: c++ templates boost boost-mpl