Created
June 16, 2011 17:18
-
-
Save osyo-manga/1029726 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <string> | |
#include <boost/variant.hpp> | |
#include <boost/mpl/identity.hpp> | |
#include <boost/mpl/print.hpp> | |
typedef boost::mpl::print<int>::type hogehoge; | |
typedef boost::variant<std::string const&, char const*> any_string; | |
struct c_str_impl{ | |
typedef char const* result_type; | |
result_type | |
operator ()(any_string const& str) const{ | |
return boost::apply_visitor(*this, str); | |
} | |
result_type | |
operator ()(std::string const& str) const{ | |
return str.c_str(); | |
} | |
result_type | |
operator ()(char const* str) const{ | |
return str; | |
} | |
} c_str; | |
void | |
hoge(any_string v){ | |
std::cout << c_str(v) << std::endl; | |
} | |
int | |
main(){ | |
hoge("char*"); | |
hoge(std::string("string")); | |
std::cout << "hello world" << std::endl; | |
std::cout << "hel" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment