Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-10-21 04:57:24


> >> // 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...
>
> 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.

Yes, it compiles, and instantiates Copy<int *, int *>. Template
parameter deduction strips top level cv-qualifiers. Consider what would
happen if Copy was defined as

template <typename InputIter, typename ForwardIter>
 inline ForwardIter Copy(InputIter first, InputIter last, ForwardIter
result)
{
    for(; first != last; ++first, ++result) *result = *first;
}

and InputIter was int * const. ++first wouldn't compile.

--
Peter Dimov
Multi Media Ltd.

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