Boost's call_traits_test.cpp

Paolo Carlini pcarlini@unitus.it
Wed Apr 25 14:33:00 GMT 2001


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.



More information about the Libstdc++ mailing list