Allocator Builder
Policy Based C++ Template Allocator Library
 All Classes Functions Variables Enumerations Enumerator Groups Pages
noatomic.hpp
1 //
3 // Copyright 2014 Felix Petriconi
4 //
5 // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0
6 //
7 // Authors: http://petriconi.net, Felix Petriconi
8 //
10 #pragma once
11 
12 namespace alb {
13  inline namespace v_100 {
14  namespace internal {
15 
25  template <typename T>
26  class no_atomic
27  {
28  T value_;
29 
30  public:
31  using type = T;
32 
33  no_atomic() noexcept
34  {}
35 
36  explicit no_atomic(T v) noexcept
37  : value_(std::move(v))
38  {}
39 
40  T load() const noexcept {
41  return value_;
42  }
43 
44  no_atomic &operator=(T v) noexcept {
45  value_ = std::move(v);
46  return *this;
47  }
48 
49  bool compare_exchange_strong(T &, T v) noexcept
50  {
51  value_ = std::move(v);
52  return true;
53  }
54 
55  operator T() const {
56  return value_;
57  }
58 
59  T operator++() { return ++value_; }
60  T operator++(int) { return value_++; }
61  T operator--() { return --value_;}
62  T operator--(int) { return value_--; }
63  T operator+=(T arg) { return value_ += arg; }
64  T operator-=(T arg) { return value_ -= arg; }
65  };
66  }
67  }
68  using namespace v_100;
69 }