我想要做的是用constexpr函数替换字符串,例如:
constexpr auto replace_sub_str(const char* x) {
// some magic
return ans;
}
#define LOG(x) replace_sub_str(x)示例:LOG("hello XX, XX");,它将被替换为"hello KK, KK"
我更新了这个问题,因为也许奇怪的人物让人困惑。这里XX只是一个子字符串,KK也是。
发布于 2022-06-15 07:14:16
是:
template <auto N>
constexpr auto replace_sub_str(char const (&src)[N]) {
std::array<char, N> res = {};
// do whatever string manipulation you want in res.
return res;
}
auto constexpr str = replace_sub_str("hello {}, {}");https://stackoverflow.com/questions/72627188
复制相似问题