Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Last active September 16, 2015 01:53
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/1929547c54a505e83902 to your computer and use it in GitHub Desktop.
Save thiagomg/1929547c54a505e83902 to your computer and use it in GitHub Desktop.
Template and OO - Custom class
//Now I can add my own class to this string_builder add function
struct LazyMessage {
std::string type;
int seq;
std::vector<std::string> entries;
};
namespace Text {
namespace internal {
template <>
struct add<LazyMessage> {
add(std::string &buffer, LazyMessage &msg, int size_inc) {
std::string s = msg.type;
for(const auto &entry : msg.entries)
s += " [" + entry + "]";
_check_size(buffer, s.size(), size_inc);
buffer += s;
}
};
} //Namespace internal
} //Namespace Text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment