#include <iostream>
#include <vector>
#include <boost/assign.hpp>
#include <boost/format.hpp>
#include <boost/current_function.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/ptr_container/ptr_container.hpp>
namespace jefuty {
struct Hoge {
Hoge () :x_(false)
{ }
bool judge (void) const {
std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")" << std::endl;
return x_;
}
void modify (void) {
std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")->("<< !x_ << ")" << std::endl;
x_=!x_;
}
~Hoge () {
std::cout << BOOST_CURRENT_FUNCTION << "("<< x_ <<")" << std::endl;
}
friend std::ostream & operator<< (std::ostream & os, Hoge const & h);
private:
bool x_;
};
std::ostream & operator<< (std::ostream & os, Hoge const & h) {
return os << "Hoge{" << h.x_ << "}";
}
bool singleJudge(Hoge const & h) {
std::cout << BOOST_CURRENT_FUNCTION << h << std::endl;
return h.judge();
}
void multiProcM(boost::ptr_vector<Hoge, boost::view_clone_allocator>::iterator b,
boost::ptr_vector<Hoge, boost::view_clone_allocator>::iterator e) {
std::cout << BOOST_CURRENT_FUNCTION << std::endl;
singleJudge(*b); // const refを受け取る関数に転送できる
b->judge();
b->modify();
}
void multiProcC(boost::ptr_vector<Hoge, boost::view_clone_allocator>::const_iterator b,
boost::ptr_vector<Hoge, boost::view_clone_allocator>::const_iterator e) {
std::cout << BOOST_CURRENT_FUNCTION << std::endl;
singleJudge(*b);
b->judge();
//b->modify(); // compilation error :)
}
}
int main () {
using namespace boost::assign;
using namespace jefuty;
Hoge h[3];
{
boost::ptr_vector<
Hoge,
boost::view_clone_allocator // 所有権持たない系なので
> xs(&h[0], &h[3]);
multiProcM(xs.begin(), xs.end());
multiProcC(xs.begin(), xs.end());
std::cout << "block end" << std::endl; // ここでdtorは呼ばれない
}
std::cout << "program end" << std::endl;
}