C++ Logo

std-proposals

Advanced search

Re: [std-proposals] ^^operator [was: Re: New draft proposal: Add "%s" (two-digit truncated-integer seconds) as a std::format conversion specifier for std::chrono time types.]

From: Peter Sommerlad (C++) <"Peter>
Date: Thu, 4 May 2023 13:51:01 +0200
One can use enums class types as substitutes for the built-ins and then
define operator^ to do exponentiation instead of bit-xor :-)

And may be have a separate set of bit-fiddling types, where only the
bitwise operators are defined.

For a start see my https://github.com/PeterSommerlad/PSsimplesafeint
which makes the bit operations only available for the unsinged replacements.

Regards
Peter.

David Brown via Std-Proposals wrote on 04.05.23 13:38:
> On 04/05/2023 11:47, Timur Doumler via Std-Proposals wrote:
>> I don't think we could ever have operator** because ** has a meaning
>> in C++ today (multiplication followed by dereference, or double
>> dereference). Am I missing something?
>>
>> Cheers, Timur
>>
>
> Yes, "x ** y" currently parses as "x * (*y)". I don't know how that
> could be resolved without making spaces more significant in token parsing.
>
> (Personally, I'd be happy to see the introduction of rules regulating
> spacing in connection with operators - it would lead to neater, more
> consistent code that is easier for mere humans to read. But the
> standards committee have their little obsessions about backwards
> compatibility of existing code, so I don't think that would be accepted!)
>
>
> If only C++ allowed Unicode symbols and punctuation as identifier
> letters, we could use "x ↑ y" for exponentiation (and annoy programmers
> with limited keyboard layouts!).
>
>
> David
>


-- 
Peter Sommerlad
Better Software: Consulting, Training, Reviews
Modern, Safe & Agile C++
peter.cpp_at_[hidden]
+41 79 432 23 32

Received on 2023-05-04 11:51:05