I would like to use the fmt library to create a string_view from my format args. There is plenty documented about passing in a compile-time string as the format string, however, I want to output a compile-time string, so that I may use it in other static parts of my code. Is there a way to do this? So far, all the functions I have seen return a std::string
; I also tried format_to
, but it seems to be explicitly disabled for a string_view iterator (which I am assuming wouldn't work compile-time anyway, as it's mutating). It may be simple and I'm just looking in the wrong places, I don't know.
I would like to be able to do something akin to the following:
consteval std::string_view example(unsigned i){
return fmt::something<std::string_view>("You sent {}"sv, i);
}
So far, this library seems to provide what I need, but, it would be advantageous to avoid a second dependency.
std::string_view
is non-owning. Thus it can't be a recipient of a format because there is no backing store or the backing store would be ephemeral. That would lead to a dangling reference in effect which is bad™. – Consecration