boostorg / multi_index

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

Bad Documentation or library source code #63

Closed heretic13 closed 2 years ago

heretic13 commented 2 years ago

Hello.

I have a task: Create a template class that internally uses a multi_index_container with a data type that depends on the class template parameter.

I wrote the implementation code for VS2022, but under Linux (gcc) it didn't want to compile.

The compiler throws errors, but I don't see any errors in the code.

Below is an example and my solution.

In this regard, I have questions for the developers:

  1. Fix the multi_index library code so that it compiles under Linux and Windows. or
  2. Make changes to the documentation. I reviewed carefully. boost::get<> is not mentioned as a means of obtaining keys for a container, it is an undocumented feature.
heretic13 commented 2 years ago

errors.log TestMi.cpp.txt

joaquintides commented 2 years ago

Hi,

Your fun2 incorrectly tries to invoke the template member function EpsContainer::get in a so-called dependent context without using the required template disambiguator. It should be written like this:

void fun2()
{
    const auto& byIdIndex1 = m_EndPoints.template get<0>();
    const auto& byIdIndex2 = m_EndPoints.template get<TagByEpId>();
}

Here you can find an explanation on why the template keyword is needed in this particular context. As it happens, MSVC accepts the code without template, but this is not in accordance with the C++ standard. You are not the first one to be bitten by this admittedly cumbersome rule of C++.

As for global boost::get (as applied to multi_index_container), it is documented. Look for "multi_index_container global functions for index retrieval" in class template multi_index_container reference. Global get is defined in namespace boost::multi_index but lifted to namespace boost by means of a using-declaration, as documented in header "boost/multi_index_container.hpp" synopsis (look for using multi_index::get there).

heretic13 commented 2 years ago

Excellent. Thanks for the clarification.

The topic can be closed.