--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
Are any thoughts about adding the method append to sequantial containers?
No, I do not think so.
It is common interface of all sequential containers including and together with std::basic_string.
--
--
I do not see any great sense in this function. In fact you need to write its realization for each container. So it looks like the realization of function std:;swap in containers. Moreover std::basic_string has already method append. So that to make the call of the function interchangeable with other containers it is better to make it a class member.
In this case you can not substituted a call of the method for std::basic_string with a call for a vector. So the interface will not be consistent.
Apart from this the callstd::cout << v.append( { 1, 2, 3, 4, 5 } );looks semantically more clear than
std::cout << append( v, { 1, 2, 3, 4, 5 } );From the second call it is not clear what is outputed whether it is a new vector or it is the original vector.
As I said I do not see a great sense to make the method as a non-member function. In my opinion it is a wrong approach because if to do so the question arises what to do with arrays.
They have no method insert. Also what to do with other containers that also have no method insert as for example std::forward_list?
--
--- You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
I don't see whyappend( v, { 1, 2, 3, 4 } )raises any more question about what is actually returned when compared withv.append( { 1, 2, 3, 4 } )
In my opinion append is a property of a container.
Arrays have no such a property, std::array also has no such a property.
Associative containers also have no such a property. std::forward_list has no method insert. So a general function will only conduse users.
And your "general practice" is not applied in this case because as I said it is a property of a container.
Yeah, this should really start as a cohesive library first e.g. in Boost with other similar functions things go that way.
Also depends on what we get out of the Ranges SG.
At least because as a general rule if a function that deals with two objects and is declared as a member function it usually returns reference to "this" object. On the other hand, if such a function is declared as a non-member function it usually returns a new object.
At least because as a general rule if a function that deals with two objects and is declared as a member function it usually returns reference to "this" object. On the other hand, if such a function is
There are ways to implement special versions for std::forward_list, like overloading.
But at first, which semantic you want to have for append( fwd_list, ... ) ? std::forward_list does not even have push_back - I think it should just fail on append.It is a good note. It seems you are starting to understand that append is a property of a container. Look how I named the thread.
In this case we will have different semantics. In my opinion it is not a good idea. I am sure that append should be introduced only for sequantial containers that have method push_back as std::basic_string, std::vector, std::deque, std::list, and std::x_forward_list
for which I am going to write a proposal as I already announced in this forum.
I do not like the idea that some non-member functions will be defined only for narrow groups of containers.
It will only confuse users. Besides it will look strange that std::forward_list will be excluded from sequantial containers relative to this function.
iterator insert(const_iterator position, const T& x);
iterator insert(const_iterator position, size_type n, const T& x);
template <class InputIterator>
iterator insert(const_iterator position,
InputIterator first, InputIterator last);
iterator insert(const_iterator position, initializer_list<T> il);
The same must be valid with push_back. It allows to append one element. What I want that it also would allow to append several elements as insert does. Only push_back will be used through its alias append when several elements are needed to append.
So we have only one possibilityv.insert( v.insert( v.insert( v.end(), s1 ), s2 ), s3 );std::cout << v;
Yes, you can. But it will not look very well taking into account a possible interchangeability with std::basic_string.
I'm pretty much meh (aka neutral to weakly against) this proposal; while the usefulness of append does come up from time to time, it doesn't come up all that often, at least in my experience.
append shows more clear the intention of the programmer. Consider codev.insert( it, std::begin( a ), std:;end( a ) );You can say nothing whether the array is indeed inserted or appended.
On Oct 23, 2013 6:09 PM, "Nevin Liber" <ne...@eviloverlord.com> wrote:
> Contrived situations don't sway me. Bad programmers will write convoluted code no matter how many member functions we give them.
Hehe…
I think we'd better not to regard this as merely a syntax sugar. I looked at libc++ code and I found that since the position is known to be end(), append() can be implemented in a much simpler way compared with insert(). Not sure how beneficial it is though, but so far it looks not too useless.
On Oct 23, 2013 6:31 PM, "Zhihao Yuan" <z...@miator.net> wrote:
> I think we'd better not to regard this as merely a syntax sugar. I looked at libc++ code and I found that since the position is known to be end(), append() can be implemented in a much simpler way compared with insert(). Not sure how beneficial it is though, but so far it looks not too useless.
PS: If you agree with this rationale, I would suggest to add prepend() method to deque, list, and forward_list as well.
--
They will think so by analogy with other similar general functions as for example advance that can be used with any type of iterators (except output iterators).
On Wed, Oct 23, 2013 at 7:05 PM, Vlad from Moscow <vlad....@mail.ru> wrote:
> In fact there is nothing new with the method append because it already
> exists for std::basic_string. If somebody has some doubts then I advise to
> try do not use append with std::basic string and substitute it everywhere in
> code for insert. I am sure that through a month of such coding he will
> quickly understand that method append is necessary.
>
> Introducing method append just makes the common interface of sequential
> containers more consistent.
I would say please forget about basic_string. basic_string
is not a general purpose container, so there is minimal reason
to say "more consistent". Containers and string are different.
For example, string's insert() methods returns string&, do you
want containers' insert() also return container&? Leave different
things different.
So far I understand append() as "bulk push_back", so I suggested
to have a "bulk push_front" as well, both as simplified interfaces
to insert(). Now I think it would be more clear if we name append()
`extend_back`, and prepend() `extend_front`. Just keep away from
string's append(), which even can take a pointer to char -- don't tell
me you want to take T* as well.
To make function append a non-member function in my opinion is simply a bad idea.In fact in this case inside the function you will call method insert because there is no other possibility in this design. So it is not effective.
Moreover this design only confuses users because you must list those containers that can be used with this function.
I understand that it can be a new silly question in interview: list the containers that can be used with this function and with that frunction.It is a very poor design.
On Wed, Oct 23, 2013 at 4:05 PM, Vlad from Moscow <vlad....@mail.ru> wrote:
In fact there is nothing new with the method append because it already exists for std::basic_string. If somebody has some doubts then I advise to try do not use append with std::basic string and substitute it everywhere in code for insert. I am sure that through a month of such coding he will quickly understand that method append is necessary.Introducing method append just makes the common interface of sequential containers more consistent.
Obviously, repeating "it will confuse users" is getting you no closer to an approved proposal, considering nobody else has stepped up in favor of the member function.
I looked at libc++ code and I found that since the position is known to be end(), append() can be implemented in a much simpler way compared with insert().