T
Taras_96
Hi everyone,
In me trying to find strtoupper wasn't working with transform (which
I've fixed now), I came across the following message:
| ------------------- cut here ---------------------
|
| #include <string>
| #include <algorithm>
| #include <cctype>
| #include <iostream
|
| using namespace std;
|
| std::string& lower( std::string& p_str )
| {
| std::transform( p_str.begin(), p_str.end(), p_str.begin(),
tolower );
^^^^^^^
This ought to be a FAQ.
Three facts:
1) std::tolower (resp. std::toupper) is an overloaded function.
2) C++ has no type for the set of overloaded functions.
3) Template-argument deduction works by unifying the argument type
with
function parameter types.
by point 2), point 3) cannot succeed, hence the error.
-- Gaby
=================
I don't really understand what points 2 & 3 are saying. Is point 3
saying that if we have a templated function:
<template X>foo(X x)
Then when we write:
foo('a')
The compiler deduces that in this function call X refers to a char
type?
No idea what point #2 is saying
On a related note:
" transform(foo.begin(), foo.end(), foo.begin(), (int(*)
(int))std::tolower);
The cast causes, on the one hand, an explicit overload resolution
in favour of the function; it also allows the compiler to properly
deduce the third argument to transform."
What does he mean we talking about casting causing an explicit
overload resolution in favour of the function?
Cheers
Taras
In me trying to find strtoupper wasn't working with transform (which
I've fixed now), I came across the following message:
| ------------------- cut here ---------------------
|
| #include <string>
| #include <algorithm>
| #include <cctype>
| #include <iostream
|
| using namespace std;
|
| std::string& lower( std::string& p_str )
| {
| std::transform( p_str.begin(), p_str.end(), p_str.begin(),
tolower );
^^^^^^^
This ought to be a FAQ.
Three facts:
1) std::tolower (resp. std::toupper) is an overloaded function.
2) C++ has no type for the set of overloaded functions.
3) Template-argument deduction works by unifying the argument type
with
function parameter types.
by point 2), point 3) cannot succeed, hence the error.
-- Gaby
=================
I don't really understand what points 2 & 3 are saying. Is point 3
saying that if we have a templated function:
<template X>foo(X x)
Then when we write:
foo('a')
The compiler deduces that in this function call X refers to a char
type?
No idea what point #2 is saying
On a related note:
" transform(foo.begin(), foo.end(), foo.begin(), (int(*)
(int))std::tolower);
The cast causes, on the one hand, an explicit overload resolution
in favour of the function; it also allows the compiler to properly
deduce the third argument to transform."
What does he mean we talking about casting causing an explicit
overload resolution in favour of the function?
Cheers
Taras