473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

c++ equivalent of java collections

hi-

where would someone find things like lists, sets, map classes like a
hash map or tree map. not specifically those but in general is there
a book section that deals with it? in java you can use the interface
to these without having to know all of the implementation details.
is there an interface to a library with these kind of methods in c++?

i knew a little c++ from 2 really basic introductory courses.
however, each time we wanted this functionality we had to program
it. an example where this would be cool is if i wanted a data structure
that TCL didn't have. i could extend TCL with C++.

thanks for letting me know what people use.
jim
Jun 19 '07 #1
16 5041

i just found a listing point to the STL.
thanks,
later
Jun 19 '07 #2
3rdshiftcoder wrote:
hi-

where would someone find things like lists, sets, map classes like a
hash map or tree map. not specifically those but in general is there
a book section that deals with it?
This is referred to as the "standard template library" (STL) and is a
normative part of the C++ standard. Not only does the STL encompass
containers like you have mentioned but also algorithms like sort or find.

There are many books that discuss these.

The "reference" I used often but it is a little dated is the SGI web
site on the STL (I have not looked at them for a while myself - maybe it
is updated).
http://www.sgi.com/tech/stl/

SGI has implemented some containers that are not part of the standard so
you need to be a little careful.

The ones you will use almost all the time in modern c++ code are:

basic_string
vector
list
map
sort
The ones I know are not part of the current standard are:

hash_map
rope

.... probably others.

The SGI examples are missing a few namespace specifiers. Usually a
using namespace std; somewhere in the example fixes those probs.
Jun 19 '07 #3
Hi Gianni -

that is a very cool link :-)
i think this is worth checking out !
the first 2 semesters of coding at school were very basic.
this is definitely some of the stuff that is missing.

thanks very much,
jim


"Gianni Mariani" <gi*******@mariani.wswrote in message
news:46***********************@per-qv1-newsreader-01.iinet.net.au...
3rdshiftcoder wrote:
>hi-

where would someone find things like lists, sets, map classes like a
hash map or tree map. not specifically those but in general is there
a book section that deals with it?

This is referred to as the "standard template library" (STL) and is a
normative part of the C++ standard. Not only does the STL encompass
containers like you have mentioned but also algorithms like sort or find.

There are many books that discuss these.

The "reference" I used often but it is a little dated is the SGI web site
on the STL (I have not looked at them for a while myself - maybe it is
updated).
http://www.sgi.com/tech/stl/

SGI has implemented some containers that are not part of the standard so
you need to be a little careful.

The ones you will use almost all the time in modern c++ code are:

basic_string
vector
list
map
sort
The ones I know are not part of the current standard are:

hash_map
rope

... probably others.

The SGI examples are missing a few namespace specifiers. Usually a using
namespace std; somewhere in the example fixes those probs.

Jun 19 '07 #4
On Tue, 19 Jun 2007 00:36:32 -0400, "3rdshiftcoder" wrote:
>where would someone find things like lists, sets, map classes like a
hash map or tree map. not specifically those but in general is there
a book section that deals with it? in java you can use the interface
to these without having to know all of the implementation details.
is there an interface to a library with these kind of methods in c++?
Actually, there is no equivalent for Java collections in Standard C++.
Java collections work only with objects but not with values, Standard
C++ collections (a.k.a. STL) work only with values but not with
objects.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 19 '07 #5
On 2007-06-19 07:27, 3rdshiftcoder wrote:
"Gianni Mariani" <gi*******@mariani.wswrote in message
news:46***********************@per-qv1-newsreader-01.iinet.net.au...
>3rdshiftcoder wrote:
>>hi-

where would someone find things like lists, sets, map classes like a
hash map or tree map. not specifically those but in general is there
a book section that deals with it?

This is referred to as the "standard template library" (STL) and is a
normative part of the C++ standard. Not only does the STL encompass
containers like you have mentioned but also algorithms like sort or find.

There are many books that discuss these.

The "reference" I used often but it is a little dated is the SGI web site
on the STL (I have not looked at them for a while myself - maybe it is
updated).
http://www.sgi.com/tech/stl/

SGI has implemented some containers that are not part of the standard so
you need to be a little careful.

The ones you will use almost all the time in modern c++ code are:

basic_string
vector
list
map
sort
The ones I know are not part of the current standard are:

hash_map
rope

... probably others.

The SGI examples are missing a few namespace specifiers. Usually a using
namespace std; somewhere in the example fixes those probs.

Hi Gianni -

that is a very cool link :-)
i think this is worth checking out !
the first 2 semesters of coding at school were very basic.
this is definitely some of the stuff that is missing.
Please, try not to top-post (fixed here), it makes it much harder to
read your posts and there are people who will not reply to people who
top-post which means you might miss out on some valuable information.

Another link to check out would be the following: www.cppreference.com,
which I believe is fully standards compliant and quite easy to navigate.

--
Erik Wikström
Jun 19 '07 #6
On Jun 19, 1:37 am, rpbg...@yahoo.com (Roland Pibinger) wrote:
On Tue, 19 Jun 2007 00:36:32 -0400, "3rdshiftcoder" wrote:
where would someone find things like lists, sets, map classes like a
hash map or tree map. not specifically those but in general is there
a book section that deals with it? in java you can use the interface
to these without having to know all of the implementation details.
is there an interface to a library with these kind of methods in c++?

Actually, there is no equivalent for Java collections in Standard C++.
Java collections work only with objects but not with values, Standard
C++ collections (a.k.a. STL) work only with values but not with
objects.

Having worked with both, I can kind of see what you mean. However, I
fundamentally disagree
with what you imply. It is true that c++ standard containers are by
value but there is no
restriction whatsoever regarding the type of that value. The value
can be a class in which
case, the objects themselves will be copied, potentially many times.
You can specify that
the containers carry pointers to objects. Finally, you can specify
that the containers can
carry shared pointers to objects which provide the same basic
advantages as Java's school marm
garbage collection.

regards,

Jon Trauntvein

Jun 19 '07 #7
On Jun 19, 3:37 am, rpbg...@yahoo.com (Roland Pibinger) wrote:
Actually, there is no equivalent for Java collections in Standard C++.
Java collections work only with objects but not with values, Standard
C++ collections (a.k.a. STL) work only with values but not with
objects.
In a frameowrk like COM, where everything already inherits from
IUnknown, tt is easy to use a shared pointer, and have something that
can store references to any object.
Even with such a framework, I agree that it is fairly difficult to
emulate Java Collections using C++. However, I have found the model
useful in some cases, when I want to model a sequence or collection in
an abstract interface.
In other words you have something like:
tempalte <class Tstruct Collection{
Iterator<Tbegin()=0;
Iterator<Tend()=0;
ConstIterator<Tbegin()const=0;
ConstIterator<Tend()const=0;
bool empty()const=0;
std::size_t size()const=0;

//plus all the requred typedefs
};
I have actually gotten this to work for read-only containers that
return const InputIterators. But going further (e.g. Forward
iterators, modifyable containers) was a lot of work for little
payoff.
Jun 19 '07 #8
On Jun 19, 9:37 am, rpbg...@yahoo.com (Roland Pibinger) wrote:
On Tue, 19 Jun 2007 00:36:32 -0400, "3rdshiftcoder" wrote:
where would someone find things like lists, sets, map classes like a
hash map or tree map. not specifically those but in general is there
a book section that deals with it? in java you can use the interface
to these without having to know all of the implementation details.
is there an interface to a library with these kind of methods in c++?
Actually, there is no equivalent for Java collections in Standard C++.
Java collections work only with objects but not with values, Standard
C++ collections (a.k.a. STL) work only with values but not with
objects.
That's to be expected, since C++ as a language works only with
values, where as Java works mainly with pointers. In this
respect, each of the libraries "fits in" with the language; a
C++ library which worked with pointers would be
counter-intuitive.

On the the other hand, the interfaces of the collections are
significantly different---the C++ two iterator idiom makes most
things significantly more verbose, is much more awkward to work
with, and much less flexible. (Of course, the Java iterator
combines access and increment, which has a few drawbacks as
well.)

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 19 '07 #9
On Tue, 19 Jun 2007 11:16:27 -0000, JH Trauntvein wrote:
>Having worked with both, I can kind of see what you mean. However, I
fundamentally disagree
with what you imply. It is true that c++ standard containers are by
value but there is no
restriction whatsoever regarding the type of that value. The value
can be a class in which
case, the objects themselves will be copied, potentially many times.
You can specify that
the containers carry pointers to objects.
You are right that the container value type can be a value or a
pointer to an object. But nevertheless STL is designed with 'value
semantics' in mind, e.g.

std::vector<T*v;
std::sort (v.begin(), v.end());

compiles but gives false results.
>Finally, you can specify that the containers can
carry shared pointers to objects
pointers in C/C++ are shared by default ;-)
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 19 '07 #10
On Tue, 19 Jun 2007 04:28:52 -0700, Lance Diduck wrote:
>I agree that it is fairly difficult to
emulate Java Collections using C++. However, I have found the model
useful in some cases, when I want to model a sequence or collection in
an abstract interface.
In other words you have something like:
tempalte <class Tstruct Collection{
Iterator<Tbegin()=0;
Iterator<Tend()=0;
ConstIterator<Tbegin()const=0;
ConstIterator<Tend()const=0;
bool empty()const=0;
std::size_t size()const=0;

//plus all the requred typedefs
};
I have actually gotten this to work for read-only containers that
return const InputIterators. But going further (e.g. Forward
iterators, modifyable containers) was a lot of work for little
payoff.
One should distinguish between containers for polymorphic objects and
polymorphic containers (your example). STL has neither.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 19 '07 #11
On Tue, 19 Jun 2007 11:36:32 -0000, James Kanze wrote:
>That's to be expected, since C++ as a language works only with
values, where as Java works mainly with pointers.
That C++ works only with values is, at least, misleading.
>In this
respect, each of the libraries "fits in" with the language; a
C++ library which worked with pointers would be
counter-intuitive.
RogueWave, Microsoft, Qt, ... successfully produced such
'counter-intuitive' libraries. OTOH, looking at STL-related postings
in newsgroups STL's 'value semantics' isn't intuitive at all for many.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 19 '07 #12
Gil
Roland Pibinger escribió:
On Tue, 19 Jun 2007 11:36:32 -0000, James Kanze wrote:
>That's to be expected, since C++ as a language works only with
values, where as Java works mainly with pointers.

That C++ works only with values is, at least, misleading.
>In this
respect, each of the libraries "fits in" with the language; a
C++ library which worked with pointers would be
counter-intuitive.

RogueWave, Microsoft, Qt, ... successfully produced such
'counter-intuitive' libraries. OTOH, looking at STL-related postings
in newsgroups STL's 'value semantics' isn't intuitive at all for many.

Anybody knows something like java's Files.list() in C++

Thanks
Jun 19 '07 #13
On 2007-06-19 20:49, Gil wrote:
Roland Pibinger escribió:
>On Tue, 19 Jun 2007 11:36:32 -0000, James Kanze wrote:
>>That's to be expected, since C++ as a language works only with
values, where as Java works mainly with pointers.

That C++ works only with values is, at least, misleading.
>>In this
respect, each of the libraries "fits in" with the language; a
C++ library which worked with pointers would be
counter-intuitive.

RogueWave, Microsoft, Qt, ... successfully produced such
'counter-intuitive' libraries. OTOH, looking at STL-related postings
in newsgroups STL's 'value semantics' isn't intuitive at all for many.

Anybody knows something like java's Files.list() in C++
There are no classes for accessing files and directories in standard
C++, but there are lots of third party libraries and any of the more
complete ones should have something similar.

--
Erik Wikström
Jun 19 '07 #14
On Jun 19, 1:49 pm, Gil <gilberto...@gmail.comwrote:
Roland Pibinger escribió:
Anybody knows something like java's Files.list() in C++
Method of accessing files varies with operating system. On Linux you
do it one way, on Windows you do it another way. Either way, you need
to either find a library that supports unified file access, or you
need to learn the specific method for the operating system you are
trying to support (Hint: In Windows lookup FindFirstFile /
FindNextFile, in Unix lookup opendir / readdir. This is highly
offtopic though, so please continue any further discussion about this
in the appropriate newsgroup.)

Jun 19 '07 #15
On Jun 19, 8:49 pm, Gil <gilberto...@gmail.comwrote:
Anybody knows something like java's Files.list() in C++
I've got one myself, but it's not standard. As of today,
there's no such thing in standard C++. But I believe that
there is something being proposed for the next version of the
standard.

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 20 '07 #16
On 19 Jun, 19:49, Gil <gilberto...@gmail.comwrote:
Anybody knows something like java's Files.list() in C++
Boost has a Filesystem library.

http://www.boost.org/libs/filesystem/doc/index.htm

Gavin Deane

Jun 20 '07 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mark | last post by:
I've been getting odd compile errors when trying to sort while using generics. I have the following code: static final List<Class> levelList; static { Vector<Class> v = new Vector<Class>();...
5
by: Egghead | last post by:
Hi, Does anyone know if there is any C#'s class equivalent to java.utl.Vector? I think the System.Collections.ArrayList is not the same: In java: for(int i = 0; i<myVector.length;i++) {...
2
by: comp.lang.php | last post by:
I looked up System.getProperties, but to be honest, I have no clue how to use it in light of what I can do in PHP, which is this: <?php echo $_SERVER . ' ' . $_SERVER; ?> it would be very...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
16
by: coosa | last post by:
Dear all, I'm familiar with the Set Class in C++ and Java; however, i have been searching in C# for a similar container as in c++ or collection as in java, but couldn't find one. Could some one...
1
by: Maury | last post by:
Do someone knows if exists a .Net equivalent of ConcurrentLinkedQueue<Tfound in Java? this class in java provides a queue which is threadsafe... thanks
9
by: Ian | last post by:
I would like to port my class library written in standard C++ with STL to C++/CLI. Several of my classes inherit from std::vector or std::deque. From what I can see, dot.net does not offer...
1
by: raagadeepthi | last post by:
Getting below error when iam trying to sort the values: Oct 29 04:33:52 WARN cb.DefaultController - Cannot forward after response has been committed java.lang.IllegalStateException: Cannot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.