pitfall.cc 754 B

1234567891011121314151617181920212223242526
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/examples - Pitfalls of assigning to lower rank
  3. // (c) Daniel Llorens - 2021
  4. // This library is free software; you can redistribute it and/or modify it under
  5. // the terms of the GNU Lesser General Public License as published by the Free
  6. // Software Foundation; either version 3 of the License, or (at your option) any
  7. // later version.
  8. #include "ra/ra.hh"
  9. #include <iostream>
  10. using std::cout, std::endl, std::flush;
  11. int main()
  12. {
  13. // Matching flat array to nested array
  14. {
  15. ra::Small<double, 3, 2> a = {{1, 2}, {3, 4}, {5, 6}};
  16. // b(i) = a(i, ∀ j), which in practice is b(i) = a(i, 1)
  17. ra::Small<ra::Small<double, 2>, 3> b = a;
  18. // 2 2 4 4 6 6 (probably)
  19. cout << b << endl;
  20. }
  21. }