Skip to content

Commit

Permalink
Simplify ColumnDefinition using C++20 features
Browse files Browse the repository at this point in the history
1. Default comparison: https://en.cppreference.com/w/cpp/language/default_comparisons
2. Parentheses initialization for aggregate types
  • Loading branch information
glebm committed Sep 2, 2023
1 parent 2644ec7 commit 275584f
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions Source/data/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,16 @@
namespace devilution {

struct ColumnDefinition {
uint8_t type;

enum class Error {
UnknownColumn
};

uint8_t type = std::numeric_limits<uint8_t>::max();

// The number of fields between this column and the last one identified as important (or from start of the record if this is the first column we care about)
unsigned skipLength = 0;

ColumnDefinition()
: type(std::numeric_limits<uint8_t>::max())
{
}

ColumnDefinition(unsigned type)
: type(type)
{
}

ColumnDefinition(unsigned type, unsigned skipLength)
: type(type)
, skipLength(skipLength)
{
}

bool operator==(const ColumnDefinition &other) const
{
return type == other.type && skipLength == other.skipLength;
}
bool operator==(const ColumnDefinition &other) const = default;

template <typename T>
explicit operator T() const
Expand Down

0 comments on commit 275584f

Please sign in to comment.