sequencer
copyable_atomic.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <atomic>
4 
5 namespace sequencer
6 {
7  template < class T >
9  {
10  public:
11  copyable_atomic() = default;
12 
13  constexpr explicit copyable_atomic( T value ) noexcept : value_{value}
14  {
15  }
16 
17  copyable_atomic& operator=( T value ) noexcept
18  {
19  value_ = value;
20  return *this;
21  }
22 
24  copyable_atomic( const copyable_atomic& other ) : value_{other.load()}
25  {
26  }
27 
30  {
31  value_ = other.load();
32  return *this;
33  }
34 
35  T load( std::memory_order order = std::memory_order_seq_cst ) const noexcept
36  {
37  return value_.load( order );
38  }
39 
40  void store( T value, std::memory_order order = std::memory_order_seq_cst ) const noexcept
41  {
42  value_.store( value, order );
43  }
44 
45  operator T() const noexcept
46  {
47  return load();
48  }
49 
50  private:
51  std::atomic< T > value_;
52  };
53 } // namespace sequencer
copyable_atomic & operator=(T value) noexcept
Definition: copyable_atomic.hpp:17
constexpr copyable_atomic(T value) noexcept
Definition: copyable_atomic.hpp:13
Definition: copyable_atomic.hpp:8
T load(std::memory_order order=std::memory_order_seq_cst) const noexcept
Definition: copyable_atomic.hpp:35
copyable_atomic(const copyable_atomic &other)
Definition: copyable_atomic.hpp:24
copyable_atomic & operator=(const copyable_atomic &other)
Definition: copyable_atomic.hpp:29
void store(T value, std::memory_order order=std::memory_order_seq_cst) const noexcept
Definition: copyable_atomic.hpp:40