Skip to content

Instantly share code, notes, and snippets.

@htfy96
Created July 31, 2015 16:03
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 htfy96/a530e810692727f36ea9 to your computer and use it in GitHub Desktop.
Save htfy96/a530e810692727f36ea9 to your computer and use it in GitHub Desktop.
template <class T>
class MyFormatting;
typedef boost::variant<bool, int, std::string> var_t;
template <>
class MyFormatting<int>
{
private:
const int& nucleus;
public:
MyFormatting(const int& n) : nucleus(n) {}
friend std::ostream& operator << (std::ostream& os, const MyFormatting& w)
{
return os << "int:" << w.nucleus;
}
};
//... specilization for bool and std::string
template <class... T>
using Variant_Formatting_t = boost::variant < MyFormatting<T>... > ;
Variant_Formatting_t<bool, int, std::string>
FMT(const var_t& A__)
{
return Variant_Formatting_t<bool, int, std::string>{A__};
}
int main()
{
var_t var_int = 3;
var_t var_str = "123";
std::cout << FMT(var_int)<< FMT(var_str) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment