I am doing my first real C ++ project, which is a simple CSV parser (at the very early stage right now), and I have the following in the header file:
class CsvReader {
public:
enum Action { ADD_CHAR, ADD_FIELD, NONE };
enum State { START, IN_FIELD, IN_QUOTED_FIELD, IN_QUOTED_QUOTE };
explicit CsvReader(File& f);
std::vector<std::string> get_row();
private:
State m_state;
LineReader m_lr;
std::tuple<State, Action, bool> next(State s, const char& c);
};
When I want to implement the function next, I was very annoyed to constantly enter CsvReader::before the enumerations, because he made the code so detailed. Therefore, instead of having something like this in the implementation
std::tuple<CsvReader::State, CsvReader::Action, bool> next(CsvReader::State s, const char& c) {
}
I did
typedef CsvReader::State State;
typedef CsvReader::Action Action;
std::tuple<State, Action, bool> CsvReader::next(State s, const char& c) {
}
Except for the fact that I cannot name anything else Stateor Actionin the file, are there any consequences for this? Are there any better solutions?