Topic: var::x
Author: "Lo c Tr gan" <loic.tregan@hol.fr>
Date: 1998/04/23 Raw View
>In any case, even without this problem, your macro doesn't work if v is
>const.
fixed !
#define forallconst(t,v,i) for( t::const_iterator i =(v).begin(); i !=
(v).end(); i++)
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Lo c Tr gan" <loic.tregan@isdnet.net>
Date: 1998/04/19 Raw View
I wanted to define this macro :
#define forall(v, i) for( v::iterator i=v.begin(); i != v.end(); i++)
it does not work (in BC++) bc :: is not defined for a variable.
is BC wrong or is it not allowed in the draft ? any reason if it is not ?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/04/19 Raw View
:: can only be applied to a namespace or class name,
or to nothing. It can't be applied to a variable name.
And yes soem people would like either:
- to apply :: to a variable
- to have typeof
example:
int i;
typeof (i) j;
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Tom McKearney" <no@spam.com>
Date: 1998/04/20 Raw View
Lo c Tr gan wrote in message <6hac24$8lb$2@news2.isdnet.net>...
>I wanted to define this macro :
>
>#define forall(v, i) for( v::iterator i=v.begin(); i != v.end(); i++)
>
>it does not work (in BC++) bc :: is not defined for a variable.
>is BC wrong or is it not allowed in the draft ? any reason if it is not ?
the :: operator is used on _types_, not variables.
you could rewrite it as:
#define forall(v, i, t) for( t::iterator i=v.begin(); i != v.end(); i++)
where 't' is the type.
Tom McKearney
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1998/04/20 Raw View
"Lo c Tr gan" <loic.tregan@isdnet.net> writes:
|> I wanted to define this macro :
|>
|> #define forall(v, i) for( v::iterator i=v.begin(); i != v.end(); i++)
|>
|> it does not work (in BC++) bc :: is not defined for a variable.
|> is BC wrong or is it not allowed in the draft ?
BC is correct. A variable is NEVER allowed as the left operator of ::.
|> any reason if it is not ?
Probably because no one ever even suggested such a thing. What could
have been proposed (but wasn't either, to my knowledge) would have been
something along the lines of v.iterator.
In any case, even without this problem, your macro doesn't work if v is
const.
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient e objet --
-- Beratung in objektorientierter Datenverarbeitung
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Chuck McCorvey" <chuckm@solutionware.com>
Date: 1998/04/20 Raw View
Lo c Tr gan wrote in message <6hac24$8lb$2@news2.isdnet.net>...
>I wanted to define this macro :
>
>#define forall(v, i) for( v::iterator i=v.begin(); i != v.end(); i++)
>
>it does not work (in BC++) bc :: is not defined for a variable.
>is BC wrong or is it not allowed in the draft ? any reason if it is not ?
>---
I tried this in VC++ 5.0:
std::list<int> list;
#define forall(t, v, i) for(t::iterator i=v.begin(); i != v.end(); ++i)
forall(std::list<int>, list, iter)
{
}
The above worked while your version (minus the t macro argument failed in
the same way as you reported in BC++. I have not yet had the chance to look
through the CD2 to see if the compilers are wrong, but I have a feeling that
they are not.
Also, notice that I used "++i" rather than "i++" in the macro. This can
make a significant performance difference as the former avoids the necessity
of creating a temporary.
--
Chuck McCorvey
Creative SolutionWare, Inc.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/04/20 Raw View
Lo=EFc Tr=E9gan wrote:
>=20
> I wanted to define this macro :
>=20
> #define forall(v, i) for( v::iterator i=3Dv.begin(); i !=3D v.end(); i+=
+)
>=20
> it does not work (in BC++) bc :: is not defined for a variable.
> is BC wrong or is it not allowed in the draft ? any reason if it is not=
?
The :: operator needs a type, not a variable. You should change your
macro into a templated function, similar to foreach(), but defined for a
container instead of for iterators:
template <class V, class Function> Function forall(V &v, Function f)
{
return foreach(v.begin(), v.end(), f); =20
}
then you just replace
forall(container, iter) function(iter);
with
forall(container, function);
However, if the body of your for() loop is neither a function nor a
function object, you'll need to learn how to use the standard library
function object binders, which can be a little intimidating at first.
I wouldn't recommend this technique, however; using foreach() directly
is almost as easy as using forall(), and keeps things simpler.
By the way, can anyone explain why foreach(first, last, f) returns f?
I'm not objecting, just curious.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]