fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. #include <boost/assign.hpp>
  5. #include <boost/format.hpp>
  6. #include <boost/current_function.hpp>
  7. #include <boost/ptr_container/ptr_vector.hpp>
  8. #include <boost/ptr_container/ptr_container.hpp>
  9.  
  10. namespace jefuty {
  11. struct Hoge {
  12. Hoge () :x_(false)
  13. { }
  14. bool judge (void) const {
  15. std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")" << std::endl;
  16. return x_;
  17. }
  18. void modify (void) {
  19. std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")->("<< !x_ << ")" << std::endl;
  20. x_=!x_;
  21. }
  22. ~Hoge () {
  23. std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")" << std::endl;
  24. }
  25. friend std::ostream & operator<< (std::ostream & os, Hoge const & h);
  26. private:
  27. bool x_;
  28. };
  29. std::ostream & operator<< (std::ostream & os, Hoge const & h) {
  30. return os << "Hoge{" << h.x_ << "}";
  31. }
  32.  
  33. bool singleJudge(Hoge const & h) {
  34. std::cout << BOOST_CURRENT_FUNCTION << h << std::endl;
  35. return h.judge();
  36. }
  37. void multiProcM(boost::ptr_vector<Hoge, boost::view_clone_allocator>::iterator b,
  38. boost::ptr_vector<Hoge, boost::view_clone_allocator>::iterator e) {
  39. std::cout << BOOST_CURRENT_FUNCTION << std::endl;
  40. singleJudge(*b); // const refを受け取る関数に転送できる
  41. b->judge();
  42. b->modify();
  43. }
  44. void multiProcC(boost::ptr_vector<Hoge, boost::view_clone_allocator>::const_iterator b,
  45. boost::ptr_vector<Hoge, boost::view_clone_allocator>::const_iterator e) {
  46. std::cout << BOOST_CURRENT_FUNCTION << std::endl;
  47. singleJudge(*b);
  48. b->judge();
  49. //b->modify(); // compilation error :)
  50. }
  51. }
  52.  
  53. int main () {
  54. using namespace boost::assign;
  55. using namespace jefuty;
  56. Hoge h[3];
  57. {
  58. boost::ptr_vector<
  59. Hoge,
  60. boost::view_clone_allocator // 所有権持たない系なので
  61. > xs(&h[0], &h[3]);
  62. multiProcM(xs.begin(), xs.end());
  63. multiProcC(xs.begin(), xs.end());
  64. std::cout << "block end" << std::endl; // ここでdtorは呼ばれない
  65. }
  66. std::cout << "program end" << std::endl;
  67. }
  68.  
Success #stdin #stdout 0s 2864KB
stdin
Standard input is empty
stdout
void jefuty::multiProcM(boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, jefuty::Hoge>, boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, jefuty::Hoge>)
bool jefuty::singleJudge(const jefuty::Hoge&)Hoge{0}
bool jefuty::Hoge::judge() const(0)
bool jefuty::Hoge::judge() const(0)
void jefuty::Hoge::modify()(0)->(1)
void jefuty::multiProcC(boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void* const*, std::vector<void*, std::allocator<void*> > >, const jefuty::Hoge>, boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void* const*, std::vector<void*, std::allocator<void*> > >, const jefuty::Hoge>)
bool jefuty::singleJudge(const jefuty::Hoge&)Hoge{1}
bool jefuty::Hoge::judge() const(1)
bool jefuty::Hoge::judge() const(1)
block end
program end
jefuty::Hoge::~Hoge()(0)
jefuty::Hoge::~Hoge()(0)
jefuty::Hoge::~Hoge()(1)