ra-14.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 0 [ra15]");
  20. {
  21. ra::Big<int2> a({}, {{ 1, 2 }});
  22. int2 c = a;
  23. tr.test_eq(1, c[0]);
  24. tr.test_eq(2, c[1]);
  25. }
  26. tr.section("From var rank 0 through view [ra15]");
  27. {
  28. ra::Big<int2> a({}, {{ 1, 2 }});
  29. tr.test_eq(0, a.rank());
  30. int2 c = a();
  31. tr.test_eq(1, c[0]);
  32. tr.test_eq(2, c[1]);
  33. }
  34. tr.section("From var rank 1 through view [ra15]");
  35. {
  36. ra::Big<int2> a = {int2{ 1, 2 }}; // [ra16] for the need to say int2
  37. tr.test_eq(1, a.rank());
  38. tr.test_eq(1, a.len(0));
  39. int2 c = a(0);
  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. c = { 3, 4 };
  54. tr.test_eq(3, ((int2 &)(a))[0]);
  55. tr.test_eq(4, ((int2 &)(a))[1]);
  56. }
  57. tr.section("From const var rank 0 to ref");
  58. {
  59. ra::Big<int2> const a({}, {{ 1, 2 }});
  60. int2 const & c = a;
  61. tr.test_eq(1, c[0]);
  62. tr.test_eq(2, c[1]);
  63. }
  64. tr.section("From const var rank 0 to ref");
  65. {
  66. static_assert(requires { requires !(std::is_convertible_v<ra::Big<int2> const, int2 &>); });
  67. }
  68. }
  69. return tr.summary();
  70. }