Following is excerpted from vs 2010 map implementation, this member function is defined in parent class _Tree which is in file xtree .
template<class _Valty>
typename _STD tr1::enable_if<!_STD tr1::is_same<const_iterator,
typename _STD tr1::remove_reference<_Valty>::type>::value,
iterator>::type
insert(const_iterator _Where,
_Valty&& _Val)
{ // try to insert node with value _Val using _Where as a hint
return (_Insert(_Where,
this->_Buynode(_STD forward<_Valty>(_Val))));
}
Actually,this function is iterator insert ( iterator position, const value_type& x ),the interesting part of it is its return type! What does it mean? From what i understand, it disable template instantiation if value_type(i.e. _Valty) is same as const_iterator.
But, in such case, since there is no implicit conversion from const_iterator to value_type, this looks like redundant.
I believe I have something that i don’t understand, what is it? what does the return type template prohibit?
There are other
insertmembers that take a range of objects, [iterator, iterator).The
enable_ifis used to avoid problems with overload resolution by enabling this function only when the types involved are different.