From b43580dd62d6522d15a4b961e86405a9207d2cc2 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Mon, 13 Apr 2020 19:00:21 +0200 Subject: [PATCH] [cleanup] Remove optional.hh --- dumux/common/CMakeLists.txt | 1 - dumux/common/optional.hh | 154 ------------------------------------ 2 files changed, 155 deletions(-) delete mode 100644 dumux/common/optional.hh diff --git a/dumux/common/CMakeLists.txt b/dumux/common/CMakeLists.txt index bcfa96e8ec..a108414371 100644 --- a/dumux/common/CMakeLists.txt +++ b/dumux/common/CMakeLists.txt @@ -26,7 +26,6 @@ loggingparametertree.hh math.hh monotonecubicspline.hh numericdifferentiation.hh -optional.hh parameters.hh partial.hh pdesolver.hh diff --git a/dumux/common/optional.hh b/dumux/common/optional.hh deleted file mode 100644 index d9dfb678bf..0000000000 --- a/dumux/common/optional.hh +++ /dev/null @@ -1,154 +0,0 @@ -// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -// vi: set et ts=4 sw=4 sts=4: -/***************************************************************************** - * See the file COPYING for full copying permissions. * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - *****************************************************************************/ -/*! - * \file - * \ingroup Common - * \brief A wrapper that can either contain an object of T or be empty. - * This might be used as a workaround for non-default constructible classes. - * \note Replace this with std::optional when C++17 is available - */ -#ifndef DUMUX_COMMON_OPTIONAL_HH -#define DUMUX_COMMON_OPTIONAL_HH - -#warning "This header is deprecated and will be removed after release 3.2" -#include <utility> - -#include <dune/common/typeutilities.hh> - -namespace Dumux { - -/*! - * \ingroup Common - * \brief A wrapper that can either contain an object of T or be empty - * \tparam T Type of wrapped objects - */ -template<class T> -class [[deprecated("Optional is deprecated (removed after 3.2); use std::optional")]] Optional -{ -public: - - Optional() : - p_(nullptr) - {} - - template<class TT, Dune::disableCopyMove<Optional, TT> = 0> - Optional(TT&& t) : - p_(nullptr) - { - emplace(std::forward<TT>(t)); - } - - Optional(Optional&& other) - { - if (other) - p_ = new (buffer_) T(std::move(other.value())); - else - p_ = nullptr; - } - - Optional(const Optional& other) - { - if (other) - p_ = new (buffer_) T(other.value()); - else - p_ = nullptr; - } - - ~Optional() - { - if (operator bool()) - p_->~T(); - } - - template<class TT, Dune::disableCopyMove<Optional, TT> = 0 > - Optional& operator=(TT&& t) - { - if (operator bool()) - *p_ = std::forward<T>(t); - else - p_ = new (buffer_) T(std::forward<T>(t)); - return *this; - } - - Optional& operator=(const Optional& other) - { - if (other) - *this = other.value(); - else if (operator bool()) - { - p_->~T(); - p_ = nullptr; - } - return *this; - } - - Optional& operator=(Optional&& other) - { - if (other) - *this = std::move(other.value()); - else if (operator bool()) - { - p_->~T(); - p_ = nullptr; - } - return *this; - } - - explicit operator bool() const - { - return p_; - } - - const T& value() const - { - return *p_; - } - - T& value() - { - return *p_; - } - - template< class... Args > - void emplace(Args&&... args) - { - if (operator bool()) - p_->~T(); - p_ = new (buffer_) T(std::forward<Args>(args)...); - } - - void release() - { - if (operator bool()) - { - p_->~T(); - p_ = nullptr; - } - } - -private: - - alignas(T) char buffer_[sizeof(T)]; - T* p_; -}; - - -} // namespace Dumux - -#endif // DUMUX_COMMON_OPTIONAL_HH -- GitLab