Is there any way to make a substring at compile time, and NOT store the original string in the binary ?
I'm using std::experimental::source_location
, and really only need the filename, and not the full path, which ends up taking lots of space in the binary
Here's an example:
#include <iostream>
#include <experimental/source_location>
consteval std::string_view filename_only(
std::experimental::source_location location = std::experimental::source_location::current())
{
std::string_view s = location.file_name();
return s.substr(s.find_last_of('/')+1);
}
int main()
{
std::cout << "File: " << filename_only() << '\n';
}
https://godbolt.org/z/TqE7T87j3
The full string "/app/example.cpp" is stored, but only the file name is needed, so "/app/" is wasted memory.