Relative Content

Tag Archive for templatesc++17

expand and fold parameter pack in specific way

#include <string> #include <string_view> template<typename… Args> std::string_view concatenateBuffer(std::string &buffer, Args &&… args){ static_assert((std::is_constructible_v<std::string_view, Args> && …)); buffer.clear(); (buffer.append(std::forward<Args>(args)), …); return buffer; } template<typename …Ts> std::string_view concat(std::string s, Ts …ts){ return concatenateBuffer(s , ((“,” , ts) , …) ); } #include <iostream> int main(){ std::string b; std::cout << concat(b, “a”) << ‘n’; std::cout << concat(b, “a”, […]