global.H 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // (c) Daniel Llorens - 2016
  2. // This library is free software; you can redistribute it and/or modify it under
  3. // the terms of the GNU Lesser General Public License as published by the Free
  4. // Software Foundation; either version 3 of the License, or (at your option) any
  5. // later version.
  6. /// @file global.H
  7. /// @brief Had to break namespace hygiene.
  8. #pragma once
  9. #include "ra/iterator.H"
  10. #include "ra/wedge.H"
  11. #define START(a) *(ra::start(a).flat())
  12. // This global versions must be available so that ra::transpose<> may be searched by ADL even when giving explicit template args. See http://stackoverflow.com/questions/9838862 .
  13. template <class A,
  14. std::enable_if_t<ra::is_scalar<A>, int> =0>
  15. inline constexpr decltype(auto) transpose(A && a) { return std::forward<A>(a); }
  16. // We also define the scalar specializations that couldn't be found through ADL in any case. See complex.H, real.H.
  17. // In all honesty these seem unnecessary, just as I do ra::concrete() I could do ra::where(). FIXME
  18. template <int cell_rank>
  19. inline constexpr void iter() { abort(); }
  20. // These ra::start are needed b/c rank 0 converts to and from scalar, so ? can't pick the right (-> scalar) conversion.
  21. template <class T, class F,
  22. std::enable_if_t<ra::is_zero_or_scalar<T> && ra::is_zero_or_scalar<F>, int> =0>
  23. inline constexpr decltype(auto) where(bool const w, T && t, F && f) { return w ? START(t) : START(f); }
  24. template <int D, int Oa, int Ob, class A, class B,
  25. std::enable_if_t<ra::is_scalar<A> && ra::is_scalar<B>, int> =0>
  26. inline constexpr auto wedge(A const & a, B const & b) { return a*b; }
  27. #undef START