SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
non_propagating_cache.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <optional>
16 
17 #include <seqan3/core/platform.hpp>
18 
19 namespace seqan3::detail
20 {
21 
35 template <typename T>
36  requires std::is_object_v<T>
37 class non_propagating_cache : public std::optional<T>
38 {
39 public:
44 
46  constexpr non_propagating_cache(non_propagating_cache const &) noexcept
47  {}
48 
50  constexpr non_propagating_cache(non_propagating_cache && other) noexcept
51  {
52  other.reset();
53  }
54 
56  constexpr non_propagating_cache & operator=(non_propagating_cache const & other) noexcept
57  {
58  if (std::addressof(other) != this)
59  this->reset();
60  return *this;
61  }
62 
64  constexpr non_propagating_cache & operator=(non_propagating_cache && other) noexcept
65  {
66  this->reset();
67  other.reset();
68  return *this;
69  }
70 
72  template <class I>
73  constexpr T & emplace_deref(I const & i)
74  requires requires (I const & i) { T(*i); }
75  {
76  this->reset();
77  this->emplace(*i);
78  return this->value();
79  }
80 };
81 
82 } // namespace seqan3::detail
T addressof(T... args)
T emplace(T... args)
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
T operator=(T... args)
Provides platform and dependency checks.
T reset(T... args)
T value(T... args)