Topic: recursive STL
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/06/15 Raw View
In article <394667C6.B032D83D@jps.net>, Dennis Yelle <dennis51@jps.net>
writes
>I tried the code above with
>gcc version 2.95.2 19991024 (release)
>and I was surprised to see that it compiled with
>no errors and no warnings.
I have a vague recollection of Andy Koenig discovering that recursive
uses of vector and deque worked on the compilers he tried. However I
also remember that we decided that it should not be required to work
even though it was an elegant solution to programming some complicated
trees.
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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: "P.J. Plauger" <pjp@plauger.com>
Date: 2000/06/15 Raw View
In article <003701bfd4d1$598f4c40$46d13118@mnis.com>,
"Mike Carrato" <mike@carrato.com> wrote:
> Does Standard C++ have any guarantees about recursive constructs such
as
> these, either directly or indirectly. By indirectly, I mean, do the =
> basic
> requirements for standard containers guarantee recursion like this =
> should
> work?
Quite the contrary. The C++ Standard defines template class allocator
in such a way that it can't work properly with incomplete types. Hence,
a fully conforming implementation should not permit the declaration
of any container class, at least if it uses the default allocator.
> Is this a bug in the implementation of MSVC's standard library, or do
> vectors and deques just "happen to work"?
They happen to work in the current release because the VC++ compiler
doesn't support a fully conforming implementation of allocator.
--
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: "P.J. Plauger" <pjp@plauger.com>
Date: 2000/06/16 Raw View
In article <394667C6.B032D83D@jps.net>,
Dennis Yelle <dennis51@jps.net> wrote:
> So, at least when using gcc, the STL works even
> better than I thought it did.
Probably because it doesn't fully conform, as I discussed in an
earlier posting to this thread.
--
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: "Jean-Daniel Nicolet" <jdn@llinkvest.ch>
Date: 2000/06/16 Raw View
P.J. Plauger wrote in message <8i98fh$pu5$1@nnrp1.deja.com>...
<SNIP>
>They happen to work in the current release because the VC++ compiler
>doesn't support a fully conforming implementation of allocator.
This must then be only half of the answer, because this does not explain why
it works with vectors and deque, but not with list, set and map.
Jean-Daniel Nicolet
Software Consultant
Geneva
Switzerland
---
[ 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: "Mike Carrato" <mike@carrato.com>
Date: 2000/06/13 Raw View
This is a multi-part message in MIME format.
------=_NextPart_000_0034_01BFD4AF.D23A61B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
(I tried posting this to the group, but it didn't seem to make it)
I apologize if this has been discussed before. I am not a regular reader =
of this
group.
Is the following code valid in standard C++? Theoretically, I would =
think
that recursion on a type using STL collections would be possible, since =
the
containers themselves have internal indirections.
I tried this code in MSVC 6.0 SP3, and found that recursion seems to =
work
for vector and deque, but not for list, set, or map.
Does Standard C++ have any guarantees about recursive constructs such as
these, either directly or indirectly. By indirectly, I mean, do the =
basic
requirements for standard containers guarantee recursion like this =
should
work?
Is this a bug in the implementation of MSVC's standard library, or do
vectors and deques just "happen to work"? I know I can use other means =
(i.e.
collections of pointers or smart pointers), but it would be much easier =
if
this worked directly...
Thanks,
Mike Carrato
/////
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
struct A
{
std::vector<A> aVector;
std::deque<A> aDeque;
std::list<A> aList; /* does not compile */
std::set<A> aSet; /* does not compile */
std::map<A,int> aMap; /* does not compile */
};
int main()
{
A a;
return 0;
}
///
------=_NextPart_000_0034_01BFD4AF.D23A61B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3017.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>(I tried posting this to the group, but =
it didn't=20
seem to make it)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I apologize if this has been discussed =
before. I am=20
not a regular reader of this<BR>group.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Is the following code valid in standard =
C++?=20
Theoretically, I would think<BR>that recursion on a type using STL =
collections=20
would be possible, since the<BR>containers themselves have internal=20
indirections.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I tried this code in MSVC 6.0 SP3, and =
found that=20
recursion seems to work<BR>for vector and deque, but not for list, set, =
or=20
map.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Does Standard C++ have any guarantees =
about=20
recursive constructs such as<BR>these, either directly or indirectly. By =
indirectly, I mean, do the basic<BR>requirements for standard containers =
guarantee recursion like this should<BR>work?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Is this a bug in the implementation of =
MSVC's=20
standard library, or do<BR>vectors and deques just "happen to work"? I =
know I=20
can use other means (i.e.<BR>collections of pointers or smart pointers), =
but it=20
would be much easier if<BR>this worked directly...</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Mike Carrato</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>/////<BR>#include =
<vector><BR>#include=20
<map><BR>#include <set><BR>#include <list><BR>#include =
<deque></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>struct =
A<BR>{<BR> std::vector<A>=20
aVector;<BR> std::deque<A> =
aDeque;<BR> std::list<A> aList;=20
/* does not compile */<BR> std::set<A> aSet; /* does not =
compile=20
*/<BR> std::map<A,int> aMap; /* does not compile=20
*/<BR>};</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>int main()<BR>{<BR> A =
a;<BR> return=20
0;<BR>}<BR>///</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2><BR></FONT> </DIV></BODY></HTML>
------=_NextPart_000_0034_01BFD4AF.D23A61B0--
======================================= MODERATOR'S COMMENT:
Please note that plain text is preferred on comp.std.c++.
---
[ 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: Dennis Yelle <dennis51@jps.net>
Date: 2000/06/14 Raw View
> Mike Carrato wrote:
[...]
> I tried this code in MSVC 6.0 SP3, and found that recursion seems to work
> for vector and deque, but not for list, set, or map.
[...]
> /////
> #include <vector>
> #include <map>
> #include <set>
> #include <list>
> #include <deque>
>
> struct A
> {
> std::vector<A> aVector;
> std::deque<A> aDeque;
> std::list<A> aList; /* does not compile */
> std::set<A> aSet; /* does not compile */
> std::map<A,int> aMap; /* does not compile */
> };
>
> int main()
> {
> A a;
> return 0;
> }
> ///
I tried the code above with
gcc version 2.95.2 19991024 (release)
and I was surprised to see that it compiled with
no errors and no warnings.
But it doesn't do anything, so I could not be sure
that it actually worked. So I tried this:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
struct A
{
int a;
std::vector<A> aVector;
std::deque<A> aDeque;
std::list<A> aList;
std::set<A> aSet;
std::map<A,int> aMap;
A( int a=0) : a(a) {}
};
void dump_list( const A& a)
{
cout << ' ' << a.a;
if ( ! a.aList.empty()) {
std::list<A>::const_iterator b=a.aList.begin(), e=a.aList.end();
cout << ' ' << '(';
for( ; b!=e; ++b) {
dump_list( *b);
}
cout << ' ' << ')';
}
}
int main()
{
A a = 1;
a.aList.push_back( A(2));
a.aList.push_back( A(3));
a.aList.back().aList.push_back( A(4));
dump_list( a);
cout << "\n" "Done.\n";
return 0;
}
That also worked properly, and produced this output:
1 ( 2 3 ( 4 ) )
Done.
So, at least when using gcc, the STL works even
better than I thought it did.
Dennis Yelle
--
I am a computer programmer and I am looking for a job.
There is a link to my resume here: http://table.jps.net/~vert
---
[ 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 ]