Fix for LWG Issue 2369: constexpr max(initializer_list) vs max_element
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@236952 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -521,11 +521,11 @@ template <class RandomAccessIterator, class Compare>
|
|||||||
|
|
||||||
template <class ForwardIterator>
|
template <class ForwardIterator>
|
||||||
ForwardIterator
|
ForwardIterator
|
||||||
min_element(ForwardIterator first, ForwardIterator last);
|
min_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14
|
||||||
|
|
||||||
template <class ForwardIterator, class Compare>
|
template <class ForwardIterator, class Compare>
|
||||||
ForwardIterator
|
ForwardIterator
|
||||||
min_element(ForwardIterator first, ForwardIterator last, Compare comp);
|
min_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
const T&
|
const T&
|
||||||
@@ -545,11 +545,11 @@ template<class T, class Compare>
|
|||||||
|
|
||||||
template <class ForwardIterator>
|
template <class ForwardIterator>
|
||||||
ForwardIterator
|
ForwardIterator
|
||||||
max_element(ForwardIterator first, ForwardIterator last);
|
max_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14
|
||||||
|
|
||||||
template <class ForwardIterator, class Compare>
|
template <class ForwardIterator, class Compare>
|
||||||
ForwardIterator
|
ForwardIterator
|
||||||
max_element(ForwardIterator first, ForwardIterator last, Compare comp);
|
max_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
const T&
|
const T&
|
||||||
@@ -569,11 +569,11 @@ template<class T, class Compare>
|
|||||||
|
|
||||||
template<class ForwardIterator>
|
template<class ForwardIterator>
|
||||||
pair<ForwardIterator, ForwardIterator>
|
pair<ForwardIterator, ForwardIterator>
|
||||||
minmax_element(ForwardIterator first, ForwardIterator last);
|
minmax_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14
|
||||||
|
|
||||||
template<class ForwardIterator, class Compare>
|
template<class ForwardIterator, class Compare>
|
||||||
pair<ForwardIterator, ForwardIterator>
|
pair<ForwardIterator, ForwardIterator>
|
||||||
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
|
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
pair<const T&, const T&>
|
pair<const T&, const T&>
|
||||||
@@ -2544,7 +2544,7 @@ rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterato
|
|||||||
template <class _ForwardIterator, class _Compare>
|
template <class _ForwardIterator, class _Compare>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
_ForwardIterator
|
_ForwardIterator
|
||||||
__min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||||
{
|
{
|
||||||
if (__first != __last)
|
if (__first != __last)
|
||||||
{
|
{
|
||||||
@@ -2556,20 +2556,12 @@ __min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp
|
|||||||
return __first;
|
return __first;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _ForwardIterator, class _Compare>
|
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
|
||||||
_ForwardIterator
|
|
||||||
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
|
||||||
{
|
|
||||||
return __min_element(__first, __last, __comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class _ForwardIterator>
|
template <class _ForwardIterator>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
_ForwardIterator
|
_ForwardIterator
|
||||||
min_element(_ForwardIterator __first, _ForwardIterator __last)
|
min_element(_ForwardIterator __first, _ForwardIterator __last)
|
||||||
{
|
{
|
||||||
return __min_element(__first, __last,
|
return _VSTD::min_element(__first, __last,
|
||||||
__less<typename iterator_traits<_ForwardIterator>::value_type>());
|
__less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2598,7 +2590,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|||||||
_Tp
|
_Tp
|
||||||
min(initializer_list<_Tp> __t, _Compare __comp)
|
min(initializer_list<_Tp> __t, _Compare __comp)
|
||||||
{
|
{
|
||||||
return *__min_element(__t.begin(), __t.end(), __comp);
|
return *_VSTD::min_element(__t.begin(), __t.end(), __comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class _Tp>
|
template<class _Tp>
|
||||||
@@ -2606,7 +2598,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|||||||
_Tp
|
_Tp
|
||||||
min(initializer_list<_Tp> __t)
|
min(initializer_list<_Tp> __t)
|
||||||
{
|
{
|
||||||
return *__min_element(__t.begin(), __t.end(), __less<_Tp>());
|
return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||||
@@ -2616,7 +2608,7 @@ min(initializer_list<_Tp> __t)
|
|||||||
template <class _ForwardIterator, class _Compare>
|
template <class _ForwardIterator, class _Compare>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
_ForwardIterator
|
_ForwardIterator
|
||||||
__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||||
{
|
{
|
||||||
if (__first != __last)
|
if (__first != __last)
|
||||||
{
|
{
|
||||||
@@ -2629,20 +2621,12 @@ __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class _ForwardIterator, class _Compare>
|
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
|
||||||
_ForwardIterator
|
|
||||||
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
|
||||||
{
|
|
||||||
return __max_element(__first, __last, __comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class _ForwardIterator>
|
template <class _ForwardIterator>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
_ForwardIterator
|
_ForwardIterator
|
||||||
max_element(_ForwardIterator __first, _ForwardIterator __last)
|
max_element(_ForwardIterator __first, _ForwardIterator __last)
|
||||||
{
|
{
|
||||||
return __max_element(__first, __last,
|
return _VSTD::max_element(__first, __last,
|
||||||
__less<typename iterator_traits<_ForwardIterator>::value_type>());
|
__less<typename iterator_traits<_ForwardIterator>::value_type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2671,7 +2655,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|||||||
_Tp
|
_Tp
|
||||||
max(initializer_list<_Tp> __t, _Compare __comp)
|
max(initializer_list<_Tp> __t, _Compare __comp)
|
||||||
{
|
{
|
||||||
return *__max_element(__t.begin(), __t.end(), __comp);
|
return *_VSTD::max_element(__t.begin(), __t.end(), __comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class _Tp>
|
template<class _Tp>
|
||||||
@@ -2679,7 +2663,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|||||||
_Tp
|
_Tp
|
||||||
max(initializer_list<_Tp> __t)
|
max(initializer_list<_Tp> __t)
|
||||||
{
|
{
|
||||||
return *__max_element(__t.begin(), __t.end(), __less<_Tp>());
|
return *_VSTD::max_element(__t.begin(), __t.end(), __less<_Tp>());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||||
@@ -2687,6 +2671,7 @@ max(initializer_list<_Tp> __t)
|
|||||||
// minmax_element
|
// minmax_element
|
||||||
|
|
||||||
template <class _ForwardIterator, class _Compare>
|
template <class _ForwardIterator, class _Compare>
|
||||||
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
std::pair<_ForwardIterator, _ForwardIterator>
|
std::pair<_ForwardIterator, _ForwardIterator>
|
||||||
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
|
||||||
{
|
{
|
||||||
@@ -2734,7 +2719,7 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __com
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class _ForwardIterator>
|
template <class _ForwardIterator>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
std::pair<_ForwardIterator, _ForwardIterator>
|
std::pair<_ForwardIterator, _ForwardIterator>
|
||||||
minmax_element(_ForwardIterator __first, _ForwardIterator __last)
|
minmax_element(_ForwardIterator __first, _ForwardIterator __last)
|
||||||
{
|
{
|
||||||
|
@@ -57,10 +57,24 @@ test()
|
|||||||
test<Iter>(1000);
|
test<Iter>(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void constexpr_test()
|
||||||
|
{
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr auto p = std::max_element(il,il+8);
|
||||||
|
static_assert ( *p == 8, "" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test<forward_iterator<const int*> >();
|
test<forward_iterator<const int*> >();
|
||||||
test<bidirectional_iterator<const int*> >();
|
test<bidirectional_iterator<const int*> >();
|
||||||
test<random_access_iterator<const int*> >();
|
test<random_access_iterator<const int*> >();
|
||||||
test<const int*>();
|
test<const int*>();
|
||||||
|
|
||||||
|
constexpr_test ();
|
||||||
}
|
}
|
||||||
|
@@ -75,6 +75,19 @@ void test_eq()
|
|||||||
delete [] a;
|
delete [] a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
|
||||||
|
struct less { constexpr bool operator ()( const int &x, const int &y) const { return x < y; }};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void constexpr_test()
|
||||||
|
{
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr auto p = std::max_element(il, il+8, less());
|
||||||
|
static_assert ( *p == 8, "" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test<forward_iterator<const int*> >();
|
test<forward_iterator<const int*> >();
|
||||||
@@ -82,4 +95,6 @@ int main()
|
|||||||
test<random_access_iterator<const int*> >();
|
test<random_access_iterator<const int*> >();
|
||||||
test<const int*>();
|
test<const int*>();
|
||||||
test_eq();
|
test_eq();
|
||||||
|
|
||||||
|
constexpr_test();
|
||||||
}
|
}
|
||||||
|
@@ -57,10 +57,24 @@ test()
|
|||||||
test<Iter>(1000);
|
test<Iter>(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void constexpr_test()
|
||||||
|
{
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr auto p = std::min_element(il, il+8);
|
||||||
|
static_assert ( *p == 1, "" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test<forward_iterator<const int*> >();
|
test<forward_iterator<const int*> >();
|
||||||
test<bidirectional_iterator<const int*> >();
|
test<bidirectional_iterator<const int*> >();
|
||||||
test<random_access_iterator<const int*> >();
|
test<random_access_iterator<const int*> >();
|
||||||
test<const int*>();
|
test<const int*>();
|
||||||
|
|
||||||
|
constexpr_test();
|
||||||
}
|
}
|
||||||
|
@@ -75,6 +75,19 @@ void test_eq()
|
|||||||
delete [] a;
|
delete [] a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
|
||||||
|
struct less { constexpr bool operator ()( const int &x, const int &y) const { return x < y; }};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void constexpr_test()
|
||||||
|
{
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr auto p = std::min_element(il, il+8, less());
|
||||||
|
static_assert(*p == 1, "");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test<forward_iterator<const int*> >();
|
test<forward_iterator<const int*> >();
|
||||||
@@ -82,4 +95,6 @@ int main()
|
|||||||
test<random_access_iterator<const int*> >();
|
test<random_access_iterator<const int*> >();
|
||||||
test<const int*>();
|
test<const int*>();
|
||||||
test_eq();
|
test_eq();
|
||||||
|
|
||||||
|
constexpr_test();
|
||||||
}
|
}
|
||||||
|
@@ -74,10 +74,25 @@ test()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void constexpr_test()
|
||||||
|
{
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr auto p = std::minmax_element(il, il+8);
|
||||||
|
static_assert ( *(p.first) == 1, "" );
|
||||||
|
static_assert ( *(p.second) == 8, "" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test<forward_iterator<const int*> >();
|
test<forward_iterator<const int*> >();
|
||||||
test<bidirectional_iterator<const int*> >();
|
test<bidirectional_iterator<const int*> >();
|
||||||
test<random_access_iterator<const int*> >();
|
test<random_access_iterator<const int*> >();
|
||||||
test<const int*>();
|
test<const int*>();
|
||||||
|
|
||||||
|
constexpr_test();
|
||||||
}
|
}
|
||||||
|
@@ -79,10 +79,26 @@ test()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr int il[] = { 2, 4, 6, 8, 7, 5, 3, 1 };
|
||||||
|
struct less { constexpr bool operator ()( const int &x, const int &y) const { return x < y; }};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void constexpr_test()
|
||||||
|
{
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
|
constexpr auto p = std::minmax_element(il, il+8, less());
|
||||||
|
static_assert ( *(p.first) == 1, "" );
|
||||||
|
static_assert ( *(p.second) == 8, "" );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test<forward_iterator<const int*> >();
|
test<forward_iterator<const int*> >();
|
||||||
test<bidirectional_iterator<const int*> >();
|
test<bidirectional_iterator<const int*> >();
|
||||||
test<random_access_iterator<const int*> >();
|
test<random_access_iterator<const int*> >();
|
||||||
test<const int*>();
|
test<const int*>();
|
||||||
|
|
||||||
|
constexpr_test();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user