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