VCCC  2024.05
VisualCamp Common C++ library
copy_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_COPY_ASSIGNMENT_H_
6 # define VCCC_OPTIONAL_INTERNAL_COPY_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 copy_assign : move_ctor<T> {
21  using base = move_ctor<T>;
22  using base::base;
23 };
24 
25 template<typename T>
26 struct copy_assign<T, false> : move_ctor<T> {
27  using base = move_ctor<T>;
28  using base::base;
29 
30  copy_assign() = default;
31  copy_assign(copy_assign const&) = default;
32  copy_assign(copy_assign &&) = default;
33  copy_assign& operator=(copy_assign const& other) {
34  if (!other.valid) {
35  this->reset();
36  } else {
37  if (this->valid)
38  this->val = other.val;
39  else
40  this->construct(other.val);
41  }
42  return *this;
43  }
44  copy_assign& operator=(copy_assign &&) = default;
45 };
46 
47 } // namespace optional
48 } // namespace internal
49 } // namespace vccc
50 
51 # endif // VCCC_OPTIONAL_INTERNAL_COPY_ASSIGNMENT_H_
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35