-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Thanks for thinking about this problem so carefully. It seems crazy that it’s so hard to make some truly compile time constant strings without heap/malloc. I have a use case similar to person on your blog I think? Just static class convenience constants to concatenate with other std::string(_view)?
Doesn’t work, because cannot be “+”()d with std::string_view (or std::string).
I am sure you can understand my intended usage. Is there a way with your lib? Or another much simpler way?
#define AK_TOOLKIT_CONFIG_USING_STRING_VIEW 1
class A {
static constexpr auto VT100_ESC = sstr::literal("\x1b");
static constexpr auto VT100_CLS = VT100_ESC + "[2J";
static constexpr auto VT100_BOX_DRAW_ON = VT100_ESC + "(0";
static constexpr auto VT100_BOX_DRAW_OFF = VT100_ESC + "(B";
static constexpr auto VT100_UNDERLINE_ON = VT100_ESC + "[4m";
static constexpr auto VT100_UNDERLINE_OFF = VT100_ESC + "[0m";
void method();
}
void A::method() {
std::string_view somestr = "hello";
std::string_view vt = VT100_UNDERLINE_ON + somestr + VT100_UNDERLINE_OFF;
std::cout << vt;
}
compile fails with:
error: invalid operands to binary expression ('const ak_toolkit::static_str::string<4, ak_toolkit::static_str::char_array>' and 'std::string_view' (aka 'basic_string_view<char>'))
std::string_view vt = VT100_UNDERLINE_ON + somestr + VT100_UNDERLINE_OFF;
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels