1

Referring to this answer:

https://stackoverflow.com/a/44883472/9620309

Even with the latest XCode Beta (10.1), this feature doesn't seem to be available on macOS High Sierra ?

I'd assume the latest Apple-clang (10.0.0) should support C++17 by now, but when i compile with the c++17 flag, it says that there's no member named extract in std::map ...

Or am i missing something ?

Edit (mcve): http://coliru.stacked-crooked.com/a/78715cf9485374d8

// clang++ -std=c++17 -Wall -pedantic main.cpp
#include<map>
#include<string>
#include<algorithm>

int main() {
  std::map<int, std::string> m{ {10, "potato"}, {1, "banana"} };
  auto nodeHandler = m.extract(10);
  nodeHandler.key() = 2;
  m.insert(std::move(nodeHandler)); // { { 1, "banana" }, { 2, "potato" } }
}
EllipsenPark
  • 127
  • 9
  • 4
    Well, you're definitely missing a [mcve], without which it is logically impossible to authoritatively conclude whether your hypothesis is correct, or you made a non-obvious typo of some sort; at least not without having specific knowledge of clang's C++17 support. – Sam Varshavchik Oct 16 '18 at 11:30
  • @SamVarshavchik added ... – EllipsenPark Oct 16 '18 at 12:12
  • 3
    Please post the code, not a link to it. – molbdnilo Oct 16 '18 at 12:14
  • 1
    Ugh why do Apple stick their own version numbers over clang? There's no such a thing as upstream version 10 clang (latest clang is 7), so it's a mess to understand what exactly that corresponds to... – Matteo Italia Oct 16 '18 at 12:21
  • @molbdnilo there you go ... – EllipsenPark Oct 16 '18 at 12:21
  • @MatteoItalia the output of `clang --version` : `Apple LLVM version 10.0.0 (clang-1000.11.45.5)`. How that corresponds to non-apple clang ? I've no clue ... – EllipsenPark Oct 16 '18 at 12:23
  • @MatteoItalia then again, coliru clang (5.0.0) doesn't compile it, either – EllipsenPark Oct 16 '18 at 12:25
  • @EllipsenPark: https://gcc.godbolt.org/z/D_gGRQ bizarre, clang 5, 6 and 7 work fine on Godbolt: but again, it's not a thing of the compiler proper, but of the standard library. – Matteo Italia Oct 16 '18 at 12:28
  • @EllipsenPark: https://gcc.godbolt.org/z/otPIaD aaah ok, using libc++ it starts working only from clang 7. Maybe XCode 10.1 ships an older version. – Matteo Italia Oct 16 '18 at 12:32
  • This compiles for me with gcc 8.1.1, so this is incomplete C++17 support in that compiler. The C++ library has gotten huge, recently, so I guess that version of clang doesn't implement everything, yet. I'm sure a future version will cover it. There are some library bits that are missing in gcc as well, it seems, so just have to work around them. – Sam Varshavchik Oct 16 '18 at 13:07

1 Answers1

2

So, to answer my own question, as of the date of writing this, the C++17 map::extract methods are NOT available in the default C++ Environment on macOS, even with the latest beta as mentioned above.

As pointed out by Matteo above, it's available with non-Apple clang 7 and the matching libc++.

So my current workaround is using CMake and clang 7 from homebrew to compile what i need as a library, and then link against it.

EllipsenPark
  • 127
  • 9