[v3] complex comparison operators
Benjamin Kosnik
bkoz@redhat.com
Sat Nov 6 04:07:00 GMT 2010
This patch is not applied.
As part of the duration constexpr-ifcation, the utility of constexpr
comparison operators became noticeable.
Original use case:
static_assert(_Period::num > 0, "period must be positive");
or
static_assert(system_clock::duration::min() <
system_clock::duration::zero(), "a clock's minimum duration cannot be
less than its epoch");
So, I went looking for other areas in the library that might benefit
from constexpr comparison operators.
Audit rubric:
1) if static constexpr function can return it
2) if some other class can contain it as a static constexpr data
3) has one of operator ==, !=, >, >=, <, <=
4) implementation of comparison operators calls only constexpr functions
This turns up std::complex operators == and != as candidates.
Close:
1. tuple, pair, and <random>'s engines have operator ==, but no
constexpr construction.
2. array, but the the operator implementations are not constexpr.
I think this should go in, but am waiting for a second.
The required complex specializations are
literal types and comparing them at compile time seems worth the
(minimal) effort. A potential problem (?) is that the primary std::complex
template does not mark real(), imag() or any of the constructors as
constexpr. (I believe this is incorrect: it means that compile-time
behavior is different for specializations and primary templates, which
seems misleading.)
Since the primary template for complex is not guaranteed to be useful
for other than the required classes, I'm not quite sure this is a
reason that is credible.
tested x86_64/linux
-benjamin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20101105-3.patch
Type: text/x-patch
Size: 3511 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20101106/af3fdeb7/attachment.bin>
More information about the Libstdc++
mailing list