osdir.com
mailing list archive

Subject: RE: STL iterators in gcc 3.2 - msg#00320

List: gcc.help

Date: Prev Next Index Thread: Prev Next Index

>
> From what I've noticed, the old 2.95 implemented std::vector iterators as
> just plain pointers (|std::vector<double>| used |double*|'s for iteration).
> It looks like now the library is using class abstractions for its iterators.
> This has many benefits, but it also means that some code, e.g.,
>
> void foo(double*);
> std::vector<double> myvect;
> foo(myvect.begin());
>
> will no longer work, since |myvect.begin()| does not necessarily produce a
> double*.
>
> I have found in order to make your code independent of the iterator object,
> you have to either use templates,
>
> template <typename OutputIterator>
> void foo(OutputIterator);
>
> or you must specifically use the iterator type defined by your container,
>
> void foo(std::vector<double>::iterator);
>
> I don't know if there is an easier conversion than either of these, but I
> would be interested in hearing any other ideas.

Of course, this explains vey well he problem. But I cannot use new
definitions of the methods using template arguments instead of pointers,
as they come from a library... So I think I'll have to use a previous
version of gcc, at least until I have time to change my code to adhere to
the standards ;-)

Anyway, thank you very much.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alberto Garcia Raboso
CERN / EP
CH-1211 Geneva 23, Switzerland
Office 40-2B-19 (+41 22 76 71626)
E-Mail: Alberto.Garcia.Raboso@xxxxxxx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Well, farewell, my hobbits! You should come safe to your own
homes now, and I shall not be kept awake for fear of your
peril. We will send word when we may, and some of us may yet
meet at times; but I fear that we shall not all be gathered
together ever again.

The return of the King. J.R.R. Tolkien
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

RE: STL iterators in gcc 3.2

> > 1.- Whereas I didn't need it before, now I have to use the "using > namespace std" directive if I want to use cout, cin,... and all this > stuff. Why the change? > This version of gcc (and g++) is more standards compliant, hence the new necessity of std:: when using the iostreams and other standard library features. > 2.- This is more serious. In my programs I use a lot of STL > vectors, and > so, iterators too. When I had a method with a pointer > argument, I passed a > random iterator to it. It worked fine with previous versions > of gcc, but > not with 3.2. Is there any way to get it work or do I have to > come back to > an older version? > >From what I've noticed, the old 2.95 implemented std::vector iterators as just plain pointers (|std::vector<double>| used |double*|'s for iteration). It looks like now the library is using class abstractions for its iterators. This has many benefits, but it also means that some code, e.g., void foo(double*); std::vector<double> myvect; foo(myvect.begin()); will no longer work, since |myvect.begin()| does not necessarily produce a double*. I have found in order to make your code independent of the iterator object, you have to either use templates, template <typename OutputIterator> void foo(OutputIterator); or you must specifically use the iterator type defined by your container, void foo(std::vector<double>::iterator); I don't know if there is an easier conversion than either of these, but I would be interested in hearing any other ideas. --Matt

Next Message by Date: click to view message preview

Problems with stringstream

Hi, I'm trying to build the following program using gcc 3.0.3. It compiles okay but when it runs there is no output. When I compile and run on MS Visual C++ the output is "Sample string" as expected. I did a quick check of the FAQ for this topic but couldn't find any information. Any suggestions are appreciated! #include <iostream> #include <sstream> #include <string> using namespace std; int main () { stringstream oss; string mystr; oss << "Sample string"; mystr=oss.str(); cout << mystr; return 0; } Thanks, Mark

Previous Message by Thread: click to view message preview

RE: STL iterators in gcc 3.2

> > 1.- Whereas I didn't need it before, now I have to use the "using > namespace std" directive if I want to use cout, cin,... and all this > stuff. Why the change? > This version of gcc (and g++) is more standards compliant, hence the new necessity of std:: when using the iostreams and other standard library features. > 2.- This is more serious. In my programs I use a lot of STL > vectors, and > so, iterators too. When I had a method with a pointer > argument, I passed a > random iterator to it. It worked fine with previous versions > of gcc, but > not with 3.2. Is there any way to get it work or do I have to > come back to > an older version? > >From what I've noticed, the old 2.95 implemented std::vector iterators as just plain pointers (|std::vector<double>| used |double*|'s for iteration). It looks like now the library is using class abstractions for its iterators. This has many benefits, but it also means that some code, e.g., void foo(double*); std::vector<double> myvect; foo(myvect.begin()); will no longer work, since |myvect.begin()| does not necessarily produce a double*. I have found in order to make your code independent of the iterator object, you have to either use templates, template <typename OutputIterator> void foo(OutputIterator); or you must specifically use the iterator type defined by your container, void foo(std::vector<double>::iterator); I don't know if there is an easier conversion than either of these, but I would be interested in hearing any other ideas. --Matt

Next Message by Thread: click to view message preview

Problems with stringstream

Hi, I'm trying to build the following program using gcc 3.0.3. It compiles okay but when it runs there is no output. When I compile and run on MS Visual C++ the output is "Sample string" as expected. I did a quick check of the FAQ for this topic but couldn't find any information. Any suggestions are appreciated! #include <iostream> #include <sstream> #include <string> using namespace std; int main () { stringstream oss; string mystr; oss << "Sample string"; mystr=oss.str(); cout << mystr; return 0; } Thanks, Mark
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by