jeudi 23 avril 2020

Why is it impossible to create an std::set

I have a class with std::set<const std::string> members which compiles fine in Clang 10.0.1 on macOS, but does not with GCC 5.4.0. MRE below

#include <set>
#include <string>

class Foo {
  std::set<const std::string> bar; ///<--- error ‘const _Tp* __gnu_cxx::new_allocator<_Tp>::address(__gnu_cxx::new_allocator<_Tp>::const_reference) const [with _Tp = const std::__cxx11::basic_string<char>; __gnu_cxx::new_allocator<_Tp>::const_pointer = const std::__cxx11::basic_string<char>*; __gnu_cxx::new_allocator<_Tp>::const_reference = const std::__cxx11::basic_string<char>&]’ cannot be overloaded

public:
  Foo() {}
};

int main(int argc, char *argv[]) {
  Foo f;
  return 0;
}

Compiler invocation:

/usr/bin/g++ -std=c++11 test.cpp

If instead I use non-const string it works. Is this a problem of an outdated standard library version?

Aucun commentaire:

Enregistrer un commentaire