Re: membership in a set in C++
On Jul 16, 5:48 am, sara <sarasar...@gmail.com> wrote:
Is there any operator like 'in' (membership in a set) in the c++?
char x
if (x in {'a', 'b','c','d'})
//do something;
There's no set type in the language proper, so there are no
language constructs to support it.
I know that it can be simulated using an array for set but I
wonder it there is more direct way to do this.
At present, no. I think the standards committee is considering
two extensions, a sort of language supported for_each, and some
extended forms of constant initialization, which together might
allow something like:
foreach ( char x in std::set< char > ?? 'a', 'b', 'c', 'd' ?? )
...
I'm very unfamiliar with these proposals, however (the ?? in my
example simply means that I haven't the slightest idea of the
syntax really being proposed), nor how likely they are to make
it into the next version of the standard.
And of course, once adopted by the standard, who knows how long
it will take before compilers actually implement it.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34