R
Raf256
Hi,
I love short syntax, so I use macros like
FORi(10) t=a[b*i];
(where FORi expands into standard for loop)
and so on.
Yes I know its a bit evil but when later #undef such macros I think they can
be quite usefull and not making any "bad" in rest of code.
Such macro especially would be usefull in iterators, like
for( vector< shared_ptr< map<int,string> > > :: interator it =
tab.begin() ...
Typing the type of vector/container through with we want to iterate each
time is not very comfortable, also making a typedef for each containter
type is not always good.
Therefore I written small macro FORiter(tab) that iterates through an
conatiner providing iterator "ir"
FORiter( tab ) { *it=777; delete *it; }
(yes, I know aobut the foreach function but I dont find it comfortable in
some situations).
--------
The code:
#define FORiter(TAB) for( typeof(TAB.mTyp_Iterator) it = tab.begin();
it!=tab.end(); ++it)
and to have it working I added mTyp_Iterator to my std::vector<> wrapper,
template <class typ>
class cVector : public std::vector<typ> {
public:
static std::vector<typ>::iterator mTyp_Iterator; // XXX
[...]
It works fine in both g++ 3.3 and 3.4, but it gives warnings:
documentation for details
I love short syntax, so I use macros like
FORi(10) t=a[b*i];
(where FORi expands into standard for loop)
and so on.
Yes I know its a bit evil but when later #undef such macros I think they can
be quite usefull and not making any "bad" in rest of code.
Such macro especially would be usefull in iterators, like
for( vector< shared_ptr< map<int,string> > > :: interator it =
tab.begin() ...
Typing the type of vector/container through with we want to iterate each
time is not very comfortable, also making a typedef for each containter
type is not always good.
Therefore I written small macro FORiter(tab) that iterates through an
conatiner providing iterator "ir"
FORiter( tab ) { *it=777; delete *it; }
(yes, I know aobut the foreach function but I dont find it comfortable in
some situations).
--------
The code:
#define FORiter(TAB) for( typeof(TAB.mTyp_Iterator) it = tab.begin();
it!=tab.end(); ++it)
and to have it working I added mTyp_Iterator to my std::vector<> wrapper,
template <class typ>
class cVector : public std::vector<typ> {
public:
static std::vector<typ>::iterator mTyp_Iterator; // XXX
[...]
It works fine in both g++ 3.3 and 3.4, but it gives warnings:
raf256_vector.h:11: warning: implicit typename is deprecated, please see theraf256_vector.h:11: warning: `std::vector said:::iterator' is implicitly a typename
documentation for details