Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use boost::multi_index::key with `const& noexcept` member function #24

Closed
phimuemue opened this issue Jun 5, 2019 · 3 comments

Comments

@phimuemue
Copy link

commented Jun 5, 2019

The following program does not compile (https://wandbox.org/permlink/odsAUNRroBveTxqw). (I tested clang 8.0.0 and g++ 9.1.0.)

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key.hpp>

struct S final {
    int m_n;
    S(int n) noexcept : m_n(n) {}
    int Get() const & noexcept { // removing "& noexcept" makes it compile
        return m_n;
    }
};

int main() {
    boost::multi_index::multi_index_container<
        S,
        boost::multi_index::indexed_by<
            boost::multi_index::ordered_unique<
                boost::multi_index::key<&S::Get>
            >
        >
    > container;
}

clang 8.0.0 reports:

In file included from prog.cc:3:
/opt/wandbox/boost-1.70.0/clang-8.0.0/include/boost/multi_index/key.hpp:77:22: error: implicit instantiation of undefined template 'boost::multi_index::detail::typed_key_impl<int (S::*)() const & noexcept, &S::Get, void>'
struct key_impl<Key>:typed_key_impl<decltype(Key),Key>{};
                     ^
/opt/wandbox/boost-1.70.0/clang-8.0.0/include/boost/multi_index/key.hpp:134:23: note: in instantiation of template class 'boost::multi_index::detail::key_impl<&S::Get>' requested here
  using type=typename key_impl<Keys...>::type;
                      ^
/opt/wandbox/boost-1.70.0/clang-8.0.0/include/boost/multi_index/key.hpp:140:1: note: in instantiation of template class 'boost::multi_index::detail::limited_size_key_impl<&S::Get>' requested here
using key=typename detail::limited_size_key_impl<Keys...>::type;
^
prog.cc:18:37: note: in instantiation of template type alias 'key' requested here
                boost::multi_index::key<&S::Get>
                                    ^
/opt/wandbox/boost-1.70.0/clang-8.0.0/include/boost/multi_index/key.hpp:38:8: note: template is declared here
struct typed_key_impl;
       ^
prog.cc:20:9: error: expected a type
        >
        ^
prog.cc:21:5: error: expected a type
    > container;
    ^
prog.cc:21:7: error: C++ requires a type specifier for all declarations
    > container;
      ^
4 errors generated.

I suspect that the problem is that key_impl is not specialized for const& and/or noexcept member functions.

@phimuemue phimuemue changed the title Cannot use boost::multi_index::key with noexcept member function Cannot use boost::multi_index::key with `const& noexcept` member function Jun 5, 2019

joaquintides added a commit that referenced this issue Jun 9, 2019
@joaquintides

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

Thank you for your report. I've added support for volatile/ref-qualified/noexcept memfuns in e49ae2b. Could you please test locally if your problem is solved?

@phimuemue

This comment has been minimized.

Copy link
Author

commented Jun 11, 2019

Thank you. I compiled it locally with Visual Studio, and could not observe any problems, albeit the compiler warns:

key.hpp(90): warning C4003: not enough arguments for function-like macro invocation 'BOOST_MULTI_INDEX_KEY_REMOVE_MEMFUN_NOEXCEPT'`
@joaquintides

This comment has been minimized.

Copy link
Member

commented Jun 11, 2019

Warning fixed in a7ef250.

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.