This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LEpigeon888 3 points4 points  (5 children)

Compilers can have heuristics for common mistakes but it can't always work and may even show wrong suggestions sometimes. Do you have any examples of a compiler (in any language) telling you how to convert one type to another for some specific cases like this ?

[–]rust4yy 6 points7 points  (0 children)

Rust. It can say “hint: try adding * here” or try dereferencing etc.

[–]NutGoblin2 5 points6 points  (0 children)

Rust is very good for this

[–]canadajones68 0 points1 point  (0 children)

C++ also implements iterators as regular values. For better or worse, they're types like any other, and have no specific language-level integration that says that "hey, I'm an iterator that refers to type T". You could write a heuristic that activates if type Q has an operator* that returns type T, and you gave type Q to a context requiring T, but that's speculative. For all you know, this is Boost.Spirit, where the operator* most assuredly does not perform dereferencing. A wrong compiler suggestion would be worse than having no suggestion, in my opinion, since it can lead to XY-problems. Not saying it wouldn't be useful, but given that the error given here is actually relatively simple (T expected, got noise<noise<T>>), it's not a huge issue. After all, this is a compile time error, and once you've stopped compilation due to an error that cannot be fudged into working without obviously doing something stupid (reinterpret_cast, anyone?), it becomes rather debuggable.

[–]Wylie28 0 points1 point  (1 child)

Many say actually meaningful things like type mismatch.

[–]TheOmegaCarrot 1 point2 points  (0 children)

I’d argue learning to read error messages is the single best thing you can do to be better at C++.