The implementation will normally use some kind of type traits to enable/disable iterator version, depending on if the iterator type is really an iterator or not.
For example, it would conceptually be something like:
template <class InputIterator, typename = enable_if_t<IsIterator_v<InputIterator>>
vector(InputIterator first, InputIteratorLast)
(or more correct to avoid redefinition of templates which defere only in default template arguments, as stated in comments and under this notes:):
// this is more the way it's actually practically implemented
template <class InputIterator, enable_if_t<IsIterator_v<InputIterator>, int> = 0>
vector(InputIterator first, InputIteratorLast)
where IsIterator_v
is implementation defined type trait for testing iterator requirement.
So in your constructor example vector(3, 100)
the iterator constructor version will then not participate in overload resolution.
In C++98 there is no enable_if
, but also then the implementation would use similar kind of concept checks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…