vendredi 26 février 2016

How do I conditionally add with boost MPL?

I am trying to evaluate a bitset's value based on the type arguments provided. The function I have right now is this:

template <class Set, class PartialSet>
constexpr auto tupleBitset() {
    using type = 
        typename mpl::fold<
            PartialSet,
            mpl::integral_c<unsigned long long, 0>,
            mpl::eval_if<
                mpl::has_key<Set, mpl::_2>,
                mpl::plus<
                    mpl::_1, 
                    mpl::integral_c<unsigned long long, 1ull << getIndex<Set, mpl::_2>()>
                >,
                mpl::_1
            >
        >::type;
    return std::bitset<mpl::size<Set>::value>(type::value);
}

Basically the gist of the function's intent is to be able to create a bitset whose bits are created based off the intersection of Set and PartialSet, both of which are mpl::sets. The function getIndex is also provided:

template <class Set, class Index>
constexpr auto getIndex() {
    return mpl::distance<
            mpl::begin<Set>::type,
            mpl::find<Set, Index>::type
        >::type::value;
};

This approach doesn't seem to work, with the compile errors evaluating down to the following:

'value' is not a member of 'boost::mpl::same_as<U1> in 'not.hpp'
'C_': invalid template argument for 'boost::mpl::aux::not_impl', expected compile-time constant expression in not.hpp

Is it possible that the left shift is not a compile time constant? And I am also not entirely sure where I am supposed to use mpl::lambda, mpl::quote, mpl::apply, and mpl::protect, so that may also be part of the issue.

Aucun commentaire:

Enregistrer un commentaire