boostorg / multi_index

Boost.org multi_index module
http://boost.org/libs/multi_index
45 stars 59 forks source link

[Feature request] make wrappers #44

Open denzor200 opened 3 years ago

denzor200 commented 3 years ago

Inspired by std::make_tuple for std::tuple.. I recently tried to create 4 simple make methods for types from this library:

template<typename T, typename M>
ordered_unique<T, M> make_ordered_unique(T, M)
{
    return {};
}

template<typename T, typename M>
ordered_non_unique<T, M> make_ordered_non_unique(T, M)
{
    return {};
}

template<typename... T>
indexed_by<T...> make_indexed_by(T...)
{
    return {};
}

template<typename T, typename I>
multi_index_container<T, I> make_multi_index_container(I)
{
    return {};
}

These methods allow me to write like this:

auto es = make_multi_index_container<employee>(make_indexed_by(
        make_ordered_unique(     tag<id>{},  BOOST_MULTI_INDEX_MEMBER(employee,int,id){}),
        make_ordered_non_unique( tag<name>{},BOOST_MULTI_INDEX_MEMBER(employee,std::string,name){}), 
        make_ordered_non_unique( tag<age>{}, BOOST_MULTI_INDEX_MEMBER(employee,int,age){})));

..And the same code without methods (how it works now):

typedef multi_index_container<
  employee,
  indexed_by<
    ordered_unique<
      tag<id>,  BOOST_MULTI_INDEX_MEMBER(employee,int,id)>,
    ordered_non_unique<
      tag<name>,BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>,
    ordered_non_unique<
      tag<age>, BOOST_MULTI_INDEX_MEMBER(employee,int,age)> >
> employee_set;

employee_set es;

In my opinion, the variant with make-methods is much better. Why not support for these methods on the library side?

joaquintides commented 3 years ago

Hi Denis, thank you for the suggestion. I don't see this feature as particularly appealing, at least in its current form: