test-ra-8.C 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // (c) Daniel Llorens - 2016
  2. // This library is free software; you can redistribute it and/or modify it under
  3. // the terms of the GNU Lesser General Public License as published by the Free
  4. // Software Foundation; either version 3 of the License, or (at your option) any
  5. // later version.
  6. /// @file test-ra-8.C
  7. /// @brief Regression test for lvalue exprs in gcc 6.1
  8. // Failed for Expr:: Ryn:: Vector:: =, += ... on gcc 6.1 due to bug 70942. This
  9. // is kept to show why that forward<decltype(y)>(y) is there.
  10. #include <iostream>
  11. #include <iterator>
  12. #include "ra/mpdebug.H"
  13. #include "ra/complex.H"
  14. #include "ra/format.H"
  15. #include "ra/test.H"
  16. #include "ra/big.H"
  17. #include "ra/operators.H"
  18. #include "ra/io.H"
  19. using std::cout; using std::endl; using std::flush; using std::tuple;
  20. using real = double;
  21. template <int rank=ra::RANK_ANY> using Ureal = ra::Unique<real, rank>;
  22. template <int rank=ra::RANK_ANY> using Uint = ra::Unique<int, rank>;
  23. int main()
  24. {
  25. TestRecorder tr(std::cout);
  26. // tr.section("gcc 6.1 A");
  27. // {
  28. // // Both must be lvalues; TODO test that these fail.
  29. // ra::Unique<int, 1> a { 0, 0, 0, 0 };
  30. // ra::Unique<int, 1> b { 0, 0, 0, 0 };
  31. // where(ra::_0>0 && ra::_0<3, ra::_0, a) = 99;
  32. // where(ra::_0>0 && ra::_0<3, a, ra::_0) = 99;
  33. // }
  34. tr.section("gcc 6.1 B");
  35. {
  36. Ureal<1> a {1, 4, 2, 3};
  37. Ureal<1> b({4}, 0.);
  38. b(3-ra::_0) = a;
  39. tr.test_eq(Ureal<1> {3, 2, 4, 1}, b);
  40. }
  41. tr.section("gcc 6.1 C");
  42. {
  43. Ureal<1> a = {1, 2, 3, 4};
  44. Uint<1> i = {3, 1, 2};
  45. a(i) = ra::Unique<real, 1> {7, 8, 9};
  46. tr.test_eq(a, Ureal<1> {1, 8, 9, 7});
  47. }
  48. tr.section("gcc 6.1 D");
  49. {
  50. ra::Big<int, 2> A({4, 4}, 0), B({4, 4}, 10*ra::_0 + ra::_1);
  51. using coord = ra::Small<int, 2>;
  52. ra::Big<coord, 1> I = { coord{1, 1}, coord{2, 2} };
  53. map([&A](auto && c) -> decltype(auto) { return A.at(c); }, I)
  54. = map([&B](auto && c) { return B.at(c); }, I);
  55. tr.test_eq(Ureal<2>({4, 4}, {0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0}), A);
  56. }
  57. return tr.summary();
  58. }