0

I'm just trying to figure out how I can use clang++ to compile this:

for (int i : std::ranges::iota_view{1, 10})
        std::cout << i << ' ';

The latest Apple Clang failed to recognize iota_view, and so I downloaded LLVM 15.0.7 using Homebrew. This suggests that 15.0.7 is compatible with ranges, but I'm still having trouble with it not being recognized, even with the -fexperimental-library, -std=c++20, and -stdlib=libc++ flags. Anyone know how to resolve this, short of just using gcc instead?

Oreese17
  • 7
  • 1

1 Answers1

0

It works with LLVM experimental C++ standard library.

#include <ranges>
#include <iostream>
#include <algorithm>

int main() {
    for (int i : std::ranges::iota_view(1, 10))
        std::cout << i << ' ';
    std::cout << '\n';
}
clang main.cc -std=c++20 -stdlib=libc++ -fexperimental-library
./a.out
1 2 3 4 5 6 7 8 9 

https://godbolt.org/z/5frq61K4Y

See also libc++ C++20 Status.

273K
  • 29,503
  • 10
  • 41
  • 64
  • 3
    Do you know how I could resolve "library not found for -lc++experimental" when using the experimental flag? – Oreese17 Feb 12 '23 at 23:57
  • @Oreese17 Take a look at [Using a different version of the C++ Standard](https://libcxx.llvm.org/UsingLibcxx.html#id2): On compilers that do not support the `-fexperimental-library` flag, users can define the `_LIBCPP_ENABLE_EXPERIMENTAL` macro and manually link against the appropriate static library (usually shipped as `libc++experimental.a`) to get access to experimental library features. Perhaps you should pass a full path `/usr/.../libc++experimental.a` instead of `-lc++experimental` or add a search path `-L/usr/.../` to `libc++experimental.a` when use `-lc++experimental`. – 273K Feb 13 '23 at 16:29