STL generated warnings

  • Thread starter Moah, full time turnip.
  • Start date
M

Moah, full time turnip.

Hi,

I'm currently using Borland C++ Builder on an application using the STL,
and it generates warnings I don't know how to handle:

"[C++ Warning] Unit1.cpp(585): W8091 Argument template, _InputIter sent
to 'for_each' is an output iterator: input iterator required
Complete Analyzer Context:
Unit1.cpp(574): analysis :, void TForm1::UpdateDBListBox()"

(rougly translated from the french).

Here's the code:

{
multiset<DBCard, CardCompare> List;
for_each(List.begin(), List.end(), AddItem);
}

(Actually everywhere I use a for_each on a multi set).
I've looked at the SGI doc on iterators, for_each and multiset but I
must admit I feel none the wiser.
What do I do wrong, and how do it write, please?

Thanks,
Moah, full time turnip.
 
M

Mike Wahler

Moah said:
Hi,

I'm currently using Borland C++ Builder on an application using the STL,
and it generates warnings I don't know how to handle:

"[C++ Warning] Unit1.cpp(585): W8091 Argument template, _InputIter sent
to 'for_each' is an output iterator:
Complete Analyzer Context:
Unit1.cpp(574): analysis :, void TForm1::UpdateDBListBox()"

(rougly translated from the french).

Here's the code:

{
multiset<DBCard, CardCompare> List;
for_each(List.begin(), List.end(), AddItem);
}

(Actually everywhere I use a for_each on a multi set).

Well, do you have the same problems those other places?
I've looked at the SGI doc on iterators, for_each and multiset but I
must admit I feel none the wiser.
What do I do wrong, and how do it write, please?

Hard to say with only that partial context. Here's
an example of 'for_each()' operating on a multiset
that compiles just fine and gives expected results:

#include <algorithm>
#include <iostream>
#include <set>

void f(int arg)
{
std::cout << arg << '\n';
}

int main()
{
std::multiset<int> ms;
ms.insert(0);
ms.insert(42);
ms.insert(3);
ms.insert(42);
ms.insert(99);
std::for_each(ms.begin(), ms.end(), f);
return 0;
}

Output:

0
3
42
42
99

HTH,
-Mike
 
B

Buster Copley

Moah said:
Hi,

I'm currently using Borland C++ Builder on an application using the STL,
and it generates warnings I don't know how to handle:

"[C++ Warning] Unit1.cpp(585): W8091 Argument template, _InputIter sent
to 'for_each' is an output iterator: input iterator required
Complete Analyzer Context:
Unit1.cpp(574): analysis :, void TForm1::UpdateDBListBox()"
(rougly translated from the french).

I think you've found a bug. According to SGI's documentation, multiset
models Associative Container, which refines Container, which refines
Forward Container, and the iterator type of a Forward Container is
required to be an input iterator. If the code works as you expect
(it may be difficult to determine whether or not this is the case)
then, in my opinion, you should feel free to ignore or disable the
warning.
Here's the code:

{
multiset<DBCard, CardCompare> List;
for_each(List.begin(), List.end(), AddItem);
}

(Actually everywhere I use a for_each on a multi set).
I've looked at the SGI doc on iterators, for_each and multiset but I
must admit I feel none the wiser.
What do I do wrong, and how do it write, please?

What version of Builder are you using?

Regards,
Buster.
 
J

Joerg Beyer

Moah said:
I'm currently using Borland C++ Builder on an application using the STL,
and it generates warnings I don't know how to handle:
"[C++ Warning] Unit1.cpp(585): W8091 Argument template, _InputIter sent
to 'for_each' is an output iterator: input iterator required
Complete Analyzer Context:
Unit1.cpp(574): analysis :, void TForm1::UpdateDBListBox()"
(rougly translated from the french).
Here's the code:
{
multiset<DBCard, CardCompare> List;

please dont call a multiset a "List", this is misleading :)

a std::multiset only takes 1 template parameter, since
sets only carry a set of elements. I dont know if you
(Actually everywhere I use a for_each on a multi set).
I've looked at the SGI doc on iterators, for_each and multiset but I

here is an example:
http://www.sgi.com/tech/stl/multiset.html

hope this helps
Joerg
 
M

Moah, full time turnip.

Buster said:
I think you've found a bug. According to SGI's documentation, multiset
models Associative Container, which refines Container, which refines
Forward Container, and the iterator type of a Forward Container is
required to be an input iterator. If the code works as you expect
(it may be difficult to determine whether or not this is the case)
then, in my opinion, you should feel free to ignore or disable the
warning.

Ok, I was wondering about that. Especially since the code works fine.
What version of Builder are you using?

Borland C++ Builder 6 Enterprise trial. Planning to buy the personal
edition when my trial expires...
Regards,
Buster.

Moah, full time turnip.
 
M

Moah, full time turnip.

Mike said:
Well, do you have the same problems those other places?

I get the exact same problem wherever I use for_each on my multiset,
but they are more or less the same thing as what I pasted.
Hard to say with only that partial context. Here's
an example of 'for_each()' operating on a multiset
that compiles just fine and gives expected results:

Thanks. Mine gives the warning, but as far as I've seen, there's
no mis-behaviour.

Moah, full time turnip.
 
M

Moah, full time turnip.

a std::multiset only takes 1 template parameter, since
sets only carry a set of elements. I dont know if you
want a multiset of std::pair<DBCard, CardCompare>,
or only of the DBCard _or_ CardCompare.

According to SGI, you can specify the comparison function to apply
for the sorting of the set/multi set. CardCompare is a functor that
compares DBCard based on external criterions:

multiset<Key, Compare, Alloc>

Key: The set's key type and value type. This is also defined as
multiset::key_type and multiset::value_type

Compare: The key comparison function, a Strict Weak Ordering whose
argument type is key_type; it returns true if its first argument is less
than its second argument, and false otherwise. This is also defined as
multiset::key_compare and multiset::value_compare.
Default: less<Key>

Alloc: The multiset's allocator, used for all internal memory mana-
gement.
Default: alloc
hope this helps
Joerg

Thanks,
Moah, full time turnip.
 
S

Shane Beasley

Moah said:
I'm currently using Borland C++ Builder on an application using the STL,
and it generates warnings I don't know how to handle:

"[C++ Warning] Unit1.cpp(585): W8091 Argument template, _InputIter sent
to 'for_each' is an output iterator: input iterator required
Complete Analyzer Context:
Unit1.cpp(574): analysis :, void TForm1::UpdateDBListBox()"

(rougly translated from the french).

Here's the code:

The code snippet you provided doesn't compile by itself, so I added
the following:

#include <algorithm>
#include <functional>
#include <set>

using std::multiset;
using std::for_each;

typedef int DBCard;
typedef std::less<DBCard> CardCompare;
void AddItem (DBCard) { }

int main ()
{
multiset<DBCard, CardCompare> List;
for_each(List.begin(), List.end(), AddItem);
}

With my changes, Comeau (www.comeaucomputing.com/tryitout) compiles
it. It could be something in the code you didn't show us, but I can't
imagine how that might happen. More likely, it's some sort of bug in
Borland's implementation. If this is the case, direct your news reader
to the forums.borland.com news server, or use its Web gateway at
<http://forums.borland.com/>.

- Shane
 
M

Moah, full time turnip.

Shane Beasley wrote:

The code snippet you provided doesn't compile by itself, so I added
the following:

.... snip the actual code ...
With my changes, Comeau (www.comeaucomputing.com/tryitout) compiles
it. It could be something in the code you didn't show us, but I can't
imagine how that might happen. More likely, it's some sort of bug in
Borland's implementation. If this is the case, direct your news reader
to the forums.borland.com news server, or use its Web gateway at
<http://forums.borland.com/>.

I copied / pasted your modified code into Borland C++ Builder, set the
warnings settings to "all" as in my normal project, and I got exactly
the same warnings. I have reported it in the Borland newsgroup, but I'll
check their web gateway jic my new server is out of date.

Thanks a lot,
Moah, full time turnip.
 

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top