C++ Logo

std-proposals

Advanced search

Re: [std-proposals] consteval hashing of compile-time constant compound literals

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 16 May 2024 10:33:02 +0100
On Wed, May 15, 2024 at 10:59 AM Jonathan Wakely wrote:
>
> Why would you want the md5sum for tuple<int, char> to
> depend on the unspecified order of the two subobjects,
> and the unspecified number of padding bytes?


It will at least be consistent for the current compiler in use, in
particular for consteval stuff. I've altered the consteval
implementation for MD5 so that, instead of returning
std::array<char,16u>, it returns a __uint128_t so that I can use it in
switch statements as follows:

    switch ( md5(some_runtime_value) )
    {
    case md5("monkey"): return 663;
    }


> Instead of inventing more complicated and less portable ways to access every
> object as a bag of bits, why not follow the actually useful and already existing
> practice of abseil and boost and others?


I want to experiment to see how far I can go with having consteval
128-Bit numbers to use in switch statements.
I think I'll alter the C++ compiler to make __builtin_bit_cast_raw
which will be the same as its namesake except it can work with
non-trivially-copiable types.

Received on 2024-05-16 09:33:15