|
Boost : |
From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2003-01-11 15:05:42
"Paul Mensonides" <pmenso57_at_[hidden]> writes:
| ----- Original Message -----
| From: "Gabriel Dos Reis" <gdr_at_[hidden]>
|
| > | However, this
| > | raises another interesting problem. Many enumerations used for this
| purpose
| > | are unnamed:
| > |
| > | template<class T> struct is_ptr {
| > | enum { value = false };
| > | };
| > |
| > | template<class T> struct is_ptr<T*> {
| > | enum { value = true };
| > | };
| > |
| > | This has its own problem in the same templated "pass by reference"
| > | situation. Namely, a template type argument cannot refer to an unnamed
| > | type:
| > |
| > | template<class T> T func(const T& ref) {
| > | return ref;
| > | }
| > |
| > | int main() {
| > | func( is_ptr<int*>::value );
| > | // error: argument deduction yields unnamed type
| >
| > Probably I'm being dense here, but please could you work out *why* you
| > think the above should fail?
|
| The type of "is_ptr<int*>::value" is "is_ptr<int*>::unnamed_type" _not_
| "int".
This, I agree with.
| Therefore template argument deduction should result in:
|
| is_ptr<int*>::unnamed_type func(const is_ptr<int*>::unnamed_type& ref);
agreed.
| ...which makes "T" equal to "is_ptr<int*>::unnamed_type" -- which is
| illegal.
This, I don't get. What I am missing?
| The problem is not binding the reference to const (as would be the problem
| with static const without a definition), but rather the template argument
| deduction attempting to bind an unnamed type to a template parameter.
Yes, but which text in the Standard forbids that?
Thanks,
-- Gaby
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk