As far as I like to use lambda to do simple things, it can degenerate quickly :)
In your case, since this is a little more complicated, I would rely on either a free function or a predicate comparator.
The advantage of a predicate is to define types more clearly so that it is usually easier to enter.
In addition, for readability, I usually type in my indexes, which gives:
namespace mi = boost::multi_index; struct FooComparator { bool operator()(Foo const& lhs, Foo const& rhs) const { return lhs.bar().property() < rhs.bar().property(); } }; typedef mi::ordered_unique < mi::tag<tag_prop>, mi::identity<Foo>, FooComparator > foo_bar_index_t; typedef boost::multi_index_container < Foo, mi::indexed_by < foo_bar_index_t,
The predicate approach requires more boilerplate code, but it allows you to perfectly separate the comparison logic from the index definition, which itself is separate from the container definition.
Clear separation makes it easy to see the structure at a glance.
Matthieu M.
source share