mercredi 20 décembre 2017

If std::addressof is a readable version of &. What is a readable version of *&?

*&x

Using c++11, we can write as

* std::addressof(x)

However, is there more readable version of this expression?

constexpr uint64_t lil_endian = 0x65'6e'64'69'61'6e; 
    // a.k.a. Clockwise-Rotated Endian which allocates like
    // char[8] = { n,a,i,d,n,e,\0,\0 }

constexpr auto& arr = 
    reinterpret_cast<const std::array<char,8> &>
        (*std::addressof(lil_endian) );

int main()
{
    const auto str = std::string(arr.crbegin()+2, arr.crend() );

    std::cout << str << '\n'
              << str.size() << '\n' << '\n';
    for (const auto ch : str) {
        std::cout << ch << " : " << std::hex << (unsigned int) ch << '\n';
    }

}


endian
6

e : 65
n : 6e
d : 64
i : 69
a : 61
n : 6e

godbolt.org/g/9StHsE

http://ift.tt/2kuCH2C

Aucun commentaire:

Enregistrer un commentaire