X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Ftest%2FMapUtilTest.cpp;h=7ef13f718fcf757e50fc2e7a202bcbb118cabc01;hp=52e63e81f7a900360a54a6d3ccd5f0fc1cf2f4be;hb=5a07e203d79324b68d69f294fa38e43b9671e9b1;hpb=d7629090e2c23da58ffc8977b22ccb17a25ae51c diff --git a/folly/test/MapUtilTest.cpp b/folly/test/MapUtilTest.cpp index 52e63e81..7ef13f71 100644 --- a/folly/test/MapUtilTest.cpp +++ b/folly/test/MapUtilTest.cpp @@ -16,6 +16,7 @@ #include +#include #include #include @@ -246,3 +247,52 @@ TEST(MapUtil, get_ref_default_path_temporary) { EXPECT_FALSE(GetRefDefaultPathCompiles::value); EXPECT_FALSE(GetRefDefaultPathCompiles::value); } + +namespace { + +class TestConstruction { + public: + TestConstruction() { + EXPECT_TRUE(false); + } + TestConstruction(TestConstruction&&) { + EXPECT_TRUE(false); + } + TestConstruction(const TestConstruction&) { + EXPECT_TRUE(false); + } + + explicit TestConstruction(std::string&& string) + : string_{std::move(string)} {} + explicit TestConstruction(int&& integer) : integer_{integer} {} + + TestConstruction& operator=(const TestConstruction&) = delete; + TestConstruction& operator=(TestConstruction&&) = delete; + + int integer_{}; + std::string string_{}; +}; + +} // namespace + +TEST(MapUtil, test_get_default_deferred_construction) { + auto map = std::unordered_map{}; + map.emplace( + std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(1)); + + EXPECT_EQ(map.at(1).integer_, 1); + + { + auto val = get_default(map, 0, 1); + EXPECT_EQ(val.integer_, 1); + EXPECT_EQ(val.string_, ""); + } + + { + auto val = get_default(map, 0, "something"); + EXPECT_EQ(val.integer_, 0); + EXPECT_EQ(val.string_, "something"); + } +}