From 7d079e8cb33ab93f1d42c5f3f84c8688932b6d55 Mon Sep 17 00:00:00 2001 From: Tessil Date: Sat, 18 May 2019 12:50:05 +0200 Subject: [PATCH] Add information on the copy and/or move constructible requirement of 'Key' and 'T'. --- README.md | 2 +- include/tsl/robin_map.h | 2 ++ include/tsl/robin_set.h | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01e1a1b..81c4b41 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ A **benchmark** of `tsl::robin_map` against other hash maps may be found [here]( `tsl::robin_map` tries to have an interface similar to `std::unordered_map`, but some differences exist. - The **strong exception guarantee only holds** if the following statement is true `std::is_nothrow_swappable::value && std::is_nothrow_move_constructible::value` (where `value_type` is `Key` for `tsl::robin_set` and `std::pair` for `tsl::robin_map`). Otherwise if an exception is thrown during the swap or the move, the structure may end up in a undefined state. Note that per the standard, a `value_type` with a noexcept copy constructor and no move constructor also satisfies this condition and will thus guarantee the strong exception guarantee for the structure (see [API](https://tessil.github.io/robin-map/classtsl_1_1robin__map.html#details) for details). -- The type `Key`, and also `T` in case of map, must be swappable. +- The type `Key`, and also `T` in case of map, must be swappable. They must also be copy and/or move constructible. - Iterator invalidation doesn't behave in the same way, any operation modifying the hash table invalidate them (see [API](https://tessil.github.io/robin-map/classtsl_1_1robin__map.html#details) for details). - References and pointers to keys or values in the map are invalidated in the same way as iterators to these keys-values. - For iterators of `tsl::robin_map`, `operator*()` and `operator->()` return a reference and a pointer to `const std::pair` instead of `std::pair` making the value `T` not modifiable. To modify the value you have to call the `value()` method of the iterator to get a mutable reference. Example: diff --git a/include/tsl/robin_map.h b/include/tsl/robin_map.h index 38bb7ed..38b8cfd 100644 --- a/include/tsl/robin_map.h +++ b/include/tsl/robin_map.h @@ -66,6 +66,8 @@ namespace tsl { * * `std::pair` must be swappable. * + * `Key` and `T` must be copy and/or move constructible. + * * If the destructor of `Key` or `T` throws an exception, the behaviour of the class is undefined. * * Iterators invalidation: diff --git a/include/tsl/robin_set.h b/include/tsl/robin_set.h index f056061..c3cf42f 100644 --- a/include/tsl/robin_set.h +++ b/include/tsl/robin_set.h @@ -66,6 +66,8 @@ namespace tsl { * * `Key` must be swappable. * + * `Key` must be copy and/or move constructible. + * * If the destructor of `Key` throws an exception, the behaviour of the class is undefined. * * Iterators invalidation: