Guest User

Untitled

a guest
Apr 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A {
  5. A() {
  6. printf("A() calledn");
  7. }
  8.  
  9. A(int i, int j) {
  10. printf("A(%d, %d) calledn", i, j);
  11. }
  12. };
  13.  
  14. struct B {
  15. A tab[100];
  16.  
  17. B(int i, int j) {
  18. // I would like to call A(i, j) for each tab entries instead of the default constructor
  19. printf("B(%d, %d) calledn", i, j);
  20. }
  21. };
  22.  
  23. int main() {
  24. B b(1, 7);
  25. return 0;
  26. }
  27.  
  28. struct B {
  29. A tab[100];
  30.  
  31. template<size_t... Is>
  32. B(int i, int j, std::index_sequence<Is...>) : tab{ {(void(Is), i), j }... } {}
  33.  
  34. B(int i, int j) : B(i, j, std::make_index_sequence<100>()) {}
  35. };
Add Comment
Please, Sign In to add comment