Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ version: 17
- // filename: CardEncyclopedia
- #pragma once
- #include <vector>
- struct Card
- {
- bool operator!=(const Card& other) const noexcept
- {
- return false;
- }
- };
- class CardEncyclopedia
- {
- std::vector<const Card&> cards;
- public:
- // the content of the function block below will be highlighted in its entirety
- // the given warning is: "Redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]"
- // after the tidy operation the content of the block will be reduced down to one line: return !;
- bool operator==(const CardEncyclopedia& other) noexcept
- {
- if (cards.size() != other.cards.size())
- return false;
- for (size_t i = 0; i < other.cards.size(); ++i)
- if (cards.at(i) != other.cards.at(i))
- return false;
- return true;
- }
- };
- // Note that vectors should not accept references because the component type of containers, like vectors,
- // must be re-assignable and references are not re-assignable. However, the compiler will not stop you from doing this.
- // This same issue also exists when using const pointers (because again; they are not re-assignable).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement