+
+namespace {
+
+class TestConstruction {
+ public:
+ static std::size_t numberDefaultConstructs;
+ TestConstruction() {
+ ++numberDefaultConstructs;
+ }
+ TestConstruction(TestConstruction&&) = default;
+ TestConstruction(const TestConstruction&) = default;
+
+ TestConstruction& operator=(const TestConstruction&) = delete;
+ TestConstruction& operator=(TestConstruction&&) = delete;
+};
+
+std::size_t TestConstruction::numberDefaultConstructs = 0;
+
+} // namespace
+
+TEST(MapUtil, test_get_default_deferred_construction) {
+ auto map = std::unordered_map<int, TestConstruction>{};
+ map.insert({1, TestConstruction{}});
+
+ EXPECT_EQ(TestConstruction::numberDefaultConstructs, 1);
+
+ {
+ auto val = get_default(map, 1);
+ EXPECT_EQ(TestConstruction::numberDefaultConstructs, 1);
+ static_cast<void>(val);
+ }
+
+ {
+ auto val = get_default(map, 1, TestConstruction{});
+ EXPECT_EQ(TestConstruction::numberDefaultConstructs, 2);
+ static_cast<void>(val);
+ }
+}