S
subramanian100in
I am copying the following lines as it is, from Stanley Lippman's C++
Primer 4th edition, page 418(First paragraph).
It says:
"Although the map and set types provide bidirectional iterators, we
can use only a subset of the algorithms on associative containers. The
problem is that key in an associative container is const. Hence, any
algorithm that writes to elements in the sequence cannot be used on an
associative container. We may use iterators bound to associative
containers only to supply arguments that will be read."
Here, consider the line "any algorithm that writes to elements in the
sequence cannot be used on an associative container".
Consider the code fragment:
typedef set<int> s_type;
s_type s1;
s_type s2;
// store some values into s1 and s2.
s_type dest;
merge(s1.begin(), s1.end(), s2.begin(), s2.end(),
inserter(dest, dest.end()));
s_type temp;
copy(s1.begin(), s1.end(), inserter(temp, temp.end()));
Here I am able to write merged elements into dest and copy elements
into temp. Can these operations be considered as "writing elements
into associative container" ? Or, if the above stated line from the
book refers to some other algorithms ? If so, please give me one or
two such algorithm names, for my understanding purpose.
My question is: I am to write elements from the input sequence into
insert_iterator< set<int> >
Kindly clarify.
Thanks
V.Subramanian
Primer 4th edition, page 418(First paragraph).
It says:
"Although the map and set types provide bidirectional iterators, we
can use only a subset of the algorithms on associative containers. The
problem is that key in an associative container is const. Hence, any
algorithm that writes to elements in the sequence cannot be used on an
associative container. We may use iterators bound to associative
containers only to supply arguments that will be read."
Here, consider the line "any algorithm that writes to elements in the
sequence cannot be used on an associative container".
Consider the code fragment:
typedef set<int> s_type;
s_type s1;
s_type s2;
// store some values into s1 and s2.
s_type dest;
merge(s1.begin(), s1.end(), s2.begin(), s2.end(),
inserter(dest, dest.end()));
s_type temp;
copy(s1.begin(), s1.end(), inserter(temp, temp.end()));
Here I am able to write merged elements into dest and copy elements
into temp. Can these operations be considered as "writing elements
into associative container" ? Or, if the above stated line from the
book refers to some other algorithms ? If so, please give me one or
two such algorithm names, for my understanding purpose.
My question is: I am to write elements from the input sequence into
insert_iterator< set<int> >
Kindly clarify.
Thanks
V.Subramanian