SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
non_propagating_cache.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <optional>
13
15
16namespace seqan3::detail
17{
18
32template <typename T>
33 requires std::is_object_v<T>
34class non_propagating_cache : public std::optional<T>
35{
36public:
38 using std::optional<T>::optional;
40 using std::optional<T>::operator=;
41
43 constexpr non_propagating_cache(non_propagating_cache const &) noexcept
44 {}
45
47 constexpr non_propagating_cache(non_propagating_cache && other) noexcept
48 {
49 other.reset();
50 }
51
53 constexpr non_propagating_cache & operator=(non_propagating_cache const & other) noexcept
54 {
55 if (std::addressof(other) != this)
56 this->reset();
57 return *this;
58 }
59
61 constexpr non_propagating_cache & operator=(non_propagating_cache && other) noexcept
62 {
63 this->reset();
64 other.reset();
65 return *this;
66 }
67
69 template <class I>
70 constexpr T & emplace_deref(I const & i)
71 requires requires (I const & i) { T(*i); }
72 {
73 this->reset();
74 this->emplace(*i);
75 return this->value();
76 }
77};
78
79} // namespace seqan3::detail
T addressof(T... args)
T emplace(T... args)
T operator=(T... args)
Provides platform and dependency checks.
T reset(T... args)
T value(T... args)
Hide me