21 #include <unordered_map> 26 using namespace folly;
36 TEST(MapUtil, get_default_function) {
58 TEST(MapUtil, get_or_throw_specified) {
61 EXPECT_EQ(2, get_or_throw<std::runtime_error>(m, 1));
62 EXPECT_THROW(get_or_throw<std::runtime_error>(m, 2), std::runtime_error);
73 TEST(MapUtil, get_optional_path_simple) {
87 TEST(MapUtil, get_optional_path_mixed) {
90 using std::unordered_map;
91 unordered_map<string, map<int, map<string, int>>>
m{{
"a", {{1, {{
"b", 2}}}}}};
102 std::map<int, int>
m;
110 TEST(MapUtil, get_ref_default_function) {
111 std::map<int, int>
m;
125 std::map<int, int>
m;
133 TEST(MapUtil, get_ptr_path_simple) {
152 TEST(MapUtil, get_ptr_path_mixed) {
155 using std::unordered_map;
156 unordered_map<string, map<int, map<string, int>>>
m{{
"a", {{1, {{
"b", 7}}}}}};
172 template <
typename T>
173 struct element_type {
177 template <
typename T>
178 struct element_type<T()> {
182 template <
typename T>
183 using element_type_t =
typename element_type<T>::type;
185 template <
typename T,
typename =
void>
188 template <
typename T>
191 void_t<decltype(get_ref_default(
192 std::declval<std::map<int, element_type_t<T>>>(),
197 TEST(MapUtil, get_default_temporary) {
208 TEST(MapUtil, get_default_path) {
216 TEST(MapUtil, get_default_path_mixed) {
219 using std::unordered_map;
222 const string key2 =
"hello";
225 m[key1][key2] =
value;
232 TEST(MapUtil, get_ref_default_path) {
241 TEST(MapUtil, get_ref_default_path_mixed) {
244 using std::unordered_map;
247 const string key2 =
"hello";
250 m[key1][key2] =
value;
258 template <
typename T,
typename =
void>
261 template <
typename T>
262 struct GetRefDefaultPathCompiles<
264 void_t<decltype(get_ref_default(
265 std::declval<std::map<int, std::map<int, element_type_t<T>>>>(),
271 TEST(MapUtil, get_ref_default_path_temporary) {
280 class TestConstruction {
285 TestConstruction(TestConstruction&&) {
288 TestConstruction(
const TestConstruction&) {
294 explicit TestConstruction(
int&& integer) :
integer_{integer} {}
296 TestConstruction& operator=(
const TestConstruction&) =
delete;
297 TestConstruction& operator=(TestConstruction&&) =
delete;
305 TEST(MapUtil, test_get_default_deferred_construction) {
306 auto map = std::unordered_map<int, TestConstruction>{};
308 std::piecewise_construct,
309 std::forward_as_tuple(1),
310 std::forward_as_tuple(1));
const Map::mapped_type * get_ptr(const Map &map, const Key &key)
Map::mapped_type get_default(const Map &map, const Key &key)
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_EQ(val1, val2)
const Map::mapped_type & get_ref_default(const Map &map, const Key &key, const typename Map::mapped_type &dflt)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
bool_constant< true > true_type
static map< string, int > m
folly::Optional< typename Map::mapped_type > get_optional(const Map &map, const Key &key)
static const char *const value
#define EXPECT_TRUE(condition)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
bool_constant< false > false_type
const Map::mapped_type & get_or_throw(const Map &map, const Key &key, const std::string &exceptionStrPrefix=std::string())
#define EXPECT_FALSE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)