public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Darko Miletic <darko@uvcms.net>
To: gcc help <gcc-help@gcc.gnu.org>
Subject: template issue
Date: Tue, 14 Sep 2004 18:20:00 -0000	[thread overview]
Message-ID: <41473666.3050308@uvcms.net> (raw)

I have been playing with std::for_each and std::map  and came with 
interresting issue:

//main.cpp
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

typedef std::map<int, std::string> mapType;

template <typename M>
inline void printMapValue(const M& value) {
   std::cout << value.first  << " - "
			<< value.second << "\n";
}

template <typename T >
void print_map(const T& map_) {
     std::for_each( map_.begin(),
                    map_.end(),
                    printMapValue<typename T::value_type>); // if 
typename is removed here GCC reports error???
        std::cout << std::endl;
}

int main(int argc, char* argv[])
{
   mapType map_;
   map_[0] = "111";
   map_[1] = "222";
   map_[2] = "333";

  print_map<mapType>(map_);

  return 0;
}

If I remove keyword typename from print_map function GCC reports this:
error: no matching function for call to `for_each(
std::_Rb_tree_iterator<std::pair<const int, std::string>, const
std::pair<const int, std::string>&, const std::pair<const int,
std::string>*>, std::_Rb_tree_iterator<std::pair<const int, std::string>,
const std::pair<const int, std::string>&, const std::pair<const int,
std::string>*>, <unknown type>)'

Why is typename needed here? Other compilers like BCB 5&6 and MSVC 7.1 
compile this fine without typename keyword.

Darko


             reply	other threads:[~2004-09-14 18:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-14 18:20 Darko Miletic [this message]
2004-09-14 18:38 ` Eljay Love-Jensen
2004-09-14 18:37 lrtaylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41473666.3050308@uvcms.net \
    --to=darko@uvcms.net \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).