Skip to content
Snippets Groups Projects
Select Git revision
  • 33f01d08da9774ad3ea15b5d3bae66cd9d8785f2
  • master default
  • releases/2.10
  • feature/update-buildsystem
  • releases/2.9
  • more-features-for-cholmodsolver
  • releases/2.8
  • fix/error-norm
  • releases/2.7
  • implement-overlappingblockgsstep
  • make-getiterationstep-return-shared-ptr
  • feature/blockgssteps_autoCopy
  • releases/2.6-1
  • feature/use-smart-ptr-ignorenodes
  • feature/update-to-clang-7
  • feature/whitespace-fix
  • flexible-loopsolver-max
  • releases/2.5-1
  • feature/incomplete-cholesky-rebased
  • feature/istl-preconditioners
  • feature/optional-ignore
  • subversion->git
22 results

FindIPOpt.cmake

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    copyorreference.hh 2.25 KiB
    // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
    // vi: set et ts=4 sw=2 sts=2:
    #ifndef DUNE_SOLVERS_COMMON_COPYORREFERENCE_HH
    #define DUNE_SOLVERS_COMMON_COPYORREFERENCE_HH
    
    #include <dune/common/indices.hh>
    #include <dune/common/concept.hh>
    
    #include <dune/solvers/common/defaultbitvector.hh>
    
    
    
    namespace Dune {
    namespace Solvers {
    
    
    /**
     * \brief A wrapper storing either a copy or reference
     *
     * \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.
     */
    template<class T>
    class CopyOrReference
    {
    public:
      using Type = std::decay_t<T>;
    
      constexpr CopyOrReference(const Type& other) :
        t_(other)
      {}
    
      constexpr CopyOrReference(Type&& other) :
        t_(std::move(other))
      {}
    
      constexpr const Type& get() const
      {
        return t_;
      }
    
      constexpr Type& get()
      {
        return t_;
      }
    
      constexpr std::true_type hasCopy() const
      {
        return {};
      }
    
    private:
      Type t_;
    };
    
    
    
    template<class T>
    class CopyOrReference<T&>
    {
    public:
      using Type = std::decay_t<T>;
    
      constexpr CopyOrReference(Type& other) :
        t_(&other)
      {}
    
      constexpr const Type& get() const
      {
        return *t_;
      }
    
      constexpr Type& get()
      {
        return *t_;
      }
    
      constexpr std::false_type hasCopy() const
      {
        return {};
      }
    
    private:
      Type* t_;
    };
    
    
    
    template<class T>
    class CopyOrReference<const T&>
    {
    public:
      using Type = std::decay_t<T>;
    
      constexpr CopyOrReference(const Type& other) :
        t_(&other)
      {}
    
      constexpr const Type& get() const
      {
        return *t_;
      }
    
      constexpr std::false_type hasCopy() const
      {
        return {};
      }
    
    private:
      const Type* t_;
    };
    
    
    
    /**
     * \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
    
    
    
    #endif // DUNE_SOLVERS_COMMON_COPYORREFERENCE_HH