[cfe-commits] [libcxx] r111742 - in /libcxx/trunk: include/ test/algorithms/alg.sorting/alg.min.max/
Howard Hinnant
hhinnant at apple.com
Sat Aug 21 13:10:01 PDT 2010
Author: hhinnant
Date: Sat Aug 21 15:10:01 2010
New Revision: 111742
URL: http://llvm.org/viewvc/llvm-project?rev=111742&view=rev
Log:
US 122, N3106
Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp
libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp
libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp
libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp
libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp
libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp
libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Sat Aug 21 15:10:01 2010
@@ -485,29 +485,29 @@
RandomAccessIterator
is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
-template <class T>
- const T&
- min(const T& a, const T& b);
+template <class ForwardIterator>
+ ForwardIterator
+ min_element(ForwardIterator first, ForwardIterator last);
-template <class T, class Compare>
- const T&
- min(const T& a, const T& b, Compare comp);
+template <class ForwardIterator, class Compare>
+ ForwardIterator
+ min_element(ForwardIterator first, ForwardIterator last, Compare comp);
template <class T>
const T&
- max(const T& a, const T& b);
+ min(const T& a, const T& b);
template <class T, class Compare>
const T&
- max(const T& a, const T& b, Compare comp);
-
-template <class ForwardIterator>
- ForwardIterator
- min_element(ForwardIterator first, ForwardIterator last);
+ min(const T& a, const T& b, Compare comp);
-template <class ForwardIterator, class Compare>
- ForwardIterator
- min_element(ForwardIterator first, ForwardIterator last, Compare comp);
+template<class T>
+ T
+ min(initializer_list<T> t);
+
+template<class T, class Compare>
+ T
+ min(initializer_list<T> t, Compare comp);
template <class ForwardIterator>
ForwardIterator
@@ -517,6 +517,46 @@
ForwardIterator
max_element(ForwardIterator first, ForwardIterator last, Compare comp);
+template <class T>
+ const T&
+ max(const T& a, const T& b);
+
+template <class T, class Compare>
+ const T&
+ max(const T& a, const T& b, Compare comp);
+
+template<class T>
+ T
+ max(initializer_list<T> t);
+
+template<class T, class Compare>
+ T
+ max(initializer_list<T> t, Compare comp);
+
+template<class ForwardIterator>
+ pair<ForwardIterator, ForwardIterator>
+ minmax_element(ForwardIterator first, ForwardIterator last);
+
+template<class ForwardIterator, class Compare>
+ pair<ForwardIterator, ForwardIterator>
+ minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
+
+template<class T>
+ pair<const T&, const T&>
+ minmax(const T& a, const T& b);
+
+template<class T, class Compare>
+ pair<const T&, const T&>
+ minmax(const T& a, const T& b, Compare comp);
+
+template<class T>
+ pair<T, T>
+ minmax(initializer_list<T> t);
+
+template<class T, class Compare>
+ pair<T, T>
+ minmax(initializer_list<T> t, Compare comp);
+
template <class InputIterator1, class InputIterator2>
bool
lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
@@ -2147,6 +2187,32 @@
return _STD::copy(__first, __middle, _STD::copy(__middle, __last, __result));
}
+// min_element
+
+template <class _ForwardIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+ if (__first != __last)
+ {
+ _ForwardIterator __i = __first;
+ while (++__i != __last)
+ if (__comp(*__i, *__first))
+ __first = __i;
+ }
+ return __first;
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+min_element(_ForwardIterator __first, _ForwardIterator __last)
+{
+ return _STD::min_element(__first, __last,
+ __less<typename iterator_traits<_ForwardIterator>::value_type>());
+}
+
// min
template <class _Tp, class _Compare>
@@ -2165,36 +2231,34 @@
return _STD::min(__a, __b, __less<_Tp>());
}
-// max
-
-template <class _Tp, class _Compare>
+template<class _Tp, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
-const _Tp&
-max(const _Tp& __a, const _Tp& __b, _Compare __comp)
+_Tp
+min(initializer_list<_Tp> __t, _Compare __comp)
{
- return __comp(__a, __b) ? __b : __a;
+ return *_STD::min_element(__t.begin(), __t.end(), __comp);
}
-template <class _Tp>
+template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-const _Tp&
-max(const _Tp& __a, const _Tp& __b)
+_Tp
+min(initializer_list<_Tp> __t)
{
- return _STD::max(__a, __b, __less<_Tp>());
+ return *_STD::min_element(__t.begin(), __t.end());
}
-// min_element
+// max_element
template <class _ForwardIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
-min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
- if (__comp(*__i, *__first))
+ if (__comp(*__first, *__i))
__first = __i;
}
return __first;
@@ -2203,34 +2267,44 @@
template <class _ForwardIterator>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
-min_element(_ForwardIterator __first, _ForwardIterator __last)
+max_element(_ForwardIterator __first, _ForwardIterator __last)
{
- return _STD::min_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+ return _STD::max_element(__first, __last,
+ __less<typename iterator_traits<_ForwardIterator>::value_type>());
}
-// max_element
+// max
-template <class _ForwardIterator, class _Compare>
+template <class _Tp, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
-_ForwardIterator
-max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+const _Tp&
+max(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
- if (__first != __last)
- {
- _ForwardIterator __i = __first;
- while (++__i != __last)
- if (__comp(*__first, *__i))
- __first = __i;
- }
- return __first;
+ return __comp(__a, __b) ? __b : __a;
}
-template <class _ForwardIterator>
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-_ForwardIterator
-max_element(_ForwardIterator __first, _ForwardIterator __last)
+const _Tp&
+max(const _Tp& __a, const _Tp& __b)
{
- return _STD::max_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+ return _STD::max(__a, __b, __less<_Tp>());
+}
+
+template<class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+max(initializer_list<_Tp> __t, _Compare __comp)
+{
+ return *_STD::max_element(__t.begin(), __t.end(), __comp);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+max(initializer_list<_Tp> __t)
+{
+ return *_STD::max_element(__t.begin(), __t.end());
}
// minmax_element
@@ -2293,6 +2367,45 @@
return _STD::minmax_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
}
+// minmax
+
+template<class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<const _Tp&, const _Tp&>
+minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
+{
+ return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) :
+ pair<const _Tp&, const _Tp&>(__a, __b);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<const _Tp&, const _Tp&>
+minmax(const _Tp& __a, const _Tp& __b)
+{
+ return _STD::minmax(__a, __b, __less<_Tp>());
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_Tp, _Tp>
+minmax(initializer_list<_Tp> __t)
+{
+ pair<const _Tp*, const _Tp*> __p =
+ _STD::minmax_element(__t.begin(), __t.end());
+ return pair<_Tp, _Tp>(*__p.first, *__p.second);
+}
+
+template<class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_Tp, _Tp>
+minmax(initializer_list<_Tp> __t, _Compare __comp)
+{
+ pair<const _Tp*, const _Tp*> __p =
+ _STD::minmax_element(__t.begin(), __t.end(), __comp);
+ return pair<_Tp, _Tp>(*__p.first, *__p.second);
+}
+
// random_shuffle
// __independent_bits_engine
Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list.pass.cpp Sat Aug 21 15:10:01 2010
@@ -16,8 +16,20 @@
#include <algorithm>
#include <cassert>
-#error max(initializer_list<T> t) is not implemented
-
int main()
{
+#ifdef _LIBCPP_MOVE
+ int i = std::max({2, 3, 1});
+ assert(i == 3);
+ i = std::max({2, 1, 3});
+ assert(i == 3);
+ i = std::max({3, 1, 2});
+ assert(i == 3);
+ i = std::max({3, 2, 1});
+ assert(i == 3);
+ i = std::max({1, 2, 3});
+ assert(i == 3);
+ i = std::max({1, 3, 2});
+ assert(i == 3);
+#endif
}
Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_init_list_comp.pass.cpp Sat Aug 21 15:10:01 2010
@@ -14,10 +14,23 @@
// max(initializer_list<T> t, Compare comp);
#include <algorithm>
+#include <functional>
#include <cassert>
-#error max(initializer_list<T> t, Compare comp) is not implemented
-
int main()
{
+#ifdef _LIBCPP_MOVE
+ int i = std::max({2, 3, 1}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({2, 1, 3}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({3, 1, 2}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({3, 2, 1}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({1, 2, 3}, std::greater<int>());
+ assert(i == 1);
+ i = std::max({1, 3, 2}, std::greater<int>());
+ assert(i == 1);
+#endif
}
Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list.pass.cpp Sat Aug 21 15:10:01 2010
@@ -16,8 +16,20 @@
#include <algorithm>
#include <cassert>
-#error min(initializer_list<T> t) is not implemented
-
int main()
{
+#ifdef _LIBCPP_MOVE
+ int i = std::min({2, 3, 1});
+ assert(i == 1);
+ i = std::min({2, 1, 3});
+ assert(i == 1);
+ i = std::min({3, 1, 2});
+ assert(i == 1);
+ i = std::min({3, 2, 1});
+ assert(i == 1);
+ i = std::min({1, 2, 3});
+ assert(i == 1);
+ i = std::min({1, 3, 2});
+ assert(i == 1);
+#endif
}
Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_init_list_comp.pass.cpp Sat Aug 21 15:10:01 2010
@@ -14,10 +14,23 @@
// min(initializer_list<T> t, Compare comp);
#include <algorithm>
+#include <functional>
#include <cassert>
-#error min(initializer_list<T> t, Compare comp) is not implemented
-
int main()
{
+#ifdef _LIBCPP_MOVE
+ int i = std::min({2, 3, 1}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({2, 1, 3}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({3, 1, 2}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({3, 2, 1}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({1, 2, 3}, std::greater<int>());
+ assert(i == 3);
+ i = std::min({1, 3, 2}, std::greater<int>());
+ assert(i == 3);
+#endif
}
Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_comp.pass.cpp Sat Aug 21 15:10:01 2010
@@ -38,13 +38,13 @@
{
int x = 0;
int y = 1;
- test(x, y, std::greater<int>(), x, y);
- test(y, x, std::greater<int>(), x, y);
+ test(x, y, std::greater<int>(), y, x);
+ test(y, x, std::greater<int>(), y, x);
}
{
int x = 1;
int y = 0;
- test(x, y, std::greater<int>(), y, x);
- test(y, x, std::greater<int>(), y, x);
+ test(x, y, std::greater<int>(), x, y);
+ test(y, x, std::greater<int>(), x, y);
}
}
Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list.pass.cpp Sat Aug 21 15:10:01 2010
@@ -10,14 +10,20 @@
// <algorithm>
// template<class T>
-// pair<const T&, const T&>
+// pair<T, T>
// minmax(initializer_list<T> t);
#include <algorithm>
#include <cassert>
-#error minmax(initializer_list<T> t) is not implemented
-
int main()
{
+#ifdef _LIBCPP_MOVE
+ assert((std::minmax({1, 2, 3}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({1, 3, 2}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({2, 1, 3}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({2, 3, 1}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({3, 1, 2}) == std::pair<int, int>(1, 3)));
+ assert((std::minmax({3, 2, 1}) == std::pair<int, int>(1, 3)));
+#endif
}
Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp?rev=111742&r1=111741&r2=111742&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp Sat Aug 21 15:10:01 2010
@@ -10,14 +10,21 @@
// <algorithm>
// template<class T, class Compare>
-// pair<const T&, const T&>
+// pair<T, T>
// minmax(initializer_list<T> t, Compare comp);
#include <algorithm>
+#include <functional>
#include <cassert>
-#error minmax(initializer_list<T> t, Compare comp) is not implemented
-
int main()
{
+#ifdef _LIBCPP_MOVE
+ assert((std::minmax({1, 2, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({1, 3, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({2, 1, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({2, 3, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({3, 1, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+ assert((std::minmax({3, 2, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)));
+#endif
}
More information about the cfe-commits
mailing list