N.B. This mail is not appropriate on this mailing list, which is for
discussion of development of GCC. For help with GCC use the gcc-help
list or to report bugs use bugzilla, thanks.
On 19 January 2013 18:58, Jason A. Donenfeld wrote:
> /*
> *
> * The output of this with gcc 4.7.2 is:
> *
> * 1
> * 2
> * this generic-int function should not be called
> * 0
This is the correct behaviour, the old behaviour was a bug.
> struct Type { int dummy; };
>
> template <typename T, typename M>
> inline T extractTag(const M &map, const char *key)
> {
> if (!strcmp(key, "blah-bool"))
> std::cout << "this generic-int function should not be called"
> << std::endl;
> T ret = 0;
> std::istringstream stream(extractTag<std::string>(map, key));
> stream >> ret;
> return ret;
> }
> template <typename M>
> inline bool extractTag(const M &map, const char *key)
> {
> if (!strcmp(key, "blah-bool"))
> std::cout << "this generic-bool function should not be
> called" << std::endl;
> std::string str(extractTag<std::string>(map, key));
> std::transform(str.begin(), str.end(), str.begin(), ::tolower);
> return (str == "1" || str == "true");
> }
This is not a partial specialization (you cannot have partial
specializations of function templates only class templates)so this is
a new overload of extractTag with a single template parameter.
> template <>
> inline bool extractTag(const Type&, const char *key)
> {
> if (!strcmp(key, "blah-bool"))
> std::cout << "this type-bool function SHOULD BE called" <<
> std::endl;
> return true;
> }
This is a specialization of extractTag<M> not extractTag<T,M>, so
cannot be called by extractTag<bool>(t, "blah-bool") because argument
deduction fails.