The title says it all, I'll provide some context though. I'm trying to create an iterator for my Dictionary
class and I've decided not to nest one inside the other. Therefore the iterator constructors must be private since I don't want them being used without the Dictionary
class. At the same time I'm trying to use a technique I just came across called tagging to overload the default constructor depending on where I want the iterator initialized (begin or end of my container).
The point here is not if the way I'm doing it is the best or most optimal but if, as the title says, declaring a explicit private constructor makes sense. I use explicit
here because the constructors take one parameter.
template <typename Container>
class DictionaryIterator
{
public:
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = typename Container::ValueType;
using pointer = value_type*;
using reference = value_type&;
// Special case since this container is node-based.
using node_type = typename Container::Node;
// Tag dispatch mechanism
struct BeginTag {} construct_at_begin;
struct EndTag {} construct_at_end;
private:
explicit DictionaryIterator(BeginTag)
{
// Do stuff
}
explicit DictionaryIterator(EndTag)
{
// Do stuff the other way around
}
};