dune-common  2.7.0
io.hh
Go to the documentation of this file.
1 #ifndef DUNE_COMMON_SIMD_IO_HH
2 #define DUNE_COMMON_SIMD_IO_HH
3 
14 #include <ios>
15 #include <type_traits>
16 
18 #include <dune/common/simd/simd.hh>
20 
21 namespace Dune {
22 
23  namespace SimdImpl {
24 
25  template<class T>
26  class Inserter {
27  T value_;
28 
29  public:
30  Inserter(const T &value) : value_(value) {}
31 
32  template<class Stream,
33  class = std::enable_if_t<std::is_base_of<std::ios_base,
34  Stream>::value> >
35  friend Stream& operator<<(Stream &out, const Inserter &ins)
36  {
37  const char *sep = "<";
38  for(auto l : range(Simd::lanes(ins.value_)))
39  {
40  out << sep << autoCopy(Simd::lane(l, ins.value_));
41  sep = ", ";
42  }
43  out << '>';
44  return out;
45  }
46  };
47 
48  template<class V, class = std::enable_if_t<Simd::lanes<V>() != 1> >
49  Inserter<V> io(const V &v)
50  {
51  return { v };
52  }
53 
54  template<class V, class = std::enable_if_t<Simd::lanes<V>() == 1> >
55  Simd::Scalar<V> io(const V &v)
56  {
57  return Simd::lane(0, v);
58  }
59 
60  }
61 
62  namespace Simd {
63 
79 
87  template<class V>
88  auto vio(const V &v)
89  {
90  return SimdImpl::Inserter<V>{ v };
91  }
92 
94 
103  template<class V>
104  auto io(const V &v)
105  {
106  return SimdImpl::io(v);
107  }
108 
110 
112 
113  } // namespace Simd
114 } // namespace Dune
115 
116 #endif // DUNE_COMMON_SIMD_IO_HH
Dune::Simd::lanes
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition: simd/interface.hh:303
simd.hh
Include file for users of the SIMD abstraction layer.
Dune::SimdImpl::Inserter::Inserter
Inserter(const T &value)
Definition: io.hh:30
Dune::range
static StaticIntegralRange< T, to, from > range(std::integral_constant< T, from >, std::integral_constant< T, to >) noexcept
Definition: rangeutilities.hh:297
typetraits.hh
Traits for type conversions and type information.
Dune::autoCopy
constexpr AutonomousValue< T > autoCopy(T &&v)
Autonomous copy of an expression's value for use in auto type deduction.
Definition: typetraits.hh:723
Dune::Simd::lane
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition: simd/interface.hh:322
Dune::SimdImpl::Inserter
Definition: io.hh:26
Dune::SimdImpl::Inserter::operator<<
friend Stream & operator<<(Stream &out, const Inserter &ins)
Definition: io.hh:35
rangeutilities.hh
Utilities for reduction like operations on ranges.
Dune
Dune namespace.
Definition: alignedallocator.hh:13