The following code using Boost 1.72.0:
#include <iostream>
#include <string>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
struct Foo
{
int intProp_;
std::string stringProp_;
};
template<typename T>
struct LoggingLess
{
auto operator()(const T& first, const T& second) const
{
std::cout << "Comparing '" << first << "' to '" << second << "'\n";
return std::less<T>()(first, second);
}
};
int main()
{
using namespace boost::multi_index;
typedef multi_index_container<Foo, indexed_by<
ordered_non_unique<member<Foo, int, &Foo::intProp_>>,
ordered_non_unique<member<Foo, std::string, &Foo::stringProp_>, LoggingLess<std::string>>
>> FooContainer;
FooContainer container;
container.insert({ 1, "xyz" });
container.insert({ 2, "abc" });
std::cout << "Insert finished\n";
auto& intIndex = container.get<0>();
intIndex.modify_key(intIndex.begin(), [](int& value)
{
value += 100;
});
}
Has the following output:
Comparing 'abc' to 'xyz'
Insert finished
Comparing 'xyz' to 'abc'
Given that I'm only updating the integer value used in the first index, why does boost multi_index also compare the strings? This could have important performance implications on keys such as strings.
Is it a simple oversight or some limitation of the implementation?