#include #include #include using namespace std; template class Wrapper { public: Wrapper(const T t) : value_{t} {} // initialize value_ void set(const T t){ value_ = t;} // set value_ T get() const {return value_; } // access value_ std::string str() const; // string representation of value_ private: T value_; }; template std::string Wrapper::str() const { return Policy::convert(value_); } struct Hexadecimal { template static std::string convert(T const & value) { ostringstream oss; oss << hex << "0x" << value; return oss.str(); } }; struct Quoted { template static std::string convert(T const & value) { ostringstream oss; oss << '"' << value << '"'; return oss.str(); } }; int main() { Wrapper hexint{4711}; cout << hexint.str() << endl; Wrapper citint{4711}; cout << citint.str() << endl; Wrapper citstring{"foobar"}; cout << citstring.str() << endl; }