C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function to Find Number of Members in a Pointer

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Wed, 27 Aug 2025 11:06:44 +0100
On Wed, 27 Aug 2025 at 09:03, Paul Robert Stackhouse via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello,
>
> You may be wondering why I decided to make a function that gets the number
> of members from a pointer that is different than just using sizeof(). The
> reason is that sizeof does not actively take into account the varied sizes
> of its members. Take a double pointer, for example. The members of a double
> pointer could be different from each other, which would mess up checking
> for the size of the double pointer vs the size of the single pointer. This
> function takes care of that.
>

What is a double pointer and what is a single pointer? Do you mean T** vs
T*?
What are the members of a pointer? A class has members, but a pointer is
not a class.


>
> It basically works by counting up the size of each individual part until
> the resulting size is no longer less than the size of the pointer.
>

Why? What has sizeof(set) got to do with anything?

This utilizes size_t as a variable, to not only keep it consistent with the
> size_t results of the size function for lists, maps, and the like, but to
> ensure that the count remains accurate, since a simple integer may not be
> big enough for the number of members. From there it returns the number of
> parts that it "detected", and the result is the total number of members
> within a pointer.
>

I'm very confused.


>
> I asked google if there was a way within c++ to do this officially, and
> its AI said there wasn't. If this already exists within the standard C++
> libraries, that's fine. However, if there isn't a way to check for the
> number of members, especially in the cases where the size of the members is
> flexible enough, then I would ask that this be added to the standard
> template library.
>
> Thank you for your consideration.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-08-27 10:07:05