Boost.flyweight and Boost.MPL

I have a question regarding fly options, given the definition below, based on 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");

what does boost::mpl::_1u mean boost::mpl::_2? When are you appointed?

boost::mpl::_1most likely std::string. boost::mpl::_2should be size_t? If true, then how to subtract? I do not understand how key_type is selected.

I read http://www.boost.org/doc/libs/1_41_0/libs/flyweight/doc/tutorial/lambda_expressions.html , but this is my first contact with Boost.MPL and this is not enough :)

+5
source share
1 answer

boost::mpl::_1 boost::mpl::_2 ; , . ( , n-arity, , (nm) -), - ( " " , ) ..

, , , , -, , , .

, typedef

typedef 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>
> hashed_factory;

, hashed_factory :

typedef typename
    boost::mpl::apply<
       hashed_factory,
       X,
       Y
    >::type result; // invoke hashed_factory with X and Y
                    // _1 is "replaced" by X, _2 by Y

Flyweight code, , _1 _2 ( ). , std::string, .

, MPL , MPL, , - .

+4

All Articles