diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-08-02 18:48:27 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-08-02 18:48:27 +0200 |
| commit | 06644a4f989fa9fe673281859734be7a7b72aeac (patch) | |
| tree | 539f9b2636ad61852c0926364179cd5952551781 | |
| parent | 0577e90fd1d73777e0c73995ac83bb2e0fc77db3 (diff) | |
| download | Project-Tick-06644a4f989fa9fe673281859734be7a7b72aeac.tar.gz Project-Tick-06644a4f989fa9fe673281859734be7a7b72aeac.zip | |
Change semantics of empty list equality
I considered making empty lists of undetermined type equal to all empty
lists, but then the comparison would not be transitive
| -rw-r--r-- | include/tag_list.h | 4 | ||||
| -rw-r--r-- | src/tag_list.cpp | 2 | ||||
| -rw-r--r-- | test/nbttest.cpp | 10 |
3 files changed, 8 insertions, 8 deletions
diff --git a/include/tag_list.h b/include/tag_list.h index af5a87d5ee..adb8623f45 100644 --- a/include/tag_list.h +++ b/include/tag_list.h @@ -161,8 +161,8 @@ public: /** * @brief Equality comparison for lists * - * Lists are considered equal if they contain equal tags. Empty lists - * are always considered equal to each other. + * Lists are considered equal if their content types and the contained tags + * are equal. */ friend bool operator==(const tag_list& lhs, const tag_list& rhs); friend bool operator!=(const tag_list& lhs, const tag_list& rhs); diff --git a/src/tag_list.cpp b/src/tag_list.cpp index 34112b3eca..7900f9872e 100644 --- a/src/tag_list.cpp +++ b/src/tag_list.cpp @@ -132,8 +132,6 @@ auto tag_list::cend() const -> const_iterator { return tags.cend(); } bool operator==(const tag_list& lhs, const tag_list& rhs) { - if(lhs.size() == 0 && rhs.size() == 0) - return true; return lhs.el_type_ == rhs.el_type_ && lhs.tags == rhs.tags; } diff --git a/test/nbttest.cpp b/test/nbttest.cpp index 347dad3e3a..c253a5d59b 100644 --- a/test/nbttest.cpp +++ b/test/nbttest.cpp @@ -297,19 +297,21 @@ void test_tag_list() ASSERT(list.size() == 0 && list.el_type() == tag_type::String); EXPECT_EXCEPTION(list.push_back(tag_short(25)), std::bad_cast); EXPECT_EXCEPTION(list.push_back(value(nullptr)), std::bad_cast); - + list.reset(); ASSERT(list.el_type() == tag_type::Null); list.emplace_back<tag_int>(17); ASSERT(list.el_type() == tag_type::Int); - + list.reset(tag_type::Float); ASSERT(list.el_type() == tag_type::Float); list.emplace_back<tag_float>(17.0f); ASSERT(list == tag_list({17.0f})); - ASSERT(tag_list() == tag_list(tag_type::Int)); - ASSERT(tag_list(tag_type::Short) == tag_list(tag_type::Int)); + ASSERT(tag_list() != tag_list(tag_type::Int)); + ASSERT(tag_list() == tag_list()); + ASSERT(tag_list(tag_type::Short) != tag_list(tag_type::Int)); + ASSERT(tag_list(tag_type::Short) == tag_list(tag_type::Short)); tag_list short_list = tag_list::of<tag_short>({25, 36}); ASSERT(short_list.el_type() == tag_type::Short); |
