#include <iostream>
#include <vector>
#include <boost/assign.hpp>
#include <boost/format.hpp>
#include <boost/foreach.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 :)
}
struct ptr_cmp {
bool operator() (int const & lhs, int const & rhs) const {
return &lhs < &rhs;
}
};
}
int main () {
using namespace boost::assign;
using namespace jefuty;
{
std::vector<int> v = list_of(0)(1)(2)(3)(4)(0);
typedef boost::ptr_vector<
int, boost::view_clone_allocator
> ptrvec;
ptrvec v1(&v[0], &v[5]);
ptrvec v2;
boost::ptr_container::ptr_back_insert_iterator< ptrvec > it(v2);
*it = &v[0];
*it = &v[1];
*it = &v[2];
*it = &v[5];
ptrvec::iterator ib(v2.begin());
ptrvec::iterator ie(v2.end());
ptrvec v4;
std::set_difference(v1.begin(), v1.end(), ib, ie, boost::ptr_container::ptr_back_inserter(v4), ptr_cmp());
BOOST_FOREACH(int i, v4) {
std::cout << i << ",";
}
std::cout << std::endl;
}
}