Date: Thu, 9 Oct 2025 14:03:55 +0200
What is the difference to static_cast<unsigned int>(size())
(or some suitably longer <size_t> type)
Or you want to definitely have functions differentiated (overloaded) by return type?
-----Ursprüngliche Nachricht-----
Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Do 09.10.2025 13:43
Betreff:Re: [std-proposals] ranges::size should always return a unsigned integer
An:std-proposals_at_[hidden];
CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>;
On Wednesday, October 8, 2025, Yexuan Xiao wrote:
Why is it allowed to return a signed integer? C++ users are accustomed to the fact that the size_type of containers is an unsigned integer, so the size of containers should also return an unsigned integer.
- - - - - - - Begin Half-baked Idea - - - - - - -
What if we could define a function (or member function) as follows:
+|- int size(void);
The trigraph, +|- , at the beginning indicates that the function has two forms: one returning signed, and one returning unsigned.
So then when you want to invoke the function, you get the unsigned version as follows:
auto x = size();
and you get the signed version as follows:
auto x = +|- size();
Similarly you would ake the address of the function as follows:
int (*p1)(void) = &size;
unsigned (*p2)(void) = & +|- size;
I would add the stipulation that both of these function pointers can compare equal (because they'll most likely have the same machine code anyway since Two's Complement is now mandatory).
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-10-09 12:16:29
