vs2019 STL库中的 c++ 全局函数的源码

(1)for_each

template <class _Iter>
constexpr decltype(auto) _Get_unwrapped(_Iter&& _It) 
{	// unwrap an iterator previously subjected to _Adl_verify_range or otherwise validated
	if constexpr (is_pointer_v<decay_t<_Iter>>)  // special-case pointers and arrays
		return _It + 0;
	else if constexpr (_Unwrappable_v<_Iter>) 
		return static_cast<_Iter&&>(_It)._Unwrapped();
	else 
		return static_cast<_Iter&&>(_It);
}

template <class _InIt, class _Fn>
_Fn for_each(_InIt _First, _InIt _Last, _Fn _Func)
{ // perform function for each element [_First, _Last)
	_Adl_verify_range(_First, _Last);
	auto _UFirst = _Get_unwrapped(_First);
	const auto _ULast = _Get_unwrapped(_Last);

	for (; _UFirst != _ULast; ++_UFirst) 
		_Func(*_UFirst);

	return _Func;
}

你可能感兴趣的:(c++学习总结,c++,开发语言)