Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2000-10-20 18:04:55


>From: "Jesse Jones" <jejones_at_[hidden]>
>
>[...]
>
>> Brave man. :-) Here's an example of using is_pointer without regard to
>> cv-qualifiers. A std::copy implementation written using
>meta-programming
>> idioms:
>>
>> #include <string>
>>
>> // is_pointer (const pointers are considered to be pointers)
>> template <typename T> struct is_pointer { static const bool value =
>false; };
>> template <typename T> struct is_pointer<T*> { static const bool value
>=
>> true; };
>> template <typename T> struct is_pointer<const T*> { static const bool
>value
>> = true; };
>
>This does not reflect what the comment says. is_pointer<T *
>const>::value is false...

Yup. It should read T* const.

>> // Copy
>> template <typename InputIter, typename ForwardIter>
>> inline ForwardIter Copy(InputIter first, InputIter last, ForwardIter
>result)
>
>... and in any event, your InputIter and ForwardIter types can't be
>cv-qualified anyway, unless you explicitly provide them...
>
>> int main()
>> {
>> int i[10];
>> int j[10];
>> Copy(i, i+10, j);
>
>... and you don't. :)

Sure they can. And the compiler agrees with me. This:

int main()
{
    int i[10];
    int j[10];
    
    int* const p = i;
    Copy(p, p+10, j);

    return 0;
}

compiles and generates the optimized assembly.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk