VCCC  2024.05
VisualCamp Common C++ library
move_assignment.h
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2021/05/24.
3 # */
4 #
5 #ifndef VCCC_OPTIONAL_INTERNAL_MOVE_ASSIGNMENT_H_
6 #define VCCC_OPTIONAL_INTERNAL_MOVE_ASSIGNMENT_H_
7 #
8 # include <type_traits>
9 #
11 
12 namespace vccc {
13 namespace internal {
14 namespace optional {
15 
16 template<typename T, bool v =
20 struct move_assign : copy_assign<T> {
21  using base = copy_assign<T>;
22  using base::base;
23 };
24 
25 template<typename T>
26 struct move_assign<T, false> : copy_assign<T> {
27  using base = copy_assign<T>;
28  using base::base;
29 
30  move_assign() = default;
31  move_assign(move_assign const&) = default;
32  move_assign(move_assign &&) = default;
33  move_assign& operator=(move_assign const&) = default;
34  move_assign& operator=(move_assign && other)
36  {
37  if (!other.valid) {
38  this->reset();
39  } else {
40  if (this->valid)
41  this->val = std::move(other.val);
42  else
43  this->construct(std::move(other.val));
44  }
45  return *this;
46  }
47 };
48 
49 } // namespace optional
50 } // namespace internal
51 } // namespace vccc
52 
53 # endif // VCCC_OPTIONAL_INTERNAL_MOVE_ASSIGNMENT_H_
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35