std::declval<int>(),
std::declval<int>(),
std::declval<T>()))>> : std::true_type {};
-
} // namespace
TEST(MapUtil, get_ref_default_path_temporary) {
class TestConstruction {
public:
- static std::size_t numberDefaultConstructs;
TestConstruction() {
- ++numberDefaultConstructs;
+ EXPECT_TRUE(false);
+ }
+ TestConstruction(TestConstruction&&) {
+ EXPECT_TRUE(false);
+ }
+ TestConstruction(const TestConstruction&) {
+ EXPECT_TRUE(false);
}
- TestConstruction(TestConstruction&&) = default;
- TestConstruction(const TestConstruction&) = default;
+
+ explicit TestConstruction(std::string&& string)
+ : string_{std::move(string)} {}
+ explicit TestConstruction(int&& integer) : integer_{integer} {}
TestConstruction& operator=(const TestConstruction&) = delete;
TestConstruction& operator=(TestConstruction&&) = delete;
-};
-std::size_t TestConstruction::numberDefaultConstructs = 0;
+ int integer_{};
+ std::string string_{};
+};
} // namespace
TEST(MapUtil, test_get_default_deferred_construction) {
auto map = std::unordered_map<int, TestConstruction>{};
- map.insert({1, TestConstruction{}});
+ map.emplace(
+ std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple(1));
- EXPECT_EQ(TestConstruction::numberDefaultConstructs, 1);
+ EXPECT_EQ(map.at(1).integer_, 1);
{
- auto val = get_default(map, 1);
- EXPECT_EQ(TestConstruction::numberDefaultConstructs, 1);
- static_cast<void>(val);
+ auto val = get_default(map, 0, 1);
+ EXPECT_EQ(val.integer_, 1);
+ EXPECT_EQ(val.string_, "");
}
{
- auto val = get_default(map, 1, TestConstruction{});
- EXPECT_EQ(TestConstruction::numberDefaultConstructs, 2);
- static_cast<void>(val);
+ auto val = get_default(map, 0, "something");
+ EXPECT_EQ(val.integer_, 0);
+ EXPECT_EQ(val.string_, "something");
}
}