3

Out of 3 compilers only gcc accepts this code. I guess clang problem is that it uses antique libstdc++, but MSVC and GCC should support ranges code.

What is the standard mandated behavior?

#include<array>
#include<algorithm>
#include<iostream>
#include<map>
#include<set>
#include<ranges>

constexpr std::array<std::pair<int, double>,2> arr{std::pair{1,1.1},std::pair{2,2.2}};

int main(){
    auto it = std::ranges::find(arr | std::views::keys , 2);    
    std::cout << *it;
}

https://godbolt.org/z/hnnb38cPM

NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277

1 Answers1

4

This needs P2017R1 (conditionally borrowed ranges) to work; without that, arr | std::views::keys is not a borrowed_range, and so ranges::find returns dangling.

Presumably the MSVC version on godbolt doesn't have that paper implemented.

T.C.
  • 133,968
  • 17
  • 288
  • 421
  • Ah it is C++23 thing, so that is why it is still not implemented... https://en.cppreference.com/w/cpp/compiler_support – NoSenseEtAl Jun 30 '21 at 13:23