R
Ricky65
Reading N3291 I noticed that algorithm copy_n is defined as:
"template<class InputIterator, class Size, class OutputIterator>
OutputIterator copy_n(InputIterator first, Size n, OutputIterator
result);"
copy_n should return a pair - an OutputIterator in the destination
range and also an InputIterator to the last element copied in the
input range. In "Elements Of Programming" by Alexander Stepanov and
Paul McJones copy_n is in this form.
By just returning an OutputIterator copy_n violates the idiom - "an
algorithm should return all the information it computed". To quote
Alexander Stepanov, "Throwing away useful information (or returning
redundant information) usually indicates a poorly designed interface."
Far more useful copy_n which returns a
std:air<InputIterator,OutputIterator>:
"template<class InputIterator, class Size, class OutputIterator>
std:air<InputIterator, OutputIterator> copy_n(InputIterator first,
Size n, OutputIterator result);"
Kind regards
Riccardo Marcangelo
"template<class InputIterator, class Size, class OutputIterator>
OutputIterator copy_n(InputIterator first, Size n, OutputIterator
result);"
copy_n should return a pair - an OutputIterator in the destination
range and also an InputIterator to the last element copied in the
input range. In "Elements Of Programming" by Alexander Stepanov and
Paul McJones copy_n is in this form.
By just returning an OutputIterator copy_n violates the idiom - "an
algorithm should return all the information it computed". To quote
Alexander Stepanov, "Throwing away useful information (or returning
redundant information) usually indicates a poorly designed interface."
Far more useful copy_n which returns a
std:air<InputIterator,OutputIterator>:
"template<class InputIterator, class Size, class OutputIterator>
std:air<InputIterator, OutputIterator> copy_n(InputIterator first,
Size n, OutputIterator result);"
Kind regards
Riccardo Marcangelo