Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <boost/fusion/container/map.hpp>
  3. #include <boost/fusion/include/map.hpp>
  4. #include <boost/fusion/container/map/map_fwd.hpp>
  5. #include <boost/fusion/include/map_fwd.hpp>
  6. #include <boost/fusion/sequence/intrinsic/at_key.hpp>
  7. #include <boost/fusion/include/at_key.hpp>
  8. #include <boost/fusion/include/io.hpp>
  9. #include <boost/archive/text_iarchive.hpp>
  10.  
  11. struct fieldOne {};
  12. struct fieldTwo {};
  13. typedef boost::fusion::map<
  14. boost::fusion::pair<fieldOne, int>,
  15. boost::fusion::pair<fieldTwo, double>
  16. > tFusionMap;
  17.  
  18. int main() {
  19. tFusionMap map;
  20. boost::archive::text_iarchive ar(std::cin);
  21.  
  22. std::cin >> map; /* no compile error */
  23. ar & map; /* compiler error: */
  24.  
  25. return 0;
  26. }
  27.  
  28. struct boost::fusion::map<boost::fusion::pair<fieldOne, int>,
  29. boost::fusion::pair<fieldTwo, double> >’ has no member named ‘serialize’
  30.  
  31. fusion_serialize(ar, m);
  32.  
  33. ar & m;
  34.  
  35. namespace boost {
  36. namespace serialization {
  37.  
  38. template<class Archive, typename T, std::size_t num_dims>
  39. void serialize( Archive & ar, T & map, const unsigned int version ) {
  40. fusion_serialize(ar,map);
  41. }
  42. }
  43. }
  44.  
  45. namespace boost { namespace serialization {
  46.  
  47. struct saver {
  48. template <typename Ar, typename Pair>
  49. void operator()(Ar& ar, Pair& data) const
  50. {
  51. ar & data.second;
  52. }
  53. };
  54.  
  55. template <typename Ar, typename... TArgs>
  56. void serialize(Ar& ar, boost::fusion::map<TArgs...>& fmap, unsigned /*version*/)
  57. {
  58. using phoenix::ref;
  59. using phoenix::arg_names::arg1;
  60. static const phoenix::function<saver> save {};
  61.  
  62. fusion::for_each(fmap, save(ref(ar), arg1));
  63. }
  64.  
  65. } }
  66.  
  67. #include <boost/archive/text_oarchive.hpp>
  68. #include <iostream>
  69.  
  70. typedef boost::fusion::map<
  71. boost::fusion::pair<struct fieldOne, int>,
  72. boost::fusion::pair<struct fieldTwo, double>
  73. > tFusionMap;
  74.  
  75. int main() {
  76. tFusionMap map { 42 , M_PI };
  77. boost::archive::text_oarchive oa(std::cout);
  78. oa & map;
  79. }
  80.  
  81. 22 serialization::archive 10 0 0 42 3.1415926535897931
  82.  
  83. #include <boost/fusion/include/map.hpp>
  84. #include <boost/fusion/algorithm.hpp>
  85. #include <boost/phoenix/phoenix.hpp>
  86. #include <boost/phoenix/fusion.hpp>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement