ra-14.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Conversion to scalar from Big/View, corner cases.
  3. // (c) Daniel Llorens - 2023
  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 <numeric>
  9. #include <iostream>
  10. #include <iterator>
  11. #include "ra/test.hh"
  12. using std::cout, std::endl, std::flush, ra::TestRecorder;
  13. int main()
  14. {
  15. TestRecorder tr(std::cout);
  16. using int2 = ra::Small<int, 2>;
  17. tr.section("Values");
  18. {
  19. tr.section("From var rank 1 through view [ra15]");
  20. {
  21. ra::Big<int2> a = {int2{ 1, 2 }}; // [ra16] for the need to say int2
  22. tr.test_eq(1, a.rank());
  23. tr.test_eq(1, a.len(0));
  24. int2 c = a(0);
  25. tr.test_eq(1, c[0]);
  26. tr.test_eq(2, c[1]);
  27. }
  28. tr.section("From var rank 0 through view [ra15]");
  29. {
  30. ra::Big<int2> a({}, {{ 1, 2 }});
  31. tr.test_eq(0, a.rank());
  32. int2 c = a();
  33. tr.test_eq(1, c[0]);
  34. tr.test_eq(2, c[1]);
  35. }
  36. tr.section("From var rank 0 [ra15]");
  37. {
  38. ra::Big<int2> a({}, {{ 1, 2 }});
  39. int2 c = a;
  40. tr.test_eq(1, c[0]);
  41. tr.test_eq(2, c[1]);
  42. }
  43. }
  44. // see also test/const.cc.
  45. tr.section("References");
  46. {
  47. tr.section("From var rank 0 to ref");
  48. {
  49. ra::Big<int2> a({}, {{ 1, 2 }});
  50. int2 & c = a;
  51. tr.test_eq(1, c[0]);
  52. tr.test_eq(2, c[1]);
  53. }
  54. tr.section("From const var rank 0 to ref");
  55. {
  56. ra::Big<int2> const a({}, {{ 1, 2 }});
  57. int2 const & c = a;
  58. tr.test_eq(1, c[0]);
  59. tr.test_eq(2, c[1]);
  60. }
  61. tr.section("From const var rank 0 to ref");
  62. {
  63. static_assert(requires { requires !(std::is_convertible_v<ra::Big<int2> const, int2 &>); });
  64. }
  65. }
  66. return tr.summary();
  67. }