Dietmar Kuehl said:
I disagree, especially when it comes to generic code: the non-member
functions are the way to go. The library should generally provide
specialized version of the general algorithms wehre feasible - although,
admittedly, most don't. The problem with member function is that they
tend to more restrictive than the non-member algorithms and are thus
unsuitable for generic code. For example, to use 'back_inserter()' with
some object, it merely needs a 'push_back()' operation.
Really, is it better to use "copy(....,back_inserter(a))" rather than
"a.insert( a.end(), ... )" just because copy is a non-member function ?
The portability argument doesn't really favor the use of push_back,
since all sequence containers are required to provide an insert(p,i,j)
member function, while push_back() is an optional feature (§23.1.1).
And as far as I know, few library implementations (do you know
an example?) actually specialize algorithms on back_inserter...
This may be a
suitable way to fill data into a custom container. Actually, I'd even
prefer if 'push_back()' were a non-member which would forward be
specialized to forward to suitable member functions.
Philosophically, I totally agree with this. I would prefer a standard
library with more non-member functions...
But I prefer to explicitly perform an insertion, than to distort the use
of 'copy' -- which to me suggests that items are being overwritten.
Among two non-member functions, I would still choose 'insert'
( unless of course an "append" algorithm was available
)
Kind regards,
Ivan