C++ Logo


Advanced search

Re: [std-proposals] constexpr support in std::filesystem API

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Tue, 12 Mar 2024 07:29:44 -0700
On Tue, Mar 12, 2024 at 7:15 AM Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> To be fair:
> How much different is it in power from a C23 #embed?
> Both feature that certain files, the ones which the implementation allows,
> can be fully (binarily) read at compile time.
> Differences:
> - the filepath can be created at runtime -> better hiding of the file
> read read; C23 probably supports macros for the filepath?
> - the contents can be processed by constexpr functions -> probably the
> same can be achieved by mixing C23 with C++ constexpr
> - the files could be read several times -> Denial of Service build; a
> long build can probably be achieved by other ways

The big one is the the filepath can be created at "runtime." Yes, #embed
allows you to use macros — for example you can now write a quine as
— but you can't actually smuggle in a fully constexpr-evaluated string like

constexpr char myfilename[] = "test.txt";
constexpr char data[] = {
#embed (myfilename) // doesn't work

So #embed doesn't seem to be useful as a "constexpr filesystem,"

Similarly, AFAICT no vendor supports `_Pragma(mystring)` with mystring a
constexpr-evaluated string; the argument must be literally a string
literal. But IIUC, C++26 *is* getting `static_assert(false, mystring)` —
not with char arrays, but at least with strings and string_views. Example:

my $.02,

Received on 2024-03-12 14:29:59