This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Boost's call_traits_test.cpp
- To: Doug Landauer <landauer at apple dot com>
- Subject: Re: Boost's call_traits_test.cpp
- From: Paolo Carlini <pcarlini at unitus dot it>
- Date: Wed, 25 Apr 2001 23:32:28 +0200
- CC: gcc at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Organization: Universita' della Tuscia
- References: <200104252105.OAA15233@scv3.apple.com>
- Reply-To: pcarlini at unitus dot it
Hi Doug,
> [snip]
>
> No, your typedef is not equivalent to the other call. It's easier
>
> to understand if you were using pointers instead of references:
>
> typedef int * pt;
>
> const pt v1;
>
> const int * v2;
>
> In the declaration of "v1", the "const" applies to the _pointer_.
>
> In the declaration of "v2", the "const" applies to the _int_.
>
> Similarly for references: your cr_type is exactly the same type
>
> as your r_type, because references themselves are always const.
>
> The "const int&" type is not the same type as "cr_type".
>
> Hope this helps,
>
> -- Doug
>
Sure it helps!
But now consider the following testcase, which I have jut posted to GNATS:
------------------
template <typename T>
struct call_traits
{
public:
typedef T type_less_spec;
};
template <typename T>
struct call_traits<T&>
{
typedef T type_more_spec;
};
int main()
{
int num;
// Two typedefs lead to the instant. of the less spec. ("wrong") template
typedef int& r_type;
typedef const r_type cr_type;
call_traits<cr_type>::type_less_spec var1 = num;
// ^^^^^^^^^^^^^^
// The explicit type leads to the instantiation of the "correct" one
call_traits<const int&>::type_more_spec var2 = num;
// ^^^^^^^^^^^^^^
// As happen with a single typedef!
typedef const int& std_cr_type;
call_traits<std_cr_type>::type_more_spec var3 = num;
// As happen, indeed, without the cv-qualifier
call_traits<r_type>::type_more_spec var4;
}
--------------------
What is going on???
It seems that Gcc does not agree with you, right? In particular it does process cr_type and r_type
as template parameters in *different* ways, instantiating different templates.
What do you think???
Thanks again for your feedback!
P.