Bad Documentation or library source code
heretic13 opened this issue · 3 comments
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:
- Fix the multi_index library code so that it compiles under Linux and Windows.
or - 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.
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).
Excellent.
Thanks for the clarification.
The topic can be closed.