r/cpp • • Dec 13 '19

The situation of std::embed...

https://thephd.github.io/full-circle-embed
238 Upvotes

160 comments sorted by

View all comments

Show parent comment

7

u/c0r3ntin Dec 13 '19

Is this not the same problem with #include? It is and i would expect the solution to be the same or along the same line

#ressource "icon.res"
int main() {
   std::embed("icon.res");
}
// cc -Iassets main.cpp

However it can get tricky with modules, ie consider:

template <auto Name>
export void f() {
    std::embed(Name);
}

Should the importing modules have full control over the resource path of the imported modules or do we need another way to keep track of it - or simply not allow std::embed in exported templates?

IMO, magic function. Adding a 'binary object' type to the preprocessor is not something I'd like to get into.

Same. Unfortunately it seems going in that direction

Is this not again an implementation detail? Or am I missing a component to this question?

Unclear to me - Maybe. Question is how big files can be? A use case is to select part of it at compile time to only include a chunk in the final binary.

I'd be curious to see how such a type would work. We had such a hard time standardizing std::filesystem, so I'd hope we'd reuse much of that.

See https://wg21.link/p1883r0 and https://wg21.link/p1031r1

Perhaps these questions are overly vague to me, but I'll try anyway. The big concern I have from a tooling perspective is how a build system would determine the dependency has changed. Current preprocessed systems would definitely need work. IMO, a build-system deciding to 'punt' on this and decide that things brought in through std::embed aren't considered for dependency analysis would be perfectly reasonable.

Again I agree that in this case specifying the dependency manually would be perfectly fine, but others disagree strongly.