Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <typeinfo>
- #include <boost/cstdint.hpp>
- #include <boost/mpl/vector.hpp>
- #include <boost/mpl/fold.hpp>
- #include <boost/mpl/map.hpp>
- #include <boost/mpl/pair.hpp>
- #include <boost/mpl/int.hpp>
- #include <boost/mpl/next.hpp>
- #include <boost/mpl/insert.hpp>
- #include <boost/mpl/at.hpp>
- using namespace boost::mpl;
- typedef vector<uint8_t, uint16_t, uint32_t, uint64_t> types_integral;
- typedef vector<float, double, long double> types_floating;
- typedef vector<std::string> types_string;
- typedef vector<types_integral, types_floating, types_string> type_sets;
- template<typename M1, typename M2>
- struct merge_maps
- {
- typedef typename fold<M1, M2, insert<_1, _2> >::type type;
- };
- template<typename S>
- struct make_type_map
- {
- typedef typename fold<
- S,
- map<>,
- insert<_1, pair<_2, S> > >::type type;
- };
- typedef fold<
- type_sets,
- map<>,
- merge_maps<_1, make_type_map<_2> > >::type map_t2s;
- template<typename T>
- struct get_comparable
- {
- typedef typename at<map_t2s, T>::type type;
- };
- int main()
- {
- std::cout << typeid(get_comparable<float>::type).name() << std::endl << std::endl;
- std::cout << typeid(get_comparable<std::string>::type).name() << std::endl << std::endl;
- std::cout << typeid(get_comparable<uint64_t>::type).name() << std::endl << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment