r/cpp • • Jul 23 '22

finally. #embed

https://thephd.dev/finally-embed-in-c23
353 Upvotes

202 comments sorted by

View all comments

Show parent comments

1

u/bruh_nobody_cares Jul 23 '22

what is blocking them though....my question is not about what we have rn but why we have it this way....why not a constexpr function in C++ or const eval function in Rust ....I'm assuming the return type can be a wrapper around something that's known at compile time....since the compiler will plug those bytes in anyways so the compiler knows the size.....
what magic does macros have and const eval functions in Rust "cannot" ?

1

u/TinyBreadBigMouth Jul 23 '22

Macros can emit arbitrary code. Functions can only return predefined types with known sizes.

I'm assuming the return type can be a wrapper around something that's known at compile time....since the compiler will plug those bytes in anyways so the compiler knows the size.....

Are you suggesting a const eval function that returns CompilerByteLiteral or something? Because that's what a Rust macro is.

0

u/bruh_nobody_cares Jul 23 '22

okay let me ask the question in reverse then....can I write a function that invokes this macro as a const eval function that return CompilerByteLiteral if not then why and if yes, then why not writing the function around the compiler built-in directly ?

1

u/sephirothbahamut Jul 23 '22

i suggest you search for compile time reflection. It sounds like what you're asking for. It is proposed for c++, and if you want to test the idea out you can try it in java, it has both compile time and runtime reflection

→ More replies (0)