Discussion:
Ranged Based For With STL Template Container
Dixon Ryan (ETAS/ERS-ENG1)
2017-07-20 18:28:54 UTC
Permalink
Hello Alan,

Emacs -Q 25.2 ( ~~15th May cc 5.33)
Please open:

someVar is not correctly highlighted.

#include <iostream>

int main()
{
for ( const std::map<SomeKey, SomeValue>::value_type& someVar : InSomeMap )
{
;
}
return 0;
}


Is it possible to request that all Template types are consistently coloured? I know you have discussed this before, but I think the best thing to is to just not perform any highlighting on template parameters since, at least, they will then be the same colour. Unless.. I am missing an obvious use case where such a thing is not possible.

Cheers.
Alan Mackenzie
2017-07-22 21:22:46 UTC
Permalink
Hello, Ryan.
Post by Dixon Ryan (ETAS/ERS-ENG1)
Hello Alan,
Emacs -Q 25.2 ( ~~15th May cc 5.33)
someVar is not correctly highlighted.
#include <iostream>
int main()
{
for ( const std::map<SomeKey, SomeValue>::value_type& someVar : InSomeMap )
{
;
}
return 0;
}
OK. The problem here is the argument list in the template brackets. Up
till now, C++ has disallowed commas and &&s and ||s in <> argument lists
in certain contexts, including within the parentheses of control
statements, because of ambiguities in C++.

In particular, in something like

if (a<0 || b>99)

, the "<" and ">" should not be treated as template brackets.

Up till now, commas, &&s, and ||s have been disallowed in "for"
statements. However, with type names including template brackets now
being common, the balance of advantages now lies in recognising commas
inside "for" statements.

I don't think the same is true for "if", "while", etc. statements,
which, I think, contain declarations more rarely.

Would you please test the attached patch in your real code, and either
confirm to me that the patch is effective, or tell me what still isn't
working properly.

Again, thank you for condensing the problem down to an easy to work with
snippet.
Post by Dixon Ryan (ETAS/ERS-ENG1)
Is it possible to request that all Template types are consistently
coloured? I know you have discussed this before, but I think the best
thing to is to just not perform any highlighting on template
parameters since, at least, they will then be the same colour.
Unless.. I am missing an obvious use case where such a thing is not
possible.
By a template type, I think you mean something like

std::map<SomeKey, SomeValue>::value_type

. It is not easy to cease fontifying such types, because there is no
abstraction "template type" in CC Mode - it simply isn't structured that
way. Such a change would involve complicated amendments spread widely
throughout CC Mode.

The template parameters (by which, I take it, you mean "Somekey", and
"SomeValue") will be fontified as types when they are known to be types
from some other use of them in the buffer. Are you suggesting here a
user option to disable the fontification of such parameters? Such an
option would not be too difficult to implement.
Post by Dixon Ryan (ETAS/ERS-ENG1)
Cheers.
--
Alan Mackenzie (Nuremberg, Germany).
Loading...