public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15469] New: Unable to compile valid code including transform() algorithm
@ 2004-05-16 22:07 relf at os2 dot ru
  2004-05-16 22:11 ` [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter relf at os2 dot ru
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: relf at os2 dot ru @ 2004-05-16 22:07 UTC (permalink / raw)
  To: gcc-bugs

While compiling the code below, gcc 3.3.3 reports the error:

bug2.cpp:21: error: no matching function for call to `transform(
   std::_Rb_tree_iterator<std::pair<const int, int>, std::pair<const int,
   int>&, std::pair<const int, int>*>, std::_Rb_tree_iterator<std::pair<const
   int, int>, std::pair<const int, int>&, std::pair<const int, int>*>,
   __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >,
   <unknown type>)'

The code looks correct, not much different from the C++ Standard section 18.6.2
examples.
secondof() function by itself works fine - i've included a line into the code to
demonstrate that.

==============================

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

template <class cl1, class cl2>
const cl2& secondof(const pair<cl1,cl2>& p) {
    return p.second;
}

int main() {
    map<int,int> M;
    M[1] = 10;
    M[4] = 50;

    cout << "secondof() works as expected: " << secondof(*M.begin()) << endl;

    vector<int> V(M.size());

    transform(M.begin(),M.end(),V.begin(),secondof);
}

-- 
           Summary: Unable to compile valid code including transform()
                    algorithm
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: relf at os2 dot ru
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15469


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter
  2004-05-16 22:07 [Bug c++/15469] New: Unable to compile valid code including transform() algorithm relf at os2 dot ru
@ 2004-05-16 22:11 ` relf at os2 dot ru
  2004-05-16 22:24 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: relf at os2 dot ru @ 2004-05-16 22:11 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Unable to compile valid code|Unable to compile valid code
                   |including transform()       |including transform()
                   |algorithm                   |algorithm: <unknown type> is
                   |                            |reported for the forth
                   |                            |parameter


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15469


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter
  2004-05-16 22:07 [Bug c++/15469] New: Unable to compile valid code including transform() algorithm relf at os2 dot ru
  2004-05-16 22:11 ` [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter relf at os2 dot ru
@ 2004-05-16 22:24 ` pinskia at gcc dot gnu dot org
  2004-05-17 19:13 ` bangerth at dealii dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-16 22:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-15 21:27 -------
This is a dup of bug 5458.

*** This bug has been marked as a duplicate of 5458 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15469


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter
  2004-05-16 22:07 [Bug c++/15469] New: Unable to compile valid code including transform() algorithm relf at os2 dot ru
  2004-05-16 22:11 ` [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter relf at os2 dot ru
  2004-05-16 22:24 ` pinskia at gcc dot gnu dot org
@ 2004-05-17 19:13 ` bangerth at dealii dot org
  2004-05-17 19:13 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2004-05-17 19:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-05-17 02:40 -------
As mentioned, this is invalid. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15469


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter
  2004-05-16 22:07 [Bug c++/15469] New: Unable to compile valid code including transform() algorithm relf at os2 dot ru
                   ` (2 preceding siblings ...)
  2004-05-17 19:13 ` bangerth at dealii dot org
@ 2004-05-17 19:13 ` bangerth at dealii dot org
  2004-05-17 19:18 ` relf at os2 dot ru
  2004-05-17 19:41 ` gdr at integrable-solutions dot net
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2004-05-17 19:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-05-17 02:39 -------
No, the bug is actually something completely different. When you 
refer to 'secondof' in the call to transform, you reference a 
template without giving the compiler the chance to actually 
deduce the template arguments. You need to write this as 
follows: 
    transform(M.begin(),M.end(),V.begin(),secondof<int,int>); 
 
Wolfgang 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15469


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter
  2004-05-16 22:07 [Bug c++/15469] New: Unable to compile valid code including transform() algorithm relf at os2 dot ru
                   ` (3 preceding siblings ...)
  2004-05-17 19:13 ` bangerth at dealii dot org
@ 2004-05-17 19:18 ` relf at os2 dot ru
  2004-05-17 19:41 ` gdr at integrable-solutions dot net
  5 siblings, 0 replies; 7+ messages in thread
From: relf at os2 dot ru @ 2004-05-17 19:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From relf at os2 dot ru  2004-05-17 04:26 -------
Wolfgang, could you please explain the difference with the following example
from B.Stroustrup "The C++ Programming Language" 3rd edition, section 18.6.2:

template<class T> T* delete_ptr(T* p) { delete p; return 0; }
void purge(deque<Shape*>& s)
{
    transform(s.begin(),s.end(),s.begin(),delete_ptr);
    // ...
}

Note that here we pass just `delete_ptr' but not `delete_ptr<Shape>' as the
forth parameter. Why this code does not reqire explicit template class
specification while my code (that is not much different, in fact) does?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15469


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter
  2004-05-16 22:07 [Bug c++/15469] New: Unable to compile valid code including transform() algorithm relf at os2 dot ru
                   ` (4 preceding siblings ...)
  2004-05-17 19:18 ` relf at os2 dot ru
@ 2004-05-17 19:41 ` gdr at integrable-solutions dot net
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at integrable-solutions dot net @ 2004-05-17 19:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at integrable-solutions dot net  2004-05-17 07:27 -------
Subject: Re:  Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter

"relf at os2 dot ru" <gcc-bugzilla@gcc.gnu.org> writes:

| Wolfgang, could you please explain the difference with the following example
| from B.Stroustrup "The C++ Programming Language" 3rd edition, section 18.6.2:
| 
| template<class T> T* delete_ptr(T* p) { delete p; return 0; }
| void purge(deque<Shape*>& s)
| {
|     transform(s.begin(),s.end(),s.begin(),delete_ptr);
|     // ...
| }

Wolfgang is right.  We don't have types for address of function
templates or overload functions (not that a function template is
treated ini many cases as an infinite overload set).

| Note that here we pass just `delete_ptr' but not `delete_ptr<Shape>' as the
| forth parameter. Why this code does not reqire explicit template class
| specification while my code (that is not much different, in fact) does?

In my copy of TC++PL3, special edition, the code reads:

   struct Delete_ptr { // use function object to get inlining
        template<class T> T* operator()(T* p) { delete p; return 0; }
   };

   void purge(deque<Shape*>& s)
   {
        transform(s.begin(), s.end(), s.begin(), Delete_ptr());
   }

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15469


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-05-17  7:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-16 22:07 [Bug c++/15469] New: Unable to compile valid code including transform() algorithm relf at os2 dot ru
2004-05-16 22:11 ` [Bug c++/15469] Unable to compile valid code including transform() algorithm: <unknown type> is reported for the forth parameter relf at os2 dot ru
2004-05-16 22:24 ` pinskia at gcc dot gnu dot org
2004-05-17 19:13 ` bangerth at dealii dot org
2004-05-17 19:13 ` bangerth at dealii dot org
2004-05-17 19:18 ` relf at os2 dot ru
2004-05-17 19:41 ` gdr at integrable-solutions dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).