3

I'm getting this error on macOS, with clang, using std=c++20 or std=c++2b .

error: no member named 'split' in namespace 'std::ranges::views'
  auto tokensRanges = blob | std::views::split('.');

Compiler details:

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.6.0

The same code works with Visual Studio cl.

What could be a solution to fix this error?

Later edit: std::ranges::views::split yields the same error. https://en.cppreference.com/w/cpp/ranges/split_view is a c++20 feature.

A minimal example that reproduces the problem:

#include <iostream>
#include <ranges>
#include <string>

auto main() -> int
{
    std::string blob = "test1.test2.test3";

    auto tokensRanges = blob | std::ranges::views::split('.');

    for (const auto &tokenRange : tokensRanges) {
        std::cout<<std::string(tokenRange.begin(), tokenRange.end())<<"\n";
    }
    return 0;
}

Compilation:

clang++ -o bin -std=c++20 test.cpp
Anton Korobeynikov
  • 9,074
  • 25
  • 28
yonutix
  • 1,964
  • 1
  • 22
  • 51
  • 1
    Get a compiler that has support for the feature you want to use. – sweenish Aug 23 '23 at 10:01
  • 1
    Technically, Apple clang [claims support](https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_library_features) for ranges in 14.0.3, but I'm not sure if I trust that. – Yksisarvinen Aug 23 '23 at 10:02
  • 1
    Maybe pass `-fexperimental-library` to the compiler? – cpplearner Aug 23 '23 at 10:16
  • 1
    The range I'm using is part of the C++20 https://en.cppreference.com/w/cpp/ranges/split_view , I assumed it should be already supported by clang. – yonutix Aug 23 '23 at 10:25
  • 1
    @cpplearner It doesn't fix the problem and it doesn't really make sense because I'm using a c++20 feature which shouldn't be experimental. – yonutix Aug 23 '23 at 10:27
  • @yonutix It does make sense, because libc++ treated its implementation of ranges as experimental until version 16. I have no idea which version is used by Apple Clang (or which version it's based on). According to [cppreference](https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_library_features), Apple Clang 14.0.3 claims full unconditional support of ranges, but cppreference may be wrong - I have no idea where to find official source on that. Check first if it really is supported already, and if yes, file a bug on the compiler. – Yksisarvinen Aug 23 '23 at 10:56
  • These days, AppleClang versions align pretty closely with real clang. So you'd have to see at what version clang claimed to support the feature. Even so, Apple makes changes to their version of clang, it would seem. OP might be better off with a dev container using a more recent clang or gcc. And then, a compiler adding a flag doesn't also imply full support. No compiler truly supports modules, but all of them have a C++20 flag. It's a whole thing, and it's messy and annoying. – sweenish Aug 23 '23 at 12:01
  • Seems normal for Apple-Clang - always some things different than in the normal clang version. – ABaumstumpf Aug 23 '23 at 21:34

0 Answers0