1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| #include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <boost/bind.hpp>
#include <boost/utility/typed_in_place_factory.hpp>
struct A
{
int m_1;
int m_2;
A(int P_1=0,int P_2=0):m_1(P_1),m_2(P_2){}
};
class B
{
public:
B(const A&P_a):m_a(P_a)
{}
A m_a;
};
template<class TypedInPlaceFactory>
typename TypedInPlaceFactory::value_type Generer(TypedInPlaceFactory const& aFactory)
{
char L_retour[sizeof(typename TypedInPlaceFactory::value_type)];
aFactory.apply(L_retour);
return *(typename TypedInPlaceFactory::value_type*)&L_retour;
}
std::ostream& operator<<(std::ostream& P_flux, const B&P_b)
{
return P_flux<<"( "<<P_b.m_a.m_1<<" , "<<P_b.m_a.m_2<<" )\n";
}
int main()
{
std::vector<A> L_vectA;
L_vectA.push_back(A(1,1));
L_vectA.push_back(A(2,2));
L_vectA.push_back(A(3,3));
L_vectA.push_back(A(4,4));
A a1;
A a2;
std::vector<B> L_vectB;
std::for_each(
L_vectA.begin(),
L_vectA.end(),
boost::bind(
&std::vector<B>::push_back
,&L_vectB
,boost::bind(
&Generer<boost::typed_in_place_factory1<B,A> >,
boost::bind(static_cast<boost::typed_in_place_factory1<B,A> (*)(A const&)>(&boost::in_place<B,A>),_1)
)
)
);
std::copy(
L_vectB.begin(),
L_vectB.end(),
std::ostream_iterator<B>(std::cout)
);
return std::cin.get();
} |
Partager