@@ -44,7 +44,7 @@ class Context
4444 template <class T >
4545 Context SetValues (T &values) noexcept
4646 {
47- Context context = Context (values);
47+ Context context (values);
4848 nostd::shared_ptr<DataList> last = context.head_ ;
4949 while (last->next_ != nullptr )
5050 {
@@ -59,7 +59,7 @@ class Context
5959 // exisiting list to the end of the new list.
6060 Context SetValue (nostd::string_view key, ContextValue value) noexcept
6161 {
62- Context context = Context (key, std::move (value));
62+ Context context (key, std::move (value));
6363 context.head_ ->next_ = head_;
6464 return context;
6565 }
@@ -92,11 +92,11 @@ class Context
9292 // A linked list to contain the keys and values of this context node
9393 struct DataList
9494 {
95- char *key_ = nullptr ;
95+ char *key_{ nullptr } ;
9696
9797 nostd::shared_ptr<DataList> next_{nullptr };
9898
99- size_t key_length_ = 0UL ;
99+ size_t key_length_{} ;
100100
101101 ContextValue value_;
102102
@@ -108,7 +108,7 @@ class Context
108108 {
109109 bool first = true ;
110110 auto *node = this ;
111- for (auto &iter : keys_and_vals)
111+ for (const auto &iter : keys_and_vals)
112112 {
113113 if (first)
114114 {
@@ -126,29 +126,28 @@ class Context
126126 // Builds a data list with just a key and value, so it will just be the head
127127 // and returns that head.
128128 DataList (nostd::string_view key, ContextValue value)
129+ : key_{new char [key.size ()]},
130+ next_{nostd::shared_ptr<DataList>{nullptr }},
131+ key_length_{key.size ()},
132+ value_{std::move (value)}
129133 {
130- key_ = new char [key.size ()];
131- key_length_ = key.size ();
132134 std::memcpy (key_, key.data (), key.size () * sizeof (char ));
133- next_ = nostd::shared_ptr<DataList>{nullptr };
134- value_ = std::move (value);
135135 }
136136
137- DataList (const DataList &other)
138- : key_(new char [other.key_length_]),
139- next_ (other.next_),
140- key_length_(other.key_length_),
141- value_(other.value_)
142- {
143- std::memcpy (key_, other.key_ , other.key_length_ * sizeof (char ));
144- }
137+ // Delete unused special member functions
138+ DataList (const DataList &other) = delete ;
139+ DataList (DataList &&other) noexcept = delete ;
140+ DataList &operator =(const DataList &other) = delete ;
145141
142+ // Move assignment operator is only called by DataList(const T &keys_and_vals)
143+ // The moved to object has default member values
146144 DataList &operator =(DataList &&other) noexcept
147145 {
148146 key_length_ = other.key_length_ ;
149147 value_ = std::move (other.value_ );
150148 next_ = std::move (other.next_ );
151149
150+ // key_ has a default nullptr value and does not need to be deleted before this assignment
152151 key_ = other.key_ ;
153152 other.key_ = nullptr ;
154153
0 commit comments