From 05fef93d8afbd53c5d17f839e209cc4b659491c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@dune-project.org> Date: Wed, 24 Aug 2016 00:09:57 +0200 Subject: [PATCH] Add template alias ConstCopyOrReference This adds constness to the stored copy or reference. Notice that simply using CopyOrReference<const T> for ConstCopyOrReference<T> does not work since 'const T' is the same as T for reference types because all references are const. --- dune/solvers/common/copyorreference.hh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dune/solvers/common/copyorreference.hh b/dune/solvers/common/copyorreference.hh index c130c567..b03ea815 100644 --- a/dune/solvers/common/copyorreference.hh +++ b/dune/solvers/common/copyorreference.hh @@ -17,7 +17,7 @@ namespace Solvers { /** * \brief A wrapper storing either a copy or reference * - * \tparam T Type to be refered to + * \tparam T Type to be stored * * If T is of reference type, the wrapper stores a reference * to the passed object. Otherwise it stores a copy. @@ -114,6 +114,27 @@ private: +/** + * \brief A wrapper storing either a const copy or const reference + * + * \tparam T Type to be stored + * + * This is an alias for CopyOrReference<TT> where TT + * is either 'const T' if T is a raw type or 'const S&' + * if T is a 'S&'. Notice that in the latter case this + * is different from 'const T' which would be the same + * as T. + */ +template<class T> +using ConstCopyOrReference = + CopyOrReference< + std::conditional_t< + std::is_reference<T>::value, + const std::remove_reference_t<T>&, + const T>>; + + + } // end namespace Solvers } // end namespace Dune -- GitLab