Reputation: 2096
Here in this article, the guy is writing an STL compatible prefix tree.
Then we have the selectors and mutators.
/* Selectors */ const_iterator find(const key_type& key) const; size_type size() const; size_type max_size() const; bool empty() const; reference at(const key_type& key); const_reference at(const key_type& key) const; /* Mutators */ iterator find(const key_type& key); std::pair<iterator, bool> insert(const key_type& key, const mapped_type& value); std::pair<iterator, bool> insert(const value_type& value); iterator insert(const_iterator hint, const value_type& value); reference operator[] (const key_type& key); void erase(const key_type& key); iterator erase(iterator pos); void clear();
I though first that they are something like setters
and getters
. the selectors
get some data stored inside or about the container, and the mutators
mutate the state of the container. But looks like it's a bit different. for example, there is a selector function called at
that returns a non-const reference type (I think this way the content of the container can be changed). What is the difinition of Selectors
and Mutators
?
Upvotes: 2
Views: 878
Reputation: 122726
Those are just names the author of the code chose, not terms that have a formal definition. From context it is clear that they call "Mutators" anything that modifes the container, and "Selectors" anything that allows to get an element from the container or get information on the container. Though, they are not quite consistent, because find
does not mutate the container and I would rather list it under "Selectors".
there is a selector function called at that returns a non-const reference type
Perhaps the reasoning was that the reference allows the caller to modify the element in the container, not the container itself.
Upvotes: 2