Skip to content

Commit

Permalink
json: add moving push to json_list
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
travisdowns committed Dec 18, 2024
1 parent 97e202a commit a860b5e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/seastar/json/json_elements.hh
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,22 @@ public:

/**
* Add an element to the list.
* @param element a new element that will be added to the list
* @param element a new element that will be added to the end of the list
*/
void push(const T& element) {
_set = true;
_elements.push_back(element);
}

/**
* Move an element into the list.
* @param element a new element that will be added to the list using move-construction
*/
void push(T&& element) {
_set = true;
_elements.push_back(std::move(element));
}

virtual std::string to_string() override
{
return formatter::to_json(_elements);
Expand Down

0 comments on commit a860b5e

Please sign in to comment.