Create a gist now

Instantly share code, notes, and snippets.

Embed
Template and OO
class string_builder {
//...
string_builder &add(int v) {
std::string s = std::to_string(v);
_check_size(s.size());
_s += s;
return *this;
}
string_builder &add(const std::string &v) {
_check_size(v.size());
_s += v;
return *this;
}
string_builder &add(const char *v) {
_check_size(strlen(v));
_s += v;
return *this;
}
string_builder &add(double v) {
std::string s = std::to_string(v);
_check_size(s.size());
_s += s;
return *this;
}
string_builder &add(bool v) {
std::string s = v?"Y":"N";
_check_size(s.size());
_s += s;
return *this;
}
//There are much more methods to implement
//string_builder &add(unsigned int v);
//string_builder &add(float v);
//string_builder &add(long long v);
//string_builder &add(unsigned long long v);
//.... And much more ....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment