#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", "b") << '\n';
}
Eu tenho function concatenateBuffer
, a versão que mostro aqui é simplificada, mas o que ela faz é anexar "strings" (char *, string_view, string) a buffer
.
Eu quero fazer outra função concat
que atue como uma função php implodir, por exemplo, colocar o separador "," entre as "strings".
por exemplo, se você ligar:
concat(b, "a") ===> "a"
concat(b, "a", "b") ===> "a,b"
concat(b, "a", "b", "c") ===> "a,b,c"
Isso é possível com o pacote de parâmetros de dobramento?
Você pode quebrar o pacote para poder inserir
,
entre as cordas: