const.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // -*- mode: c++; coding: utf-8 -*-
  2. /// @file const.cc
  3. /// @brief Const transfer from Container to View
  4. // (c) Daniel Llorens - 2021
  5. // This library is free software; you can redistribute it and/or modify it under
  6. // the terms of the GNU Lesser General Public License as published by the Free
  7. // Software Foundation; either version 3 of the License, or (at your option) any
  8. // later version.
  9. #include <iostream>
  10. #include <iterator>
  11. #include "ra/mpdebug.hh"
  12. #include "ra/complex.hh"
  13. #include "ra/test.hh"
  14. #include "ra/ra.hh"
  15. using std::cout, std::endl, std::flush, std::tuple, ra::TestRecorder;
  16. template <class T> struct is_constref;
  17. template <class T> struct is_constref<T const &> : std::true_type {};
  18. template <class T> struct is_constref<T &> : std::false_type {};
  19. template <class T> constexpr bool is_constref_v = is_constref<T>::value;
  20. int main()
  21. {
  22. TestRecorder tr(std::cout);
  23. auto test =
  24. [&](auto & a, auto & b)
  25. {
  26. tr.test(!is_constref_v<decltype(*(a.data()))>);
  27. tr.skip().test(is_constref_v<decltype(*(b.data()))>); // FIXME [ra47]
  28. tr.test(!is_constref_v<decltype(*(a().data()))>);
  29. tr.test(is_constref_v<decltype(*(b().data()))>);
  30. tr.test(!is_constref_v<decltype(*(a(ra::all).data()))>);
  31. tr.test(is_constref_v<decltype(*(b(ra::all).data()))>);
  32. };
  33. {
  34. ra::Big<int> a = {1, 2, 3, 4};
  35. ra::Big<int> const b = {9, 8, 7, 6};
  36. test(a, b);
  37. }
  38. {
  39. ra::Big<int, 1> a = {1, 2, 3, 4};
  40. ra::Big<int, 1> const b = {9, 8, 7, 6};
  41. test(a, b);
  42. }
  43. return tr.summary();
  44. }