Add a "=" operator and a default constructor to tok

This commit is contained in:
Username404 2021-12-29 19:20:12 +01:00
parent 379a230765
commit de5184056c
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 9 additions and 0 deletions

View File

@ -19,6 +19,15 @@ struct tok {
const type toktype;
const std::string toktext;
const unsigned long line;
tok& operator=(const tok& other) {
if (this != &other) {
const_cast<type&>(toktype) = other.toktype;
const_cast<std::string&>(toktext) = other.toktext;
const_cast<unsigned long&>(line) = other.line;
}
return *this;
}
tok(): toktype(UNEXPECTED), toktext(), line(0) {};
tok(const type& Type, std::string_view Text, const decltype(line)& line = 0): toktype(Type), toktext(Text), line(line) {}
explicit tok(const type& Type, const decltype(line)& line = 0): tok(Type, std::string(1, Type), line) {};
friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; }