Skip to content

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

@phimuemue

Description

@phimuemue

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions