|
Boost : |
From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2025-01-07 16:20:46
Am 07.01.25 um 16:16 schrieb Rainer Deyke via Boost:
> On 06.01.25 19:43, Ivan Matek via Boost wrote:
>> boost::implies(student.graduaded(), student.num_active_courses() == 0)
>> reads much much nicer than
>> !student.graduaded() || student.num_active_courses() == 0
>
> The problem here is that your example is closer to the English usage
> of the word "implies" than to the usage in boolean logic that we are
> talking about. "A implies B" in English usually means that there is a
> logical connection such that B is necessarily true if A is true. For
> example, a student who has graduated necessarily has no active courses.
>
> "A => B" merely means that either A is false or B is true. For
> example, "I am the president of the United States => there is world
> peace" is trivially true because I am not the president of the United
> States, even though if I would almost certainly be unable to achieve
> world peace even if I were the president of the United States. The
> C++ expression "!A || B" is actually closer to the correct English
> than "A => B" for expressing this condition.
Isn't that is exactly what was written above?
I.e. `A => B` == `boost::implies(A, B)` == `!A || B`
Or with the example: if( boost::implies(student.graduaded(),
student.num_active_courses() == 0) ) /*...*/;`
In plain English: "If a graduated student implies he has no active courses"
So I don't see how "!A || B" is closer to anything than "A => B" if they
are the same thing.
What am I missing here? Or did you mistype anything?
Aside from that I don't actually see how that could be useful outside of
asserts. I.e. `assert ( implies(this, that) )` makes sense and is readable.
But `if implies(this, that)` not so much. Because it sounds much more
general than it is it might be rather confusing.
With your example `if( i_am_president() "implies" is_world_peace() )` is
likely true right now, but if I became president at some point someone
trusting this statement would likely be disappointed. Not that such
things ever stopped any politician ;-)
It still boils down to the English language which doesn't match the
logical interpretation which is likely what you intended to say because
also when reading the code `student.graduaded()` might not magically
ensure `num_active_courses() == 0` although it reads (in English terms)
that way.
TLDR: I wouldn't want such a function or even operator as I don't see
any reasonable uses outside of assertions.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk