* strong exception guarantee applies
* a test to avoid future regressions
This commit is contained in:
Michele Caini
2022-02-22 15:03:07 +01:00
parent 507bafdd9c
commit cdd029853b
3 changed files with 21 additions and 3 deletions

1
TODO
View File

@@ -5,6 +5,7 @@
WIP:
* uses-allocator construction: dense map, compressed pair, any (with allocator support), cache, dispatcher, poly, ...
* add an ENTT_NOEXCEPT with args and use it to make ie compressed_pair conditionally noexcept
* process scheduler: reviews, use free lists internally
* runtime events (emitter)
* iterator based try_emplace vs try_insert for perf reasons

View File

@@ -140,7 +140,7 @@ public:
static constexpr auto alignment = Align;
/*! @brief Default constructor. */
basic_any() ENTT_NOEXCEPT
constexpr basic_any() ENTT_NOEXCEPT
: instance{},
info{&type_id<void>()},
vtable{},
@@ -184,7 +184,7 @@ public:
* @brief Move constructor.
* @param other The instance to move from.
*/
basic_any(basic_any &&other)
basic_any(basic_any &&other) ENTT_NOEXCEPT
: instance{},
info{other.info},
vtable{other.vtable},
@@ -221,7 +221,7 @@ public:
* @param other The instance to move from.
* @return This any object.
*/
basic_any &operator=(basic_any &&other) {
basic_any &operator=(basic_any &&other) ENTT_NOEXCEPT {
reset();
if(other.vtable) {

View File

@@ -1293,6 +1293,23 @@ TEST_F(Any, NotCopyableType) {
ASSERT_TRUE(copy.owner());
}
TEST_F(Any, NotCopyableValueType) {
std::vector<entt::any> vec{};
vec.emplace_back(std::in_place_type<not_copyable>);
vec.shrink_to_fit();
ASSERT_EQ(vec.size(), 1u);
ASSERT_EQ(vec.capacity(), 1u);
ASSERT_TRUE(vec[0u]);
// strong exception guarantee due to noexcept move ctor
vec.emplace_back(std::in_place_type<not_copyable>);
ASSERT_EQ(vec.size(), 2u);
ASSERT_TRUE(vec[0u]);
ASSERT_TRUE(vec[1u]);
}
TEST_F(Any, NotMovableType) {
entt::any any{std::in_place_type<not_movable>};
entt::any other{std::in_place_type<not_movable>};