From a1d748cb1404f0b8b1aab7804d407713d356cc9b Mon Sep 17 00:00:00 2001 From: Simon Praetorius <simon.praetorius@tu-dresden.de> Date: Fri, 1 Mar 2019 11:03:37 +0100 Subject: [PATCH] rebase to develop branch --- src/amdis/common/Apply.hpp | 15 ++-- src/amdis/common/ClonablePtr.hpp | 127 -------------------------- src/amdis/common/Concepts.hpp | 4 +- src/amdis/common/ConcurrentCache.hpp | 7 +- src/amdis/common/FieldMatVec.hpp | 2 +- src/amdis/common/FieldMatVec.inc.hpp | 2 +- src/amdis/common/FieldTraits.hpp | 16 ---- src/amdis/common/ScalarTypes.hpp | 41 --------- src/amdis/common/TypeTraits.hpp | 2 +- src/amdis/common/Utility.hpp | 130 --------------------------- src/amdis/typetree/TreeContainer.hpp | 5 +- 11 files changed, 17 insertions(+), 334 deletions(-) delete mode 100644 src/amdis/common/ClonablePtr.hpp delete mode 100644 src/amdis/common/FieldTraits.hpp delete mode 100644 src/amdis/common/ScalarTypes.hpp delete mode 100644 src/amdis/common/Utility.hpp diff --git a/src/amdis/common/Apply.hpp b/src/amdis/common/Apply.hpp index 05bab973..7cade134 100644 --- a/src/amdis/common/Apply.hpp +++ b/src/amdis/common/Apply.hpp @@ -5,6 +5,7 @@ #include <utility> #include <amdis/common/Mpl.hpp> +#include <amdis/common/TypeTraits.hpp> namespace AMDiS { @@ -15,7 +16,7 @@ namespace AMDiS template <class F, class Tuple, std::size_t... I> constexpr decltype(auto) apply_impl(F&& f, Tuple&& t, std::index_sequence<I...>) { - return f(std::get<I>(std::forward<Tuple>(t))...); + return f(std::get<I>(FWD(t))...); } template <class F, std::size_t I0, std::size_t... I> @@ -28,31 +29,27 @@ namespace AMDiS template <class F, class Tuple> constexpr decltype(auto) apply(F&& f, Tuple&& t) { - return Impl_::apply_impl( - std::forward<F>(f), std::forward<Tuple>(t), + return Impl_::apply_impl(FWD(f), FWD(t), std::make_index_sequence<std::tuple_size<std::remove_reference_t<Tuple>>::value>{}); } template <class F, class... Args> constexpr decltype(auto) apply_variadic(F&& f, Args&&... args) { - return apply(std::forward<F>(f), std::forward_as_tuple(args...)); + return apply(FWD(f), std::forward_as_tuple(args...)); } template <class F, std::size_t N> constexpr decltype(auto) apply_indices(F&& f, index_t<N>) { - return Impl_::apply_indices_impl( - std::forward<F>(f), - index_t<0>{}, + return Impl_::apply_indices_impl(FWD(f), index_t<0>{}, std::make_index_sequence<N>{}); } template <class F, std::size_t I0, std::size_t I1> constexpr decltype(auto) apply_indices(F&& f, index_t<I0>, index_t<I1>) { - return Impl_::apply_indices_impl( - std::forward<F>(f), index_t<I0>{}, + return Impl_::apply_indices_impl(FWD(f), index_t<I0>{}, std::make_index_sequence<I1-I0>{}); } } diff --git a/src/amdis/common/ClonablePtr.hpp b/src/amdis/common/ClonablePtr.hpp deleted file mode 100644 index 23821f1c..00000000 --- a/src/amdis/common/ClonablePtr.hpp +++ /dev/null @@ -1,127 +0,0 @@ -#pragma once - -#include <memory> -#include <utility> - -#include <amdis/common/Utility.hpp> - -namespace AMDiS -{ - // A pointer class that deletes only when owning the pointer - template <class T> - class ClonablePtr - { - private: - struct alloc_tag {}; ///< hidden helper struct, used by \ref make - - public: - using Self = ClonablePtr; - using element_type = T; - - /// Default constructor, creates a non-owned nullptr - ClonablePtr() = default; - - /// Constructor from pointer. Can only be used via make method, - /// Transfers ownership. - ClonablePtr(owner<T>* p, alloc_tag) noexcept - : p(p) - , is_owner(true) - {} - - /// Constructor from reference - explicit ClonablePtr(T& ref) noexcept - : p(&ref) - , is_owner(false) - {} - - /// Constructor from std::unique_ptr - explicit ClonablePtr(std::unique_ptr<T>& ptr) - : p(ptr.release()) - , is_owner(true) - {} - - explicit ClonablePtr(std::unique_ptr<T>&& ptr) - : p(ptr.release()) - , is_owner(true) - {} - - /// Destructor, deletes in case of owner only - ~ClonablePtr() noexcept - { - if (is_owner) - delete p; - } - - /// Copy constructor, creates a clone of the pointed to object - ClonablePtr(Self const& that) noexcept( std::is_nothrow_copy_constructible<T>::value ) - : p(new T(*that.p)) - , is_owner(true) - {} - - /// Move constructor, copies the pointer only. - ClonablePtr(Self&& that) noexcept - : p(that.p) - , is_owner(that.is_owner) - { - that.p = nullptr; - that.is_owner = false; - } - - /// Copy and move assignment operator, using the copy-and-swap idiom - Self& operator=(Self that) noexcept - { - swap(that); - return *this; - } - - /// Factory method. creates a new Object of type T and stores the pointer. - template <class... Args> - static Self make(Args&&... args) - noexcept( std::is_nothrow_constructible<T, remove_cvref_t<Args>...>::value ) - { - return {new T(FWD(args)...), Self::alloc_tag()}; - } - - /// Access-method by dereferencing - T& operator*() const noexcept - { - return *p; - } - - /// Access-method by pointer access - T* operator->() const noexcept - { - return p; - } - - /// retrieve the underlying pointer - T* get() const noexcept - { - return p; - } - - /// Test whether pointer is NULL - operator bool() const noexcept - { - return !(p == NULL); - } - - void swap(Self& that) noexcept - { - using std::swap; - swap(p, that.p); - swap(is_owner, that.is_owner); - } - - private: - T* p = nullptr; ///< managed pointer - bool is_owner = false; ///< true, if class is owner of pointer, false otherwise - }; - - template <class T> - void swap(ClonablePtr<T>& a, ClonablePtr<T>& b) noexcept - { - a.swap(b); - } - -} // end namespace AMDiS diff --git a/src/amdis/common/Concepts.hpp b/src/amdis/common/Concepts.hpp index 6131f1cf..d17060df 100644 --- a/src/amdis/common/Concepts.hpp +++ b/src/amdis/common/Concepts.hpp @@ -20,7 +20,7 @@ namespace AMDiS { template <class A, class B> struct IsSimilar - : std::is_same<std::decay_t<A>, std::decay_t<B>> {}; + : std::is_same<remove_cvref_t<A>, remove_cvref_t<B>> {}; template <class A, class B> struct IsSimilar<Types<A>, Types<B>> @@ -52,7 +52,7 @@ namespace AMDiS struct Callable { template <class F, class... Args> - auto requires_(F&& f, Args&&... args) -> decltype( f(FWD(args)...)); + auto requires_(F&& f, Args&&... args) -> decltype(f(FWD(args)...)); }; // idx[0] diff --git a/src/amdis/common/ConcurrentCache.hpp b/src/amdis/common/ConcurrentCache.hpp index 3f820916..eb28a417 100644 --- a/src/amdis/common/ConcurrentCache.hpp +++ b/src/amdis/common/ConcurrentCache.hpp @@ -78,8 +78,7 @@ namespace AMDiS template <class F, class... Args> data_type const& get_or_init(key_type const& key, F&& f, Args&&... args) const { - return impl(std::is_default_constructible<data_type>{}, - key, std::forward<F>(f), std::forward<Args>(args)...); + return impl(std::is_default_constructible<data_type>{}, key, FWD(f), FWD(args)...); } private: @@ -90,7 +89,7 @@ namespace AMDiS data_type empty; auto it = cachedData_.emplace(key, std::move(empty)); if (it.second) { - data_type data = f(key, std::forward<Args>(args)...); + data_type data = f(key, FWD(args)...); it.first->second = std::move(data); } return it.first->second; @@ -104,7 +103,7 @@ namespace AMDiS if (it != cachedData_.end()) return it->second; else { - data_type data = f(key, std::forward<Args>(args)...); + data_type data = f(key, FWD(args)...); auto it = cachedData_.emplace(key, std::move(data)); return it.first->second; } diff --git a/src/amdis/common/FieldMatVec.hpp b/src/amdis/common/FieldMatVec.hpp index 165e98d6..7f2c226d 100644 --- a/src/amdis/common/FieldMatVec.hpp +++ b/src/amdis/common/FieldMatVec.hpp @@ -82,7 +82,7 @@ namespace Dune template <class T> decltype(auto) simplify(T&& t) { - return std::forward<T>(t); + return FWD(t); } template <class T> diff --git a/src/amdis/common/FieldMatVec.inc.hpp b/src/amdis/common/FieldMatVec.inc.hpp index 40d8dbe6..4644778c 100644 --- a/src/amdis/common/FieldMatVec.inc.hpp +++ b/src/amdis/common/FieldMatVec.inc.hpp @@ -305,7 +305,7 @@ T distance(FieldVector<T, N> const& lhs, FieldVector<T, N> const& rhs) template <class T, class S, int N, int M, int K> auto outer(FieldMatrix<T,N,K> const& vec1, FieldMatrix<S,M,K> const& vec2) { - using result_type = FieldMatrix<decltype( std::declval<T>() * std::declval<S>() ), N, M>; + using result_type = FieldMatrix<TYPEOF( std::declval<T>() * std::declval<S>() ), N, M>; result_type mat; for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) diff --git a/src/amdis/common/FieldTraits.hpp b/src/amdis/common/FieldTraits.hpp deleted file mode 100644 index b4560e0b..00000000 --- a/src/amdis/common/FieldTraits.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include <dune/common/ftraits.hh> - -#include <amdis/common/Utility.hpp> - -namespace AMDiS -{ - template <class... T> - struct CommonFieldTraits - { - using field_type = std::common_type_t<typename Dune::FieldTraits<T>::field_type...>; - using real_type = std::common_type_t<typename Dune::FieldTraits<T>::real_type...>; - }; - -} // end namespace AMDiS diff --git a/src/amdis/common/ScalarTypes.hpp b/src/amdis/common/ScalarTypes.hpp deleted file mode 100644 index 6a3ed614..00000000 --- a/src/amdis/common/ScalarTypes.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -// std c++ headers -#include <type_traits> -#include <amdis/common/Utility.hpp> - -namespace AMDiS -{ - namespace Traits - { - template <class T> - struct IsIntegral - : public std::is_integral<remove_cvref_t<T>> {}; - - template <class T> - struct IsArithmetic - : public std::is_arithmetic<remove_cvref_t<T>> {}; - - } // end namespace traits - - namespace Concepts - { - /** \addtogroup Concepts - * @{ - **/ - - /// \brief The types following the std type-trait \ref std::is_integral are - /// categorized as *integral types*. - template <class T> - constexpr bool Integral = Traits::IsIntegral<T>::value; - - /// \brief The types following the std type-trait \ref std::is_arithmetic are - /// categorized as *arithmetic types*. - template <class T> - constexpr bool Arithmetic = Traits::IsArithmetic<T>::value; - - /** @} **/ - - } // end namespace Concepts - -} // end namespace AMDiS diff --git a/src/amdis/common/TypeTraits.hpp b/src/amdis/common/TypeTraits.hpp index 315b6cc2..20558d35 100644 --- a/src/amdis/common/TypeTraits.hpp +++ b/src/amdis/common/TypeTraits.hpp @@ -59,7 +59,7 @@ namespace AMDiS template <class Obj> auto makeUniquePtr(Obj&& obj) { - return std::make_unique<std::decay_t<Obj>>(std::forward<Obj>(obj)); + return std::make_unique<remove_cvref_t<Obj>>(FWD(obj)); } } // end namespace AMDiS diff --git a/src/amdis/common/Utility.hpp b/src/amdis/common/Utility.hpp deleted file mode 100644 index 49fc8203..00000000 --- a/src/amdis/common/Utility.hpp +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once - -#include <memory> -#include <type_traits> -#include <vector> - -#if AMDIS_HAS_CXX_CONSTEXPR_IF -#define IF_CONSTEXPR if constexpr -#else -#define IF_CONSTEXPR if -#endif - -namespace AMDiS -{ - /// \brief Remove cv and ref qualifiers of type T. - /** - * If the type T is a reference type, provides the member typedef type which - * is the type referred to by T with its topmost cv-qualifiers removed. - * Otherwise type is T with its topmost cv-qualifiers removed. - * - * Note: This is a backport of c++20 std::remove_cvref - **/ - template< class T > - struct remove_cvref - { - using type = std::remove_cv_t<std::remove_reference_t<T>>; - }; - - /// Helper alias template for \ref remove_cvref - template< class T > - using remove_cvref_t = typename remove_cvref<T>::type; - - - namespace Impl - { - template <class T> - struct UnderlyingType - { - using type = remove_cvref_t<T>; - }; - - template <class T> - struct UnderlyingType<std::reference_wrapper<T>> - { - using type = std::remove_cv_t<T>; - }; - } - - /// \brief strip reference_wrapper, const, volatile, and references from type T - template <class T> - using Underlying_t = typename Impl::UnderlyingType<T>::type; - - - /// Macro for forwarding universal references to obj - #define FWD(obj) std::forward<decltype(obj)>(obj) - - /// A decay version of decltype, similar to GCCs __typeof__ - #define TYPEOF(...) remove_cvref_t<decltype(__VA_ARGS__)> - - /// Extract the static value of an integral_constant variable - #define VALUE(...) TYPEOF(__VA_ARGS__)::value - - /// Create a unique_ptr by copy/move construction - template <class Obj> - auto makeUniquePtr(Obj&& obj) - { - return std::make_unique<TYPEOF(obj)>(FWD(obj)); - } - - // --------------------------------------------------------------------------- - - // base template for tuple size, must implement a static value member - template <class TupleType> - struct TupleSize; - - // utility constant returning the value of the tuple size - template <class TupleType> - constexpr std::size_t TupleSize_v = TupleSize<TupleType>::value; - - - // base template for retrieving the tuple element type, must implement the type member `type` - template <size_t I, class TupleType> - struct TupleElement; - - // base template for retrieving the tuple element type - template <size_t I, class TupleType> - using TupleElement_t = typename TupleElement<I, TupleType>::type; - - - /// A variadic type list - template <class... Ts> - struct Types {}; - - template <class... Ts> - using Types_t = Types<remove_cvref_t<Ts>...>; - - - template <class... T> - struct TupleSize<Types<T...>> - : std::integral_constant<std::size_t, sizeof...(T)> {}; - - template <size_t I, class Head, class... Tail> - struct TupleElement<I, Types<Head, Tail...>> - { - using type = typename TupleElement<I-1, Types<Tail...>>::type; - }; - - template <class Head, class... Tail> - struct TupleElement<0, Types<Head, Tail...>> - { - using type = Head; - }; - - - /// Alias that indicates ownership of resources - template <class T> - using owner = T; - - - // --------------------------------------------------------------------------- - - - /// generalization of get<tuple>, get<array> for vectors - template <std::size_t I, class T, class A> - T const& get(std::vector<T,A> const& vec) - { - return vec[I]; - } - -} // end namespace AMDiS diff --git a/src/amdis/typetree/TreeContainer.hpp b/src/amdis/typetree/TreeContainer.hpp index cd013a67..4bad3c79 100644 --- a/src/amdis/typetree/TreeContainer.hpp +++ b/src/amdis/typetree/TreeContainer.hpp @@ -11,6 +11,7 @@ #include <dune/typetree/treepath.hh> #include <amdis/common/Apply.hpp> +#include <amdis/common/TypeTraits.hpp> // NOTE: backport of dune/typetree/treecontainer.hh @@ -135,7 +136,7 @@ namespace AMDiS template<class Container> auto makeTreeContainerVectorBackend(Container&& container) { - return TreeContainerVectorBackend<std::decay_t<Container>>(std::forward<Container>(container)); + return TreeContainerVectorBackend<remove_cvref_t<Container>>(FWD(container)); } } // end namespace Impl @@ -192,7 +193,7 @@ namespace AMDiS * \brief Alias to container type generated by makeTreeContainer for given value and tree type */ template<class Value, class Tree> - using TreeContainer = std::decay_t<decltype(makeTreeContainer<Value>(std::declval<const Tree&>()))>; + using TreeContainer = TYPEOF(makeTreeContainer<Value>(std::declval<const Tree&>())); //! \} group TypeTree -- GitLab