|
20 | 20 | #include <memory> |
21 | 21 | #include <string> |
22 | 22 | #include <unordered_map> |
| 23 | +#include <utility> |
23 | 24 | #include <vector> |
24 | 25 |
|
25 | 26 | enum class kJITHeuristics { |
@@ -80,30 +81,37 @@ class Node { |
80 | 81 | static const int kMaxChildren = 3; |
81 | 82 |
|
82 | 83 | protected: |
83 | | - const std::array<Node_ptr, kMaxChildren> m_children; |
84 | | - const af::dtype m_type; |
85 | | - const int m_height; |
| 84 | + std::array<Node_ptr, kMaxChildren> m_children; |
| 85 | + af::dtype m_type; |
| 86 | + int m_height; |
86 | 87 |
|
87 | 88 | template<typename T> |
88 | 89 | friend class NodeIterator; |
89 | 90 |
|
| 91 | + void swap(Node &other) noexcept { |
| 92 | + using std::swap; |
| 93 | + for (int i = 0; i < kMaxChildren; i++) { |
| 94 | + swap(m_children[i], other.m_children[i]); |
| 95 | + } |
| 96 | + swap(m_type, other.m_type); |
| 97 | + swap(m_height, other.m_height); |
| 98 | + } |
| 99 | + |
90 | 100 | public: |
| 101 | + Node() = default; |
91 | 102 | Node(const af::dtype type, const int height, |
92 | 103 | const std::array<Node_ptr, kMaxChildren> children) |
93 | | - : m_children(children), m_type(type), m_height(height) {} |
94 | | - |
95 | | - /// Default copy constructor |
96 | | - Node(Node &node) = default; |
| 104 | + : m_children(children), m_type(type), m_height(height) { |
| 105 | + static_assert(std::is_nothrow_move_assignable<Node>::value, |
| 106 | + "Node is not move assignable"); |
| 107 | + } |
97 | 108 |
|
98 | | - /// Default move constructor |
99 | | - Node(Node &&node) = default; |
| 109 | + /// Default copy constructor operator |
| 110 | + Node(const Node &node) = default; |
100 | 111 |
|
101 | 112 | /// Default copy assignment operator |
102 | 113 | Node &operator=(const Node &node) = default; |
103 | 114 |
|
104 | | - /// Default move assignment operator |
105 | | - Node &operator=(Node &&node) = default; |
106 | | - |
107 | 115 | int getNodesMap(Node_map_t &node_map, std::vector<Node *> &full_nodes, |
108 | 116 | std::vector<Node_ids> &full_ids); |
109 | 117 |
|
@@ -213,7 +221,7 @@ class Node { |
213 | 221 | virtual std::string getNameStr() const { return getShortName(m_type); } |
214 | 222 |
|
215 | 223 | /// Default destructor |
216 | | - virtual ~Node() = default; |
| 224 | + virtual ~Node() noexcept = default; |
217 | 225 | }; |
218 | 226 |
|
219 | 227 | struct Node_ids { |
|
0 commit comments