@@ -57,16 +57,16 @@ class DFA
57
57
}
58
58
59
59
// ! Retrieves the alphabet of this finite automaton.
60
- Alphabet alphabet () const ;
60
+ [[nodiscard]] Alphabet alphabet () const ;
61
61
62
62
// ! Retrieves the initial state.
63
- StateId initialState () const { return initialState_; }
63
+ [[nodiscard]] StateId initialState () const { return initialState_; }
64
64
65
65
// ! Retrieves the list of available states.
66
- const StateVec& states () const { return states_; }
67
- StateVec& states () { return states_; }
66
+ [[nodiscard]] const StateVec& states () const { return states_; }
67
+ [[nodiscard]] StateVec& states () { return states_; }
68
68
69
- StateIdVec stateIds () const
69
+ [[nodiscard]] StateIdVec stateIds () const
70
70
{
71
71
StateIdVec v;
72
72
v.reserve (states_.size ());
@@ -76,7 +76,7 @@ class DFA
76
76
}
77
77
78
78
// ! Retrieves the list of accepting states.
79
- std::vector<StateId> acceptStates () const ;
79
+ [[nodiscard]] std::vector<StateId> acceptStates () const ;
80
80
81
81
/* *
82
82
* Traverses all states and edges in this NFA and calls @p visitor for each state & edge.
@@ -89,39 +89,39 @@ class DFA
89
89
90
90
void setInitialState (StateId state);
91
91
92
- const TransitionMap& stateTransitions (StateId id) const
92
+ [[nodiscard]] const TransitionMap& stateTransitions (StateId id) const
93
93
{
94
94
return states_[static_cast <size_t >(id)].transitions ;
95
95
}
96
96
97
97
// {{{ backtracking (for lookahead)
98
98
void setBacktrack (StateId from, StateId to) { backtrackStates_[from] = to; }
99
99
100
- std::optional<StateId> backtrack (StateId acceptState) const
100
+ [[nodiscard]] std::optional<StateId> backtrack (StateId acceptState) const
101
101
{
102
102
if (auto i = backtrackStates_.find (acceptState); i != backtrackStates_.end ())
103
103
return i->second ;
104
104
105
105
return std::nullopt;
106
106
}
107
107
108
- const BacktrackingMap& backtracking () const noexcept { return backtrackStates_; }
108
+ [[nodiscard]] const BacktrackingMap& backtracking () const noexcept { return backtrackStates_; }
109
109
// }}}
110
110
111
111
// ! Flags given state as accepting-state with given Tag @p acceptTag.
112
112
void setAccept (StateId state, Tag acceptTag) { acceptTags_[state] = acceptTag; }
113
113
114
- bool isAccepting (StateId s) const { return acceptTags_.find (s) != acceptTags_.end (); }
114
+ [[nodiscard]] bool isAccepting (StateId s) const { return acceptTags_.find (s) != acceptTags_.end (); }
115
115
116
- std::optional<Tag> acceptTag (StateId s) const
116
+ [[nodiscard]] std::optional<Tag> acceptTag (StateId s) const
117
117
{
118
118
if (auto i = acceptTags_.find (s); i != acceptTags_.end ())
119
119
return i->second ;
120
120
121
121
return std::nullopt;
122
122
}
123
123
124
- std::optional<StateId> delta (StateId state, Symbol symbol) const
124
+ [[nodiscard]] std::optional<StateId> delta (StateId state, Symbol symbol) const
125
125
{
126
126
const auto & T = states_[state].transitions ;
127
127
if (auto i = T.find (symbol); i != T.end ())
@@ -133,7 +133,7 @@ class DFA
133
133
void setTransition (StateId from, Symbol symbol, StateId to);
134
134
void removeTransition (StateId from, Symbol symbol);
135
135
136
- StateIdVec nonAcceptStates () const
136
+ [[nodiscard]] StateIdVec nonAcceptStates () const
137
137
{
138
138
StateIdVec result;
139
139
result.reserve (
@@ -146,9 +146,9 @@ class DFA
146
146
return result;
147
147
}
148
148
149
- bool isAcceptor (Tag t) const
149
+ [[nodiscard]] bool isAcceptor (Tag t) const
150
150
{
151
- for (const std::pair<StateId, Tag>& p: acceptTags_)
151
+ for (std::pair<StateId, Tag> p: acceptTags_)
152
152
if (p.second == t)
153
153
return true ;
154
154
0 commit comments