Re: std::string bad design????
Seungbeom Kim wrote:
Le Chaud Lapin wrote:
Yes. But the acquiring and releasing is not expensive at all. The
solution, which I want to emphasize for the others reading this post
(not you) should not be tried in plain C++, is to execute an atomic,
inexpensive attempt to grab the lock (atomic-test and set /
atomic-swap, etc.), and if that fails, fail-over to a full blown
kernel-mode mutex, which you would have had to do anyway. This is very
fast.
It seems like making things too complicated; I may not know what most
other people know, but I expect to have seen much more of such a
solution if it were that good. Instead, what I have heard enough was
that usage of mutexes should be kept to the minimum necessary.
It is pretty common technique. The writer of the library usually hides
whats going on in the .acquire() function.
typedef map<int, double> M;
for (M::const_iterator i = foo.begin(); i != foo.end(); ++i) {
for (M::const_iterator j = boost::next(i); j != foo.end(); ++j) {
if (i->second == j->second) {
std::cout << i->first << " and " << j->first;
std::cout << " both have the value " << i->second << '\n';
}
}
}
I don't understand; how would the iterator for the outer loop advance
when the shared iterator has swept from the beginning to the end in the
inner loop? Can you illustrate your point by some code?
int main ()
{
typedef Red_Black::Associative_Set<int, double> M;
M foo;
if (foo.seek_first())
{
do
{
const M::Node *i = &foo.node();
if (foo.seek_forward())
{
do
if (i->right == foo.RHE())
{
std::cout << i->left << " and " << foo.LHE();
std::cout << " both have the value " << i->right;
}
while (foo.seek_forward());
}
foo.locate(i->left);
}
while (foo.seek_forward());
}
return 0;
}
Anyhow, it still seems quite obvious to me that the separate iterator
model better suits such a situation where you need multiple iterators.
You right. My code is a lot less compact. I only prefer my model in
cases where there is one iterator.
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]