Add #embed generation support and string_view-based path APIs - #32
Merged
Conversation
CMakeRC.cmake now emits a C23 #embed directive in generated resource files when the compiler supports it (guarded by __has_embed), falling back to the hex-literal array otherwise; empty files keep the existing zero-byte array behavior. cmrc.hpp gains optional std::string_view support: file::view(), a string_view-based path_param, and heterogeneous (std::less<>) map lookups under C++17, avoiding string copies when opening/embedded path lookups while remaining compatible with older standards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Emit
#embedfor resource bytes and addstring_viewpath APIsMotivation
The generated resource file carries every byte as a hex-literal array, which is slow to compile and blows up the generated file. C23's
#embedlets the compiler paste the bytes directly, so that's a no-brainer for compilers that support it. While in there: every path lookup tookconst std::string&, which forced a copy even when the caller already had a view. That's gone too.Changes
#embeddirective guarded by__has_embed, with the hex-literal array kept as the fallback for older compilers. Empty files still emit the zero-byte array —#embedof an empty file is ill-formed in some compilers withoutif_empty().file::view()and apath_paramtype (std::string_viewunder C++17,const std::string&before);open,is_file,is_directory,existsanditerate_directoryall take it.std::less<>) under C++14+, so lookups no longer materialize astd::stringkey.@sandsc submitted a pr in the original CMakeRC repository to support std::string_view -- this PR adds support for std::stringview, but implemented differently.