Created
July 31, 2015 16:03
-
-
Save htfy96/a530e810692727f36ea9 to your computer and use it in GitHub Desktop.
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
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