removed some headers from amdis and moved them to independent repository dune-blocked
#pragma once | ||
#include <tuple> | ||
#include <type_traits> | ||
#include <dune/common/ftraits.hh> | ||
#include <dune/functions/common/indexaccess.hh> | ||
#include <amdis/common/Concepts.hpp> | ||
#include <amdis/common/ForEach.hpp> | ||
#include <amdis/common/Index.hpp> | ||
#include <amdis/common/Range.hpp> | ||
#include <amdis/common/StaticSize.hpp> | ||
#include <amdis/common/TypeTraits.hpp> | ||
namespace AMDiS | ||
{ | ||
// forward declaration | ||
template <class... FV> | ||
class MultiTypeVector; | ||
} | ||
namespace Dune | ||
{ | ||
template <class... FV> | ||
struct FieldTraits<AMDiS::MultiTypeVector<FV...>> | ||
{ | ||
using field_type = std::common_type_t<typename Dune::FieldTraits<FV>::field_type...>; | ||
using real_type = std::common_type_t<typename Dune::FieldTraits<FV>::real_type...>; | ||
}; | ||
} | ||
namespace AMDiS | ||
{ | ||
template <class... FV> | ||
class MultiTypeVector | ||
: public std::tuple<FV...> | ||
{ | ||
using Self = MultiTypeVector; | ||
using Super = std::tuple<FV...>; | ||
public: | ||
using field_type = typename Dune::FieldTraits<Self>::field_type; | ||
using real_type = typename Dune::FieldTraits<Self>::real_type; | ||
using size_type = std::size_t; | ||
static constexpr int dimension = std::tuple_size<Super>::value; | ||
template <class... FV_, | ||
REQUIRES( Concepts::Similar<Types<FV...>, Types<FV_...>> )> | ||
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 <std::size_t I> | ||
decltype(auto) operator[](index_t<I> const) const | ||
{ | ||
return std::get<I>(as_tuple()); | ||
} | ||
/// Mutable access to the tuple elements | ||
template <std::size_t I> | ||
< |