0

I have the following simple iteration over yaml-cpp node that contains a list of items:

for (const auto &group_entry: node["groups"]) { /*...*/ }

The code compiles and works as expected, but in CLion IDE it is addressed as an error, claiming "const YAML::Node' is not a valid range type". Is it any problem with this and if not, how could I remove this annoying highlight? This is a C++17 project.

1 Answer 1

1

Generally, the compiler is the better judge of whether some code is valid or not. Your code is perfectly fine.

The error message also gives us a hint at what seems to be the problem: It talks about a range type which simply is not a thing in this context (C++20 ranges library does exist but is irrelevant here). The range-for you are using simply requires the range-expression to be either an array, have begin and end functions defined, or be a braced-init-list.

So what we are seeing is likely the result of CLion not correctly checking this restraint, possibly by re-using code from JetBrains' other IDEs that is not appropriate for C++. The issue you created is therefore appropriate way of making this error go away.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.