hallo.
This is my question:
let's assume a map like:
map< string, my_object > str_map;
map< string, my_object >::iterator iter = str_map.find("h allo");
map is an sorted container, so I think, question about index (ie. position
of objext in the map) of object 'iter' iterator points to, makes sense.
I was looking for a method to perform such operation but I didn't find any
:(((
Do You have any ideas ?
Thanks
Maciej 2 5500
"Maciej Kwapulinski" <pi****@wp.pl > wrote in message
news:be******** **@news2.ipartn ers.pl... hallo. This is my question: let's assume a map like:
map< string, my_object > str_map;
map< string, my_object >::iterator iter = str_map.find("h allo");
map is an sorted container, so I think, question about index (ie. position of objext in the map) of object 'iter' iterator points to, makes sense.
I was looking for a method to perform such operation but I didn't find any :(((
Do You have any ideas ?
Thanks Maciej
Use the distance function, which returns the distance from one iterator to
another (more or less).
map< string, my_object > str_map;
map< string, my_object >::iterator iter = str_map.find("h allo");
size_t index = std::distance(s tr_map.begin(), iter);
This isn't built into map because its not efficient. For a map iterator the
time taken to compute distance will be proportional to the value of the
index, i.e. it will take a lot longer to get your index for items near the
end of the map.
john
On Wed, 9 Jul 2003 18:34:51 +0200, "Maciej Kwapulinski" <pi****@wp.pl >
wrote: hallo. This is my question: let's assume a map like:
map< string, my_object > str_map;
map< string, my_object >::iterator iter = str_map.find("h allo");
map is an sorted container, so I think, question about index (ie. position of objext in the map) of object 'iter' iterator points to, makes sense.
I was looking for a method to perform such operation but I didn't find any :(((
Do You have any ideas ?
It isn't random access, so getting the "index" (position number) of an
element in a map is linear time, but here's the code (following on
from yours):
int index = std::distance(s tr_map.begin(), iter);
I can't think of any use for the index though. What are you trying to
do?
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Abhijit Ray |
last post by:
I am using hash_set which is available from gcc ( and which i presume
is not part of the C++ standard yet )
okay , In hash tables the key is used by a hash function to calculate
a index and the object is stored under that key.
I would like to have the index value. I want to iterate over all the
objects stored in the hash_set and get all the objects and their
index. )
The aim is to display the hash_set graphically, so that we can...
|
by: Thomas Casanova |
last post by:
Hi,
I am compiling a MSVC++ project on linux gcc 3.3.4.
gcc is whimsical about templates. It does understand the declaration
of the template type PointerList. It scream the error : 'PointerList'
is used as a type, but is not defined as a type. from this sources
code:
class TableFormat
|
by: gouqizi.lvcha |
last post by:
Hi, All:
I have an Linux object file, for example, foobar.o. Can I know which
version
of gcc build it?
Rick
|
by: Steve Crawford |
last post by:
How can I create an index on an array element? I seem to recall having
done this in the past but I don't recall how.
steve=# \d foo
Table "public.foo"
Column | Type | Modifiers
-----------+--------+-----------
textarray | text |
steve=# create index foodex on foo (textarray);
|
by: Dima Tkach |
last post by:
Hi, everybody!
I just ran into a weird problem on 7.3.4.
Here is a simple testcase:
rapidb=# create table nametab (name text);
CREATE TABLE
rapidb=# create index name_idx on nametab(name);
CREATE INDEX
rapidb=# set enable_seqscan=false;
| |
by: JS |
last post by:
I am a bit confused about the meaning of object files (.o).
I read this in a make file:
lotto: main.o init.o select.o sort.o display.o
gcc main.o init.o select.o sort.o display.o -o lotto
main.o: main.c lotto.h
gcc -c main.c
|
by: cranium.2003 |
last post by:
hi,
Here is my code
#include <iostream.h>
int main()
{
cout <<"HI";
return 0;
}
and using following command to compile a C++ program
g++ ex1.cpp -o ex1
|
by: flyingleon |
last post by:
I have today downloaded gcc-4.1.1 and tried to configure and build it.
I have successfully done this before with gcc-3.4.2. The gcc-4.1.1
includes gfortran which is a language that I need. The native build
platform is Linux AMD 64bit Opteron. I have previous built
libgmp.so.3.4.1 and libmpfr.so.1.0.0 and installed them in
/usr/local/lib which I understand are needed by gfortran.
My build directory on a local disk is:
...
|
by: TonyHa |
last post by:
Hello
I try to install boost_1_33_1 on RedHat Linux.
I have downloaded boost into /user/dtgtools/tmp and I try to install it
into
/user/dtgtools/packages/boost.
I use the following commands:
export PYTHON_ROOT="/user/dtgtools/packages/python/2.5"
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |