fork(140) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. #include <boost/assign.hpp>
  5. #include <boost/format.hpp>
  6. #include <boost/foreach.hpp>
  7. #include <boost/current_function.hpp>
  8. #include <boost/ptr_container/ptr_vector.hpp>
  9. #include <boost/ptr_container/ptr_container.hpp>
  10.  
  11. namespace jefuty {
  12. struct Hoge {
  13. Hoge () :x_(false)
  14. { }
  15. bool judge (void) const {
  16. std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")" << std::endl;
  17. return x_;
  18. }
  19. void modify (void) {
  20. std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")->("<< !x_ << ")" << std::endl;
  21. x_=!x_;
  22. }
  23. ~Hoge () {
  24. std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")" << std::endl;
  25. }
  26. friend std::ostream & operator<< (std::ostream & os, Hoge const & h);
  27. private:
  28. bool x_;
  29. };
  30. std::ostream & operator<< (std::ostream & os, Hoge const & h) {
  31. return os << "Hoge{" << h.x_ << "}";
  32. }
  33.  
  34. bool singleJudge(Hoge const & h) {
  35. std::cout << BOOST_CURRENT_FUNCTION << h << std::endl;
  36. return h.judge();
  37. }
  38. void multiProcM(boost::ptr_vector<Hoge, boost::view_clone_allocator>::iterator b,
  39. boost::ptr_vector<Hoge, boost::view_clone_allocator>::iterator e) {
  40. std::cout << BOOST_CURRENT_FUNCTION << std::endl;
  41. singleJudge(*b); // const refを受け取る関数に転送できる
  42. b->judge();
  43. b->modify();
  44. }
  45. void multiProcC(boost::ptr_vector<Hoge, boost::view_clone_allocator>::const_iterator b,
  46. boost::ptr_vector<Hoge, boost::view_clone_allocator>::const_iterator e) {
  47. std::cout << BOOST_CURRENT_FUNCTION << std::endl;
  48. singleJudge(*b);
  49. b->judge();
  50. //b->modify(); // compilation error :)
  51. }
  52.  
  53. struct ptr_cmp {
  54. bool operator() (int const & lhs, int const & rhs) const {
  55. return &lhs < &rhs;
  56. }
  57. };
  58. }
  59.  
  60. int main () {
  61. using namespace boost::assign;
  62. using namespace jefuty;
  63. {
  64. std::vector<int> v = list_of(0)(1)(2)(3)(4)(0);
  65. typedef boost::ptr_vector<
  66. int, boost::view_clone_allocator
  67. > ptrvec;
  68. ptrvec v1(&v[0], &v[5]);
  69. ptrvec v2;
  70. boost::ptr_container::ptr_back_insert_iterator< ptrvec > it(v2);
  71. *it = &v[0];
  72. *it = &v[1];
  73. *it = &v[2];
  74. *it = &v[5];
  75.  
  76. ptrvec::iterator ib(v2.begin());
  77. ptrvec::iterator ie(v2.end());
  78. ptrvec v4;
  79. std::set_difference(v1.begin(), v1.end(), ib, ie, boost::ptr_container::ptr_back_inserter(v4), ptr_cmp());
  80. BOOST_FOREACH(int i, v4) {
  81. std::cout << i << ",";
  82. }
  83. std::cout << std::endl;
  84. }
  85. }
  86.  
  87.  
Success #stdin #stdout 0s 2872KB
stdin
Standard input is empty
stdout
3,4,