Add diagnostics for min/max algorithms when a InputIterator is used.
These algorithms require a ForwardIterator or better. Ensure
we diagnose the contract violation at compile time instead of
of silently doing the wrong thing.
Further algorithms will be audited in upcoming patches.
llvm-svn: 340426
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 74a326d..ee2a54d 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -2398,6 +2398,8 @@
_ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
+ static_assert(__is_forward_iterator<_ForwardIterator>::value,
+ "std::min_element requires a ForwardIterator");
if (__first != __last)
{
_ForwardIterator __i = __first;
@@ -2462,6 +2464,8 @@
_ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
+ static_assert(__is_forward_iterator<_ForwardIterator>::value,
+ "std::max_element requires a ForwardIterator");
if (__first != __last)
{
_ForwardIterator __i = __first;
@@ -2548,6 +2552,8 @@
std::pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
+ static_assert(__is_forward_iterator<_ForwardIterator>::value,
+ "std::minmax_element requires a ForwardIterator");
std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first);
if (__first != __last)
{