Skip to content

Commit 2f85010

Browse files
committed
Avoid constructing temporary T in make_box
1 parent 496c20f commit 2f85010

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

include/function2/function2.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ struct box : private Allocator {
376376

377377
T value_;
378378

379-
explicit box(T value, Allocator allocator_)
379+
explicit box(const T& value, Allocator allocator_)
380+
: Allocator(std::move(allocator_)), value_(value) {
381+
}
382+
383+
explicit box(T&& value, Allocator allocator_)
380384
: Allocator(std::move(allocator_)), value_(std::move(value)) {
381385
}
382386

@@ -392,7 +396,11 @@ struct box<false, T, Allocator> : private Allocator {
392396

393397
T value_;
394398

395-
explicit box(T value, Allocator allocator_)
399+
explicit box(const T& value, Allocator allocator_)
400+
: Allocator(std::move(allocator_)), value_(std::move(value)) {
401+
}
402+
403+
explicit box(T&& value, Allocator allocator_)
396404
: Allocator(std::move(allocator_)), value_(std::move(value)) {
397405
}
398406

0 commit comments

Comments
 (0)