global.H 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // -*- mode: c++; coding: utf-8 -*-
  2. /// @file global.H
  3. /// @brief Had to break namespace hygiene.
  4. // (c) Daniel Llorens - 2016
  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. #pragma once
  10. #include "ra/wedge.H"
  11. #include "ra/atom.H"
  12. // TODO All users be int, then this take int.
  13. // See also using std::abs, etc. in real.H.
  14. using ra::odd, ra::every, ra::any;
  15. // These global versions must be available so that e.g. ra::transpose<> may be searched by ADL even when giving explicit template args. See http://stackoverflow.com/questions/9838862 .
  16. template <class A,
  17. std::enable_if_t<ra::is_scalar<A>, int> =0>
  18. inline constexpr decltype(auto) transpose(A && a) { return std::forward<A>(a); }
  19. // We also define the scalar specializations that couldn't be found through ADL in any case. See complex.H, real.H.
  20. // These seem unnecessary, just as I do ra::concrete() I could do ra::where(). FIXME
  21. template <int cell_rank>
  22. inline constexpr void iter() { abort(); }
  23. // These ra::start are needed b/c rank 0 converts to and from scalar, so ? can't pick the right (-> scalar) conversion.
  24. template <class T, class F,
  25. std::enable_if_t<ra::is_zero_or_scalar<T> && ra::is_zero_or_scalar<F>, int> =0>
  26. inline constexpr decltype(auto) where(bool const w, T && t, F && f)
  27. {
  28. return w ? *(ra::start(t).flat()) : *(ra::start(f).flat());
  29. }
  30. template <int D, int Oa, int Ob, class A, class B,
  31. std::enable_if_t<ra::is_scalar<A> && ra::is_scalar<B>, int> =0>
  32. inline constexpr auto wedge(A const & a, B const & b) { return a*b; }