C++ Logo

std-proposals

Advanced search

Re: Modern std::byte stream IO for C++

From: Lyberta <lyberta_at_[hidden]>
Date: Fri, 6 Mar 2020 14:03:57 +0300
Maciej Cencora:
> Exactly as I said, endianess in your example is a runtime property, while
> in most scenarios it is actually known at compile time.
> It should be something like:
> std::io::default_big_endian_context ctx{stream};
> or
> std::io_default_context<std::endian::big> ctx{stream};
>

I'm pretty sure we can avoid doing explicit NTTP because:

1. Serialization functions should be templates by default.
2. Once compilers implement `std::bit_cast`, everything except system calls in file IO should become constexpr.

I think that templates + constexpr is enough for compiler to see that the developer hard-codes the value of endianness and to
remove dead branches.


Received on 2020-03-06 05:06:50