Lines Matching +full:- +full:std

6 #include <sstream> // std::ostringstream
9 #include <algorithm> // std::sort
15 // see https://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x
16 static inline void hash_combine(std::size_t &) noexcept { } in hash_combine()
19 static inline void hash_combine(std::size_t &seed, const T &v, Rest &&...rest) noexcept in hash_combine()
21 std::hash<T> hasher; in hash_combine()
23 hash_combine(seed, std::forward<Rest>(rest)...); in hash_combine()
27 namespace std \
31 std::size_t operator()(const type &t) const noexcept \
33 std::size_t ret = 0; \
40 using pair_type = std::pair<int, double>;
54 …bool operator<(const Foo &other) const noexcept { return std::tie(x, y) < std::tie(other.x, other.… in operator <()
56 PetscErrorCode to_string(std::string &buf) const noexcept in to_string()
59 PetscCallCXX(buf = std::to_string(x) + ", " + std::to_string(y)); in to_string()
63 friend std::ostream &operator<<(std::ostream &oss, const Foo &f) noexcept in operator <<()
65 std::string ret; in operator <<()
77 std::vector<int> x{};
78 std::string y{};
81 Bar(std::vector<int> x, std::string y) noexcept : x(std::move(x)), y(std::move(y)) { } in Bar()
84 …bool operator<(const Bar &other) const noexcept { return std::tie(x, y) < std::tie(other.x, other.… in operator <()
86 PetscErrorCode to_string(std::string &buf) const noexcept in to_string()
90 for (std::size_t i = 0; i < x.size(); ++i) { in to_string()
91 PetscCallCXX(buf += std::to_string(x[i])); in to_string()
98 friend std::ostream &operator<<(std::ostream &oss, const Bar &b) noexcept in operator <<()
100 std::string ret; in operator <<()
111 constexpr std::size_t operator()(const T &) const noexcept in operator ()()
119 using signature = PetscErrorCode(const T &, std::string &);
121 mutable std::string buffer;
122 std::function<signature> printer;
125 Printer(F &&printer) noexcept : printer(std::forward<F>(printer)) in Printer()
132 PetscCallAbort(PETSC_COMM_SELF, this->printer(value, this->buffer)); in operator ()()
133 PetscFunctionReturn(this->buffer.c_str()); in operator ()()
170 const std::string map_name;
173 std::function<value_type(void)> generator;
177 std::ostringstream oss; in view_map()
180 PetscCallCXX(oss << std::boolalpha); in view_map()
181 PetscCallCXX(oss << "map: '" << this->map_name << "'\n"); in view_map()
189 …entry : map) PetscCallCXX(oss << " key: [" << this->key_printer(entry.first) << "] -> [" << thi… in view_map()
198 PetscCall(this->view_map(map__)); \
199 SETERRQ(comm__, ierr__, "%s: " base_mess__, this->map_name.c_str(), __VA_ARGS__); \
217 …PetscErrorCode check_size_capacity_coherent(map_type &map, std::size_t expected_size, std::size_t … in check_size_capacity_coherent()
234 using insert_return_type = std::pair<typename map_type::iterator, bool>; in test_insert()
239 const auto pair = std::make_pair(key_const, value_const); in test_insert()
242 …ret.second, PETSC_COMM_SELF, PETSC_ERR_PLIB, "%s reinserted key '%s'", op, this->key_printer(key)); in test_insert()
243 …irst->first == key, PETSC_COMM_SELF, PETSC_ERR_PLIB, "%s returned iterator key '%s' != expected '%… in test_insert()
244->second == value, PETSC_COMM_SELF, PETSC_ERR_PLIB, "%s returned iterator value '%s' != expected '… in test_insert()
245 …SC_ERR_PLIB, "%s map[%s] '%s' != '%s'", op, this->key_printer(key), this->value_printer(map[key]),… in test_insert()
246 …_PLIB, "%s changed value '%s' != expected '%s'", op, this->value_printer(map[key_const]), this->va… in test_insert()
254 …PetscCall(CHECK_REINSERT(map.emplace(std::piecewise_construct, std::make_tuple(key), std::make_tup… in test_insert()
255 PetscCall(CHECK_REINSERT(map.insert(std::make_pair(key, value)))); in test_insert()
262 PetscCall(this->check_size_capacity_coherent(map)); in test_insert()
266 PetscCall(this->check_size_capacity_coherent(map, size_before + 1, capacity_before)); in test_insert()
268 …SELF, PETSC_ERR_PLIB, "Map default key %s != map value %s", this->key_printer(key), this->value_pr… in test_insert()
280 PetscCall(this->check_size_capacity_coherent(map, 0, capacity_before)); in test_insert()
283 …o test_map_contains_expected_items = [&](std::function<PetscErrorCode(std::vector<value_type> &)> … in test_insert()
284 auto key_value_pairs = this->make_key_values(kv_size); in test_insert()
285 std::vector<std::size_t> found_key_value(key_value_pairs.size()); in test_insert()
289 PetscCall(this->check_size_capacity_coherent(map, 0, 0)); in test_insert()
292 PetscCall(this->check_size_capacity_coherent(map, key_value_pairs.size(), 0)); in test_insert()
294 // sort the vector so we can use std::binary_search on it in test_insert()
295 PetscCallCXX(std::sort(key_value_pairs.begin(), key_value_pairs.end())); in test_insert()
298 const auto found = std::lower_bound(kv_begin, key_value_pairs.cend(), *it); in test_insert()
299 const auto dist = std::distance(kv_begin, found); in test_insert()
302 …PLIB, "Map contained key-value pair (%s, %s) not present in input range!", this->key_printer(it->f… in test_insert()
303 …"Index of found key-value pair (%s -> %s) %td is < 0", this->key_printer(it->first), this->value_p… in test_insert()
305 PetscCallCXX(++found_key_value.at(static_cast<std::size_t>(dist))); in test_insert()
308 // there should only be 1 instance of each key-value in the map in test_insert()
309 for (std::size_t i = 0; i < found_key_value.size(); ++i) { in test_insert()
310 … insert key %s (value %s), have find count %zu", this->key_printer(key_value_pairs[i].first), this in test_insert()
315 // clang-format off in test_insert()
318 [&](std::vector<value_type> &key_value_pairs) in test_insert()
330 // clang-format on in test_insert()
332 // test that inserting using std algorithms work in test_insert()
336 // clang-format off in test_insert()
339 [&](std::vector<value_type> &key_value_pairs) in test_insert()
345 …PetscCallCXX(std::copy(key_value_pairs.cbegin(), key_value_pairs.cend(), std::inserter(map, map.be… in test_insert()
351 // clang-format on in test_insert()
355 …nger contains key-value pair (%s -> %s) after std::copy() and container went out of scope", this->… in test_insert()
356->first == saved_value.first, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Map founnd iterator key (%s) does … in test_insert()
357->second == saved_value.second, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Map founnd iterator value (%s) d… in test_insert()
375 const auto sample_values = this->make_key_values(145); in test_find()
383 …!= map.end(), PETSC_COMM_SELF, PETSC_ERR_PLIB, "Failed to find %s in map", this->key_printer(key)); in test_find()
384 …apCheck(map, it->first == key, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Find iterator key %s != expected … in test_find()
385 …eck(map, it->second == value, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Find iterator value %s != expected… in test_find()
386 … reports false, even though map.find(key) successfully found it! key: %s", this->key_printer(key)); in test_find()
387 …t(key) == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "map.count(%s) %zu != 1", this->key_printer(key), ma… in test_find()
392 const auto range_size = std::distance(range_begin, range.second); in test_find()
395 …e_begin->first == key, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Equal range iterator key %s != expected %… in test_find()
396 …gin->second == value, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Equal range iterator value %s != expected … in test_find()
414 auto sample_values = this->make_key_values(57); in test_erase()
430 const auto begin_key = it->first; in test_erase()
431 const auto begin_val = it->second; in test_erase()
434 …MM_SELF, PETSC_ERR_PLIB, "Erasing %s did not work, found again in map", this->key_printer(begin_ke… in test_erase()
445 … PETSC_ERR_PLIB, "Iterator (%s -> %s) occupied after erase", this->key_printer(before->first), thi… in test_erase()
460 std::size_t cap_before; in test_erase()
468 …MM_SELF, PETSC_ERR_PLIB, "Map capacity should be 0 (have %zu) after clear() -> shrink_to_fit()!", … in test_erase()
490 // test erase by std::swap with empty map in test_erase()
493 using std::swap; in test_erase()
502 sample_values = this->make_key_values(); in test_erase()
503 std::copy(sample_values.cbegin(), sample_values.cend(), std::inserter(map, map.begin())); in test_erase()
518 // stupid dummy function because auto-lambdas are C++14
522 constexpr std::size_t max_iter = 10000; in test_iterators()
523 constexpr auto is_normal = std::is_same<It, typename map_type::iterator>::value; in test_iterators()
524 constexpr auto is_const = std::is_same<It, typename map_type::const_iterator>::value; in test_iterators()
526 constexpr const char *it_name = is_normal ? "Non-const" : "Const"; in test_iterators()
533 PetscCallCXX(--it); in test_iterators()
534 PetscCallCXX(it2--); in test_iterators()
535 …TSC_COMM_SELF, PETSC_ERR_PLIB, "%s iterator does not equal itself after --it, and it2--", it_name); in test_iterators()
539 std::size_t i; in test_iterators()
556 PetscCallCXX(it = std::prev(map.end())); in test_iterators()
559 PetscCallCXX(--it); in test_iterators()
562 PetscCallCXX(it = std::prev(map.end())); in test_iterators()
565 PetscCallCXX(it--); in test_iterators()
574 const auto sample_values = this->make_key_values(97); in test_misc()
578 PetscCall(this->test_iterators(map, map.begin(), map.begin())); in test_misc()
579 PetscCall(this->test_iterators(map, map.cbegin(), map.cbegin())); in test_misc()
593 PetscCall(this->test_insert(map_copy)); in test_misc()
595 PetscCall(this->test_find(map_copy)); in test_misc()
597 PetscCall(this->test_erase(map_copy)); in test_misc()
601 auto moved_copy = std::move(map_copy); in test_misc()
605 PetscCall(this->test_insert(moved_copy)); in test_misc()
607 PetscCall(this->test_find(moved_copy)); in test_misc()
609 PetscCall(this->test_erase(moved_copy)); in test_misc()
618 PetscCall(this->test_insert()); in test()
619 PetscCall(this->test_find()); in test()
620 PetscCall(this->test_erase()); in test()
621 PetscCall(this->test_misc()); in test()
626 PETSC_NODISCARD std::vector<value_type> make_key_values(std::size_t size = 100) const noexcept in make_key_values()
628 std::vector<value_type> v(size); in make_key_values()
630 std::generate(v.begin(), v.end(), this->generator); in make_key_values()
641 return {vwr, name, std::forward<Args>(args)...}; in make_tester()
658 const auto int_printer = [](int key, std::string &buf) { in main()
660 PetscCallCXX(buf = std::to_string(key)); in main()
663 const auto double_printer = [](double value, std::string &buf) { in main()
665 PetscCallCXX(buf = std::to_string(value)); in main()
668 const auto foo_printer = [](const Foo &key, std::string &buf) { in main()
673 const auto bar_printer = [](const Bar &value, std::string &buf) { in main()
678 const auto pair_printer = [](const std::pair<int, double> &value, std::string &buf) { in main()
680 … PetscCallCXX(buf = '<' + std::to_string(value.first) + ", " + std::to_string(value.second) + '>'); in main()
705 constexpr std::size_t max_size = 14, min_size = 1; in main()
706 const auto isize = std::abs(make_int()); in main()
707 std::vector<int> x(std::max(static_cast<std::size_t>(isize) % max_size, min_size)); in main()
710 PetscCallCXXAbort(PETSC_COMM_SELF, std::generate(x.begin(), x.end(), make_int)); in main()
711 auto ret = Bar{std::move(x), std::to_string(isize)}; in main()
715 const auto int_double_generator = [&] { return std::make_pair(make_int(), make_double()); }; in main()
716 …PetscCall(make_tester<int, double>(vwr, "int-double basic map", int_printer, double_printer, int_d… in main()
717 …PetscCall(make_tester<int, double, BadHash>(vwr, "int-double bad hash map", int_printer, double_pr… in main()
719 const auto int_foo_generator = [&] { return std::make_pair(make_int(), make_foo()); }; in main()
720 …PetscCall(make_tester<int, Foo, BadHash>(vwr, "int-foo bad hash map", int_printer, foo_printer, in… in main()
722 const auto foo_bar_generator = [&] { return std::make_pair(make_foo(), make_bar()); }; in main()
723 …PetscCall(make_tester<Foo, Bar>(vwr, "foo-bar basic map", foo_printer, bar_printer, foo_bar_genera… in main()
724 …PetscCall(make_tester<Foo, Bar, BadHash>(vwr, "foo-bar bad hash map", foo_printer, bar_printer, fo… in main()
729 auto pair = std::make_pair(make_int(), make_double()); in main()
730 return std::make_pair(pair, pair); in main()
732 …PetscCall(make_tester<std::pair<int, double>, std::pair<int, double>>(vwr, "pair<int, double>-pair… in main()
733 …PetscCall(make_tester<std::pair<int, double>, std::pair<int, double>, BadHash>(vwr, "pair<int, dou… in main()