is implicitly a typename warning

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:

raf256_vector.h:11: warning: `std::vector said:
::iterator' is implicitly a typename
raf256_vector.h:11: warning: implicit typename is deprecated, please see the
documentation for details
 
R

Raf256

Raf256 said:
#define FORiter(TAB) for( typeof(TAB.mTyp_Iterator) it = tab.begin();
it!=tab.end(); ++it)

errata:

#define FORiter(TAB) for( typeof(TAB.mTyp_Iterator) it = TAB.begin();
it!=TAB.end(); ++it)
 
V

Victor Bazarov

Raf256 said:
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: `std::vector said:
::iterator' is implicitly a typename
raf256_vector.h:11: warning: implicit typename is deprecated, please see the
documentation for details

-----
The problem

How can I do code above the c++ and/or gnu g++ way - using some "typename"
afaik?


Why do you care? You're using 'typeof', which is non-standard anyway...
Never mind. Change the XXX line to read

static typename std::vector<typ>::iterator mTyp_Iterator;

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top