Much to think about.
@
JLBorges
Yes, you have noticed the std::find_if / std::any_of connection. Too much rainbow in that cookie, though. Comparability magic should pre-exist, IMO.
if (contains( x, xs )) ←→
if ((x in xs))
if (in( x, xs, []{...} )) ←→
if (any_of( x, xs, []{...} ))
↑
er, what?
Does not read well without having to look up what “in” means beyond “membership”...?
Remember, “in” is strict membership, fudging only on is_comparable( x, any element of xs ).
lastchance wrote: |
---|
Trouble is, I use "in" for the name of an istream rather a lot. |
Crud.
I knew that, too. Using languages where “in” actually
is an operator (like Pascal and Python), has made me hesitant to ever use it as an object identifier to the point where I forget that people do.
And such use is perfectly valid reasonable, too.
(I tend to use “input” and “inf” where it makes a difference over just “f” for file meta names.)
if (x|xs) still has the readability problems... (“What does
that mean...?”)
if ((x in xs)) would still work, but it would break any place you try to use “in” as an identifier...
Though, and this is probably a conceit of mine, since C++ does not have anything like Python’s set comprehensions, the (x|xs) syntax is still close enough to set builder notation that it works for my mind. Maybe even better as ((x|xs)), since the extra parentheses do actually indicate that we are going boolean with the expression.
In Pascal, you can say “
x in xs” for a simple membership predicate, and “
xs <= ys” for a subset predicate (xs ⊆ ys), so I have considered
<= as well, but it just doesn’t flow, and is no better than a simple vertical pipe. That is,
if (x <= xs) just doesn’t feel right, and makes no more sense than
if ((x|xs)).
Sigh. If only there were
in and
ni operators in C++. (Something I have always missed.)
Vanity projects can be both rewardingly fun and tear-your-hair-out frustrating.
Y’all’ve given me [more stuff] to think about. Thanks!