Use a mutable field instead of const_cast

This commit is contained in:
Celtic Minstrel 2016-04-15 14:16:54 -04:00
parent afb85a2000
commit c50e941af7
2 changed files with 2 additions and 2 deletions

View file

@ -142,7 +142,7 @@ std::string context_free_grammar_generator::print_nonterminal(const std::string&
picked = seed[seed_pos++] % got.possibilities_.size();
if (seed_pos >= seed_size) seed_pos = 0;
}
const_cast<unsigned int&>(got.last_) = picked; /* The variable last_ can change, the rest must stay const */
got.last_ = picked;
const std::vector<std::string>& used = got.possibilities_[picked];
for (unsigned int i = 0; i < used.size(); i++) {
if (used[i][0] == '{') result += print_nonterminal(used[i].substr(1), seed, seed_pos);

View file

@ -29,7 +29,7 @@ private:
struct nonterminal {
nonterminal() : last_(1) {}
std::vector<std::vector<std::string> > possibilities_;
unsigned int last_;
mutable unsigned int last_;
};
std::map<std::string, nonterminal> nonterminals_;