469,927 Members | 1,549 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Is this possible: map of references (map<string&, string&>)

Hello

Is it possible to use map<string&, string&>?

Why I need it. I have a large amount of data obtained from XML file.
I should do processing of this data.

The processing takes many stages, and could be done using std::map
templates. But new instance of std::map is required on each stage.

I would like to avoid additional memory allocation which is done in
map<string, stringcase.

I would like to use smth like map<string&, string&- in this case
there is no need to write additional binary operator
to be used as predicate for map (which would be required if I use
map<string*, string*>)

The questions are:
1. is it possible
2. are any underground problems if I use it

Would like to hear guru comments on it...

Tx,
Alexandru

May 11 '07 #1
3 2090
no, we cannot use map<string&, string&>.
use map<string*, string*instead.

<as*******@gmail.com>
??????:11**********************@y5g2000hsa.googleg roups.com...
Hello

Is it possible to use map<string&, string&>?

Why I need it. I have a large amount of data obtained from XML file.
I should do processing of this data.

The processing takes many stages, and could be done using std::map
templates. But new instance of std::map is required on each stage.

I would like to avoid additional memory allocation which is done in
map<string, stringcase.

I would like to use smth like map<string&, string&- in this case
there is no need to write additional binary operator
to be used as predicate for map (which would be required if I use
map<string*, string*>)

The questions are:
1. is it possible
2. are any underground problems if I use it

Would like to hear guru comments on it...

Tx,
Alexandru

May 11 '07 #2
as*******@gmail.com wrote:
Is it possible to use map<string&, string&>?
No. References are not objects. Consider pointers.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 11 '07 #3
as*******@gmail.com wrote:
>
Is it possible to use map<string&, string&>?
Not directly, but if you've got a library that supports TR1 (or boost,
in a different namespace) you can use
std::tr1::reference_wrapper<stringin both of those places.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
May 12 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Kaptain524 | last post: by
12 posts views Thread by Jeff Lanfield | last post: by
5 posts views Thread by Stephan Hoffmann | last post: by
9 posts views Thread by Robert Schneider | last post: by
10 posts views Thread by Steven Spits | last post: by
9 posts views Thread by Wayne Smith | last post: by
13 posts views Thread by ragged_hippy | last post: by
reply views Thread by subramanian100in | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.