template issue

Darko Miletic darko@uvcms.net
Tue Sep 14 16:30:00 GMT 2004


I was playing around with std::for_each and std::map  and came to an
interresting problem.

here is the sample code :
//main.cpp
#include <iostream>
#include <algorithm>
#include <string>

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

template <typename T, typename map_value_type >
void print_map(const T& map_) {
	std::for_each( map_.begin(),
                        map_.end(),
                        printMapValue<map_value_type>);
        std::cout << std::endl;
}

template <typename T >
void print_map_(const T& map_) {
   print_map<T, T::value_type>(map_);
}

int main(int argc, char* argv[])
{
   typedef std::map<int, std::string> mapType;
   mapType map_;
   map_[0] = "111";
   map_[1] = "222";
   map_[2] = "333";

  print_map<mapType,mapType::value_type>(map_); //<--- this works
  print_map_<mapType>(map_); //<--- this does not work on GCC , works on
BCB 5 and 6 and msvc 7.1

  return 0;
}

I get this error:
error: no matching function for call to `print_map(const
std::map<int, std::string, std::less<int>, std::allocator<std::pair<const
int, std::string> > >&)'

Any ideas?




More information about the Libstdc++ mailing list