Add is_empty

131 views
Skip to first unread message

joewo...@gmail.com

unread,
Mar 12, 2019, 2:17:06 PM3/12/19
to ISO C++ Standard - Future Proposals
The one thing that has irritated me the most with the standard library is using ::empty() instead of ::is_empty(). Is there a possibility of adding is_empty() to every class using empty()?

Daniel Krügler

unread,
Mar 12, 2019, 2:33:03 PM3/12/19
to std-pr...@isocpp.org
Am Di., 12. März 2019 um 19:17 Uhr schrieb <joewo...@gmail.com>:
>
> The one thing that has irritated me the most with the standard library is using ::empty() instead of ::is_empty(). Is there a possibility of adding is_empty() to every class using empty()?
>

I don't consider that as a viable option:

1) An API that provides both "empty" and "is_empty" is confusing: Does
"empty" means something different? In addition: This is not really new
functionality, it is just selling existing functionality under a new
name.
2) Albeit the current Container requirements are actual tables that
are intended to simplify the Standard C++ Library specification, many
programmers in the world do consider them as kind of concepts and this
means that you break existing libraries providing a "Standard
Container" type which don't provide yet both empty() and is_empty()
3) Why should we modify a bunch of types in the standard, if we could
just provide a single _free_ function template? Problem is: We already
have such a single free function "empty" ;-)

My recommendation is: Why don't you define your own free function
template is_empty (similar to the free function "empty" as described
by (3)) that delegates either to std::empty() or that implements an
even simpler protocol (Such as that it participates in overload
resolution when x.empty() is valid for some const object x of type X)?

- Daniel

Jake Arkinstall

unread,
Mar 12, 2019, 2:37:28 PM3/12/19
to std-pr...@isocpp.org
Agree that the current naming convention is dumb.

Disagree that adding a new method is a solution. If there's one thing that's worse than a badly named method, it's multiple versions of the same thing doing what they do best: confusing people.


On Tue, 12 Mar 2019, 18:17 , <joewo...@gmail.com> wrote:
The one thing that has irritated me the most with the standard library is using ::empty() instead of ::is_empty(). Is there a possibility of adding is_empty() to every class using empty()?

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ee9b4876-3e40-417c-a460-347fa83871ce%40isocpp.org.

joewo...@gmail.com

unread,
Mar 12, 2019, 2:59:15 PM3/12/19
to ISO C++ Standard - Future Proposals
I tend to agree for all but this case. FYI, see string::size() and string::length()

Daniel Krügler

unread,
Mar 12, 2019, 3:03:49 PM3/12/19
to std-pr...@isocpp.org
Am Di., 12. März 2019 um 19:59 Uhr schrieb <joewo...@gmail.com>:
>
> I tend to agree for all but this case. FYI, see string::size() and string::length()

This is a historical accident - and note that no other container
(except submatch) provides such a length function.

- Daniel

Daniel Krügler

unread,
Mar 12, 2019, 3:05:18 PM3/12/19
to std-pr...@isocpp.org
Am Di., 12. März 2019 um 20:03 Uhr schrieb Daniel Krügler
<daniel....@gmail.com>:
I meant match_results instead of submatch (submatch is no container)

> - Daniel
Reply all
Reply to author
Forward
0 new messages