Last active
August 29, 2015 14:01
-
-
Save dgodfrey206/62b851d1e02d953951ad to your computer and use it in GitHub Desktop.
A num_put facet that appends a prepends and appends text to an output operation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <locale> | |
template<class char> | |
class num_put : public std::num_put<char> | |
{ | |
using string_type = std::basic_string<char>; | |
string_type first_, second_; | |
public: | |
num_put(const string_type& first = string_type{}, | |
const string_type& second = string_type{}, | |
int refs = 0) | |
: std::num_put<char>(refs) | |
, first_(first) | |
, second_(second) | |
{ } | |
protected: | |
iter_type do_put(iter_type out, std::ios_base& str, char_type fill, long v) const; | |
iter_type do_put(iter_type out, std::ios_base& str, char_type fill, unsigned long v) const; | |
private: | |
iter_type do_put_impl(iter_type out, std::ios_base& str, char_type fill, long v) const; | |
}; | |
num_put::iter_type | |
do_put_impl(iter_type out, std::ios_base& str, num_put::char_type fill, long v) const | |
{ | |
num_put::iter_type it = std::copy(first_.begin(), first_.end(), out); | |
it = std::num_put<char>::do_put(out, str, fill, v); | |
it = std::copy(second_.begin(), second_.end(), out); | |
return it; | |
} | |
num_put::iter_type | |
num_put::do_put(num_put::iter_type out, std::ios_base& str, num_put::char_type fill, long v) const | |
{ | |
return do_put_impl(out, str, fill, v); | |
} | |
num_put::iter_type | |
num_put::do_put(num_put::iter_type out, std::ios_base& str, num_put::char_type fill, unsigned long v) const | |
{ | |
return do_put_impl(out, str, fill, v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment