C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Consistent behavior on Container actions

From: organicoman <organicoman_at_[hidden]>
Date: Tue, 28 Oct 2025 07:32:05 +0100
Hello Simon,Thank you for your feedback.This thread was not going toward the direction i wanted, so I stopped it to save everyone 's time.But if you want answers to your observations in private session, i will happy to elaborate.OgSent from my Galaxy
-------- Original message --------From: Simon Schröder via Std-Proposals <std-proposals_at_[hidden]> Date: 10/28/25 7:10 AM (GMT+01:00) To: std-proposals_at_[hidden] Cc: Simon Schröder <dr.simon.schroeder_at_[hidden]> Subject: Re: [std-proposals] Consistent behavior on Container actions On Oct 26, 2025, at 6:00 PM, organicoman via Std-Proposals <std-proposals_at_[hidden]> wrote:-------- Original message --------From: Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]> Date: 10/26/25 4:52 PM (GMT+01:00) To: std-proposals_at_[hidden] Cc: Sebastian Wittmeier <wittmeier_at_[hidden]> Subject: Re: [std-proposals] Consistent behavior on Container actions
>You can create a container, which applies >certain operations (like copy, move, >empty) on all of its contained objects.It would be more intuitive to have this as the default. ///vec(const vec&) ;// copy each elemvec(vec&&);// move each elemvec& operator =(const vec&);//assignment by copy construction or copy assign each elemvec& operator =(vec&&);// assignment by move construction or move assign each elemvoid clear();//destroy each elem///Actually, I fully disagree: Every member function of a container works on the container. This is usually how things work: if you call member functions on an object (i.e. a container in this case) it does its operation on the object (and not something contained in it).Copying a container needs to copy every single element. How else would it work? Moving the container moves the container and not its elements. Clearing the container clears it; as a side effect it needs to destruct all of its elements. If the intended goal is to destruct all of its elements, clear() is a bad description (because it is not clearing the elements themselves, but destructing them) and should rather be called destruct_all_elements(). size() gives you the size of the container and not the sizes of the elements. empty() tells me if the container is empty and not if it’s elements are empty. resize() doesn‘t even work in your logic. If you want to apply an operation on every element of the container you have the free-standing functions of the <functional> header.Your logic is flawed. Member functions of a container work on the container and not its elements. You are confusing the necessary side effects with the actual action performed on the container. And the side effects are done in the most effective way possible. And this is C++: we WANT the most effective way possible and not your twisted logic.Even if your logic was right, the C++ compiler should optimize for the fastest performance possible. See the current implementation as an optimization of what you want. Optimizations don‘t always give you what you think you want. But, they certainly give you better performance.

Received on 2025-10-28 06:32:17