const.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Const transfer from Container to View
  3. // (c) Daniel Llorens - 2021-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 <iostream>
  9. #include <iterator>
  10. #include "mpdebug.hh"
  11. #include "ra/test.hh"
  12. #include "ra/complex.hh"
  13. using std::cout, std::endl, std::flush, std::tuple, ra::TestRecorder;
  14. template <class T> constexpr bool is_cref_v = std::is_reference_v<T> && std::is_const_v<std::remove_reference_t<T>>;
  15. template <class T> constexpr bool is_ncref_v = std::is_reference_v<T> && !std::is_const_v<std::remove_reference_t<T>>;
  16. int main()
  17. {
  18. TestRecorder tr(std::cout);
  19. auto test =
  20. [&](auto & a, auto & b)
  21. {
  22. tr.test(is_ncref_v<decltype(*(a.data()))>);
  23. tr.test(is_cref_v<decltype(*(b.data()))>);
  24. tr.test(is_ncref_v<decltype(*(a().data()))>);
  25. tr.test(is_cref_v<decltype(*(b().data()))>);
  26. tr.test(is_ncref_v<decltype(*(a(ra::all).data()))>);
  27. tr.test(is_cref_v<decltype(*(b(ra::all).data()))>);
  28. };
  29. tr.section("dynamic rank");
  30. {
  31. ra::Big<int> a = {1, 2, 3, 4};
  32. ra::Big<int> const b = {9, 8, 7, 6};
  33. test(a, b);
  34. }
  35. tr.section("static rank");
  36. {
  37. ra::Big<int, 1> a = {1, 2, 3, 4};
  38. ra::Big<int, 1> const b = {9, 8, 7, 6};
  39. test(a, b);
  40. }
  41. tr.section("static dimensions");
  42. {
  43. ra::Small<int, 4> a = {1, 2, 3, 4};
  44. ra::Small<int, 4> const b = {9, 8, 7, 6};
  45. test(a, b);
  46. }
  47. return tr.summary();
  48. }