Visual Studio 2017 claims that they support C++17 range based for loops. However when I try to compile I get errors indicating that it is using the C++11 style. Has anyone managed to get sentinel loops working in VS 2017?
Here is some example code. I've gutted this code to make it short, so it obviously won't work properly, but it should compile.
struct MyExampleIterator
{
int operator*() const { return 0; }
MyExampleIterator& operator++() { return *this; }
};
class MyExampleSentinel {};
bool operator!=(const MyExampleIterator& a, const MyExampleSentinel& b) { return true; }
struct MyExampleRange
{
MyExampleIterator begin() { return MyExampleIterator(); }
MyExampleSentinel end() { return MyExampleSentinel(); }
};
If I try to use this class in a range based for loop in VS2017 (15.2) I get error C3538: in a declarator-list 'auto' must always deduce to the same type
MyExampleRange range;
for (auto i : range) {} // error C3538
But if I manually construct the C++17 standard code it compiles fine:
// Compiles fine
MyExampleRange range;
{
auto && __range = range;
auto __begin = __range.begin();
auto __end = __range.end();
for (; __begin != __end; ++__begin) {
auto i = *__begin;
}
}
!=is always true).