fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct foo_t {
  5. foo_t() = delete;
  6. foo_t(const foo_t&) = delete;
  7. foo_t(int, float, const std::string& /*... whatever*/) {}
  8. };
  9.  
  10. struct C {
  11. C(double, char /*... whatever constructor arguments*/)
  12. : foo(nullptr) {
  13. // lenghty computations allowing to define a, b and c
  14. int a = 0 /* ? */;
  15. float b = 0 /* ? */;
  16. std::string s /* ? */;
  17. foo.reset(new foo_t(a,b,s));
  18. // remaining computations...
  19. }
  20.  
  21. std::unique_ptr<foo_t> foo;
  22. };
  23.  
  24. // translate that into ->
  25.  
  26. std::tuple<int, float, std::string> precompute(double, char) {
  27. // lenghty computations allowing to define a, b and c
  28. int a = 0 /* ? */;
  29. float b = 0 /* ? */;
  30. std::string s /* ? */;
  31. return {a, b, std::move(s)};
  32. }
  33.  
  34. struct C2 {
  35. C2(double d, char c /*... whatever constructor arguments*/)
  36. : C2(d, c, precompute(d, c)) {}
  37.  
  38. C2(double, char, std::tuple<int, float, std::string>&& tpl)
  39. : foo(std::get<0>(tpl), std::get<1>(tpl), std::get<2>(tpl)) {
  40. // remaining computations...
  41. }
  42.  
  43. foo_t foo;
  44. };
  45.  
  46.  
  47. int main() {
  48. // your code goes here
  49. return 0;
  50. }
Success #stdin #stdout 0s 4524KB
stdin
Standard input is empty
stdout
Standard output is empty