const.cc 1.7 KB

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