From db169073f195efcb9b35df5c314c65ba39705cef Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Wed, 22 Jul 2015 17:21:54 +0200 Subject: Change how emplacing is being done to avoid unnecessary move_clones on temporaries --- include/tag_compound.h | 2 +- include/tag_list.h | 4 ++-- test/nbttest.cpp | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/tag_compound.h b/include/tag_compound.h index 1f1c5f3e1a..8e09ff4834 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -127,7 +127,7 @@ private: template std::pair tag_compound::emplace(const std::string& key, Args&&... args) { - return put(key, value(T(std::forward(args)...))); + return put(key, value(make_unique(std::forward(args)...))); } } diff --git a/include/tag_list.h b/include/tag_list.h index 137b53d5d1..f1f5e6dec1 100644 --- a/include/tag_list.h +++ b/include/tag_list.h @@ -175,7 +175,7 @@ void tag_list::emplace_back(Args&&... args) el_type_ = T::type; else if(el_type_ != T::type) throw std::bad_cast(); - tags.emplace_back(T(std::forward(args)...)); + tags.emplace_back(make_unique(std::forward(args)...)); } template @@ -184,7 +184,7 @@ void tag_list::init(std::initializer_list init) el_type_ = T::type; tags.reserve(init.size()); for(const Arg& arg: init) - tags.emplace_back(T(arg)); + tags.emplace_back(make_unique(arg)); } } diff --git a/test/nbttest.cpp b/test/nbttest.cpp index fdc6d5e3f0..7e3a78b341 100644 --- a/test/nbttest.cpp +++ b/test/nbttest.cpp @@ -274,6 +274,8 @@ void test_tag_list() EXPECT_EXCEPTION(list.at(-1), std::out_of_range); list.set(1, tag_string("baz")); + EXPECT_EXCEPTION(list.set(1, value(nullptr)), std::bad_cast); + EXPECT_EXCEPTION(list.set(1, -42), std::bad_cast); ASSERT(static_cast(list[1]) == "baz"); ASSERT(list.size() == 2); -- cgit 0.0.5-2-1-g0f52