|
|
@@ -6,36 +6,35 @@
|
|
|
#include <vector>
|
|
|
#include <gtest/gtest.h>
|
|
|
#include <entt/core/compressed_pair.hpp>
|
|
|
+#include "../common/empty.h"
|
|
|
#include "../common/non_default_constructible.h"
|
|
|
|
|
|
-struct empty_type {};
|
|
|
-
|
|
|
TEST(CompressedPair, Size) {
|
|
|
struct local {
|
|
|
int value;
|
|
|
- empty_type empty;
|
|
|
+ test::empty empty;
|
|
|
};
|
|
|
|
|
|
ASSERT_EQ(sizeof(entt::compressed_pair<int, int>), sizeof(int[2u]));
|
|
|
- ASSERT_EQ(sizeof(entt::compressed_pair<empty_type, int>), sizeof(int));
|
|
|
- ASSERT_EQ(sizeof(entt::compressed_pair<int, empty_type>), sizeof(int));
|
|
|
- ASSERT_LT(sizeof(entt::compressed_pair<int, empty_type>), sizeof(local));
|
|
|
- ASSERT_LT(sizeof(entt::compressed_pair<int, empty_type>), sizeof(std::pair<int, empty_type>));
|
|
|
+ ASSERT_EQ(sizeof(entt::compressed_pair<test::empty, int>), sizeof(int));
|
|
|
+ ASSERT_EQ(sizeof(entt::compressed_pair<int, test::empty>), sizeof(int));
|
|
|
+ ASSERT_LT(sizeof(entt::compressed_pair<int, test::empty>), sizeof(local));
|
|
|
+ ASSERT_LT(sizeof(entt::compressed_pair<int, test::empty>), sizeof(std::pair<int, test::empty>));
|
|
|
}
|
|
|
|
|
|
TEST(CompressedPair, ConstructCopyMove) {
|
|
|
- ASSERT_FALSE((std::is_default_constructible_v<entt::compressed_pair<test::non_default_constructible, empty_type>>));
|
|
|
- ASSERT_TRUE((std::is_default_constructible_v<entt::compressed_pair<std::unique_ptr<int>, empty_type>>));
|
|
|
+ ASSERT_FALSE((std::is_default_constructible_v<entt::compressed_pair<test::non_default_constructible, test::empty>>));
|
|
|
+ ASSERT_TRUE((std::is_default_constructible_v<entt::compressed_pair<std::unique_ptr<int>, test::empty>>));
|
|
|
|
|
|
- ASSERT_TRUE((std::is_copy_constructible_v<entt::compressed_pair<test::non_default_constructible, empty_type>>));
|
|
|
- ASSERT_FALSE((std::is_copy_constructible_v<entt::compressed_pair<std::unique_ptr<int>, empty_type>>));
|
|
|
- ASSERT_TRUE((std::is_copy_assignable_v<entt::compressed_pair<test::non_default_constructible, empty_type>>));
|
|
|
- ASSERT_FALSE((std::is_copy_assignable_v<entt::compressed_pair<std::unique_ptr<int>, empty_type>>));
|
|
|
+ ASSERT_TRUE((std::is_copy_constructible_v<entt::compressed_pair<test::non_default_constructible, test::empty>>));
|
|
|
+ ASSERT_FALSE((std::is_copy_constructible_v<entt::compressed_pair<std::unique_ptr<int>, test::empty>>));
|
|
|
+ ASSERT_TRUE((std::is_copy_assignable_v<entt::compressed_pair<test::non_default_constructible, test::empty>>));
|
|
|
+ ASSERT_FALSE((std::is_copy_assignable_v<entt::compressed_pair<std::unique_ptr<int>, test::empty>>));
|
|
|
|
|
|
- ASSERT_TRUE((std::is_move_constructible_v<entt::compressed_pair<std::unique_ptr<int>, empty_type>>));
|
|
|
- ASSERT_TRUE((std::is_move_assignable_v<entt::compressed_pair<std::unique_ptr<int>, empty_type>>));
|
|
|
+ ASSERT_TRUE((std::is_move_constructible_v<entt::compressed_pair<std::unique_ptr<int>, test::empty>>));
|
|
|
+ ASSERT_TRUE((std::is_move_assignable_v<entt::compressed_pair<std::unique_ptr<int>, test::empty>>));
|
|
|
|
|
|
- entt::compressed_pair copyable{test::non_default_constructible{42}, empty_type{}};
|
|
|
+ entt::compressed_pair copyable{test::non_default_constructible{42}, test::empty{}};
|
|
|
auto by_copy{copyable};
|
|
|
|
|
|
ASSERT_EQ(by_copy.first().value, 42);
|
|
|
@@ -45,7 +44,7 @@ TEST(CompressedPair, ConstructCopyMove) {
|
|
|
|
|
|
ASSERT_EQ(copyable.first().value, 3);
|
|
|
|
|
|
- entt::compressed_pair<empty_type, std::unique_ptr<int>> movable{empty_type{}, std::make_unique<int>(99)};
|
|
|
+ entt::compressed_pair<test::empty, std::unique_ptr<int>> movable{test::empty{}, std::make_unique<int>(99)};
|
|
|
auto by_move{std::move(movable)};
|
|
|
|
|
|
ASSERT_EQ(*by_move.second(), 99);
|
|
|
@@ -60,7 +59,7 @@ TEST(CompressedPair, ConstructCopyMove) {
|
|
|
|
|
|
TEST(CompressedPair, PiecewiseConstruct) {
|
|
|
std::vector<int> vec{42};
|
|
|
- entt::compressed_pair<empty_type, empty_type> empty{std::piecewise_construct, std::make_tuple(), std::make_tuple()};
|
|
|
+ entt::compressed_pair<test::empty, test::empty> empty{std::piecewise_construct, std::make_tuple(), std::make_tuple()};
|
|
|
entt::compressed_pair<std::vector<int>, std::size_t> pair{std::piecewise_construct, std::forward_as_tuple(std::move(vec)), std::make_tuple(sizeof(empty))};
|
|
|
|
|
|
ASSERT_EQ(pair.first().size(), 1u);
|
|
|
@@ -70,10 +69,10 @@ TEST(CompressedPair, PiecewiseConstruct) {
|
|
|
|
|
|
TEST(CompressedPair, DeductionGuide) {
|
|
|
int value = 42;
|
|
|
- empty_type empty{};
|
|
|
+ test::empty empty{};
|
|
|
entt::compressed_pair pair{value, 3};
|
|
|
|
|
|
- testing::StaticAssertTypeEq<decltype(entt::compressed_pair{empty_type{}, empty}), entt::compressed_pair<empty_type, empty_type>>();
|
|
|
+ testing::StaticAssertTypeEq<decltype(entt::compressed_pair{test::empty{}, empty}), entt::compressed_pair<test::empty, test::empty>>();
|
|
|
testing::StaticAssertTypeEq<decltype(pair), entt::compressed_pair<int, int>>();
|
|
|
|
|
|
ASSERT_EQ(pair.first(), 42);
|
|
|
@@ -81,14 +80,14 @@ TEST(CompressedPair, DeductionGuide) {
|
|
|
}
|
|
|
|
|
|
TEST(CompressedPair, Getters) {
|
|
|
- entt::compressed_pair pair{3, empty_type{}};
|
|
|
+ entt::compressed_pair pair{3, test::empty{}};
|
|
|
const auto &cpair = pair;
|
|
|
|
|
|
testing::StaticAssertTypeEq<decltype(pair.first()), int &>();
|
|
|
- testing::StaticAssertTypeEq<decltype(pair.second()), empty_type &>();
|
|
|
+ testing::StaticAssertTypeEq<decltype(pair.second()), test::empty &>();
|
|
|
|
|
|
testing::StaticAssertTypeEq<decltype(cpair.first()), const int &>();
|
|
|
- testing::StaticAssertTypeEq<decltype(cpair.second()), const empty_type &>();
|
|
|
+ testing::StaticAssertTypeEq<decltype(cpair.second()), const test::empty &>();
|
|
|
|
|
|
ASSERT_EQ(pair.first(), cpair.first());
|
|
|
ASSERT_EQ(&pair.second(), &cpair.second());
|