#pragma once #include #include #include #include #include #include #include #include #include #include namespace AMDiS { // forward declaration template class MultiTypeVector; } namespace Dune { template struct FieldTraits> { using field_type = std::common_type_t::field_type...>; using real_type = std::common_type_t::real_type...>; }; } namespace AMDiS { template class MultiTypeVector : public std::tuple { using Self = MultiTypeVector; using Super = std::tuple; public: using field_type = typename Dune::FieldTraits::field_type; using real_type = typename Dune::FieldTraits::real_type; using size_type = std::size_t; static constexpr int dimension = std::tuple_size::value; template , Types> )> MultiTypeVector(FV_&&... fv) : Super(FWD(fv)...) {} /// Default construction of tuple of FieldVectors MultiTypeVector() = default; /// Construct tuple by initializing all tuple elements with a constant value explicit MultiTypeVector(real_type value) { *this = value; } /// Assignment of real number to all tuple elements MultiTypeVector& operator=(real_type value) { Tools::for_each(as_tuple(), [value](auto& fv) { fv = value; }); return *this; } // Compound assignment operator += MultiTypeVector& operator+=(MultiTypeVector const& that) { Tools::for_range<0,dimension>([&that,this](auto const i) { (*this)[i] += that[i]; }); return *this; } // Compound assignment operator -= MultiTypeVector& operator-=(MultiTypeVector const& that) { Tools::for_range<0,dimension>([&that,this](auto const i) { (*this)[i] -= that[i]; }); return *this; } // Scaling of all tuple elements by a constant value MultiTypeVector& operator*=(real_type value) { Tools::for_each(as_tuple(), [value](auto& fv) { fv *= value; }); return *this; } // Scaling of all tuple elements by the inverse of a constant value MultiTypeVector& operator/=(real_type value) { Tools::for_each(as_tuple(), [value](auto& fv) { fv /= value; }); return *this; } /// Const access to the tuple elements template decltype(auto) operator[](index_t const) const { return std::get(as_tuple()); } /// Mutable access to the tuple elements template decltype(auto) operator[](index_t const) { return std::get(as_tuple()); } /// Const access to the vector using multi-indices template )> decltype(auto) operator[](Index const& index) const { return Dune::Functions::hybridMultiIndexAccess(*this, index); } /// Mutable access to the vector using multi-indices template )> decltype(auto) operator[](Index const& index) { return Dune::Functions::hybridMultiIndexAccess(*this, index); } /// Return number of elements of the tuple static constexpr std::size_t size() { return dimension; } private: std::tuple& as_tuple() { return *this; } std::tuple const& as_tuple() const { return *this; } }; } // end namespace AMDiS