Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Created September 16, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomg/9ed2f69d01a186923ab8 to your computer and use it in GitHub Desktop.
Save thiagomg/9ed2f69d01a186923ab8 to your computer and use it in GitHub Desktop.
Template and OO
struct string_builder {
/...
template<typename T>
string_builder &add(T v) {
internal::add<T>(_s, v, _size);
return *this;
}
namespace internal {
//General implementation
template <typename T>
struct add {
add(std::string &buffer, T val, int size_inc) {
std::string s = std::to_string(val);
_check_size(buffer, s.size(), size_inc);
buffer += s;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment