473,320 Members | 2,004 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,320 software developers and data experts.

What is the point with std::set?

In std::set key_type = value_type. So if I want to find a value in a
std::set I do:

find(k)

where k is the value that I want to find...but I supply find with the
data I would like to find...makes no sense to me since I already have
the data, k, that I want to find.
Mar 12 '08 #1
6 4727
saneman wrote:
In std::set key_type = value_type. So if I want to find a value in a
std::set I do:

find(k)

where k is the value that I want to find...but I supply find with the
data I would like to find...makes no sense to me since I already have
the data, k, that I want to find.
find returns an iterator giving you the position of the item in the set.

--
Ian Collins.
Mar 12 '08 #2
saneman wrote:
In std::set key_type = value_type. So if I want to find a value in a
std::set I do:

find(k)

where k is the value that I want to find...but I supply find with the
data I would like to find...makes no sense to me since I already have
the data, k, that I want to find.
If find(k) returns end(), you find out that the set did not contain k.
Best

Kai-Uwe Bux
Mar 12 '08 #3
On 12 Mar., 22:39, saneman <asdf...@asd.comwrote:
In std::set key_type = value_type. So if I want to find a value in a
std::set I do:

find(k)

where k is the value that I want to find...but I supply find with the
data I would like to find...makes no sense to me since I already have
the data, k, that I want to find.
Adding to what others have told you, the set-element might also
contain data that is not part of the comparison. This data could be
useful!

/Peter
Mar 12 '08 #4
On Mar 12, 4:39 pm, saneman <asdf...@asd.comwrote:
In std::set key_type = value_type. So if I want to find a value in a
std::set I do:

find(k)

where k is the value that I want to find...but I supply find with the
data I would like to find...makes no sense to me since I already have
the data, k, that I want to find.
But it's useful if you want to determine if an object or value belongs
to a set of objects or values.
Mar 12 '08 #5
On 13 Mar, 12:26, Jeff Schwab <je**@schwabcenter.comwrote:
saneman wrote:
><paraphrase>What's the point of std::set?</paraphrase>

<begin quick example>

<snip>

<end quick example; begin unnecessarily elaborate example, offering no
new information>

<snip>

<end elaborate example>
Outstanding! If only my tutor had given such clear, concise, erudite,
and witty examples when I was at college, I think I'd probably have
graduated in half the time I did.

Nicely done, sir.
Mar 13 '08 #6
On 2008-03-12 18:44:38, Ian Collins wrote:
saneman wrote:
>In std::set key_type = value_type. So if I want to find a value in a
std::set I do:

find(k)

where k is the value that I want to find...but I supply find with the
data I would like to find...makes no sense to me since I already have
the data, k, that I want to find.

find returns an iterator giving you the position of the item in the set.
.... and that allows you, for example, to easily get the item that follows k
in the set.

Gerhard
Mar 13 '08 #7

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

Similar topics

11
by: snnn | last post by:
On the book <Generic Programming and the STL>( Matthew . H . Austern ),this function is defined as iterator set::begin() const. However, why should a const object returns a non-const iterator?...
5
by: Peter Jansson | last post by:
Hello, I have the following code: std::map<int,std::set<std::string> > k; k="1234567890"; k="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)...
10
by: danibe | last post by:
I never had any problems storing pointers in STL containers such std::vector and std::map. The benefit of storing pointers instead of the objects themselves is mainly saving memory resources and...
4
by: Gernot Frisch | last post by:
Hi, is the sorting order of std::set / std::map defined? i.e. is the *begin() of std::set<int> always smaller than *(--end()) ? -- -Gernot int main(int argc, char** argv) {printf...
16
by: Cory Nelson | last post by:
Does anyone know how std::set prevents duplicates using only std::less? I've tried looking through a couple of the STL implementations and their code is pretty unreadable (to allow for different...
2
by: shuisheng | last post by:
Dear All, std::set is sorted. So I am wondering is there any fast way to access (sucn as random access) to its elements just like std::vector. Assume I have a set std::set<inta; So I can...
7
by: desktop | last post by:
In the C++ standard page 472 it says that you can construct a std::set in linear time if the constructor gets a sorted sequence of elements. But how is this possible when insert takes logarithmic...
7
by: Renzr | last post by:
I have a problem about the std::set<>iterator. After finding a term in the std::set<>, i want to know the distance from the current term to the begin(). But i have got a error. Please offer me...
2
by: mathieu | last post by:
hi there, I would like to know if the following piece of code is garantee to work. I am afraid that the cstring address I am using in the std::map found from a request in std::set is not...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.