Bonjour,
Je souhaite un générateur un peu générique et je n'y arrive pas:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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)
   {}

protected:
   A m_a;
};

template<class T, class InPlaceFactory>
T Generer(InPlaceFactory const& aFactory)
{
   char L_retour[sizeof(T)];
   aFactory.template apply<T>(L_retour);
   return *(T*)&L_retour;
}

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));
   
   std::vector<B> L_vectB;
// en rouge ce qui ne compile pas:
   std::for_each(
      L_vectA.begin(),
      L_vectA.end(),
      std::for_each(
            L_vectA.begin(),
            L_vectA.end(),
            boost::bind(
               &std::vector<B>::push_back,
               &L_vectB,
               boost::bind(&Generer<B>,boost::bind(&boost::in_place,_1))
           )
         );
     )
   );
}
Si quelque a une piste, je suis preneur.
Merci.