Skip to content

Commit 613d8b3

Browse files
travisdownsavikivity
authored andcommitted
json: add moving push to json_list
When building up json lists in memory we have only the `push` method which takes const T&, but one taking an rvalue reference and moves into the list would be useful for heavy elements.
1 parent c863886 commit 613d8b3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

include/seastar/json/json_elements.hh

+10-1
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,22 @@ public:
162162

163163
/**
164164
* Add an element to the list.
165-
* @param element a new element that will be added to the list
165+
* @param element a new element that will be added to the end of the list
166166
*/
167167
void push(const T& element) {
168168
_set = true;
169169
_elements.push_back(element);
170170
}
171171

172+
/**
173+
* Move an element into the list.
174+
* @param element a new element that will be added to the list using move-construction
175+
*/
176+
void push(T&& element) {
177+
_set = true;
178+
_elements.push_back(std::move(element));
179+
}
180+
172181
virtual std::string to_string() override
173182
{
174183
return formatter::to_json(_elements);

0 commit comments

Comments
 (0)