Search code examples
c++visual-studioc++17range-v3compiler-explorer

ranges::subrange in MSVC on Compiler Explorer


The following code compiles and runs just fine with GCC 8.3 and with Clang 10.0.1, whereas it fails miserably on MicroSoft shiny compiler.

#include <vector>
#include <range/v3/view/group_by.hpp>

int main(){
    std::vector<int> edits{1,1,3,2,2,4,4,4,4,1,1,3,3,2};
    auto xxx = ranges::subrange(edits.begin(), edits.end());
}

Is there some flag that I'm missing?


Solution

  • You've specified /std:c++17 and ranges::subrange is not present in C++ 17. Ranges-v3 also requires C++ 20 because it uses Concepts.

    Compiling instead with /std:c++latest succeeds.

    The errors turn out to be coming from a Concepts emulation layer bundled in Ranges v3, which evidently does not work correctly on the latest Visual C++'s C++17 mode. According to the documentation, it needed experimental compiler options even when it did work, so best to just turn on C++ 20 support when using Microsoft's compiler.