Use a regular constructor instead of aggregate initialization

This commit is contained in:
Max Brunsfeld 2018-06-15 15:33:32 -07:00
parent 8afd99e35e
commit 3fce691fae
2 changed files with 6 additions and 3 deletions

View File

@ -47,7 +47,7 @@ struct Scanner {
unsigned i = 0; unsigned i = 0;
while (i < length) { while (i < length) {
Tag tag { static_cast<TagType>(buffer[i]), "" }; Tag tag(static_cast<TagType>(buffer[i]), "");
i++; i++;
if (tag.type == CUSTOM) { if (tag.type == CUSTOM) {
unsigned length = buffer[i++]; unsigned length = buffer[i++];

View File

@ -303,6 +303,8 @@ struct Tag {
TagType type; TagType type;
string custom_tag_name; string custom_tag_name;
Tag(TagType type, const string &name) : type(type), custom_tag_name(name) {}
bool operator==(const Tag &other) const { bool operator==(const Tag &other) const {
if (type != other.type) return false; if (type != other.type) return false;
if (type == TagType::CUSTOM && custom_tag_name != other.custom_tag_name) return false; if (type == TagType::CUSTOM && custom_tag_name != other.custom_tag_name) return false;
@ -360,8 +362,9 @@ struct Tag {
static inline Tag for_name(const string &name) { static inline Tag for_name(const string &name) {
unordered_map<string, TagType>::const_iterator type = TAG_TYPES_BY_TAG_NAME.find(name); unordered_map<string, TagType>::const_iterator type = TAG_TYPES_BY_TAG_NAME.find(name);
if (type != TAG_TYPES_BY_TAG_NAME.end()) { if (type != TAG_TYPES_BY_TAG_NAME.end()) {
return Tag { type->second, "" }; return Tag(type->second, string());
} else {
return Tag(CUSTOM, name);
} }
return Tag { CUSTOM, name };
} }
}; };