diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index bd89e6e1346..3c2d291778e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,33 @@ +2008-09-16 Chris Fairles + + * testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc: + New. + * testsuite/25_algorithms/min/requirements/explicit_instantiation/ + pod2.cc: Likewise. + * testsuite/25_algorithms/min/3.cc: Likewise. + * testsuite/25_algorithms/min/4.cc: Likewise. + * testsuite/25_algorithms/max/requirements/explicit_instantiation/3.cc: + Likewise. + * testsuite/25_algorithms/max/requirements/explicit_instantiation/ + pod2.cc: Likewise. + * testsuite/25_algorithms/max/3.cc: Likewise. + * testsuite/25_algorithms/max/4.cc: Likewise. + * testsuite/25_algorithms/minmax/requirements/explicit_instantiation/ + 3.cc: Likewise. + * testsuite/25_algorithms/minmax/requirements/explicit_instantiation/ + pod2.cc: Likewise. + * testsuite/25_algorithms/minmax/2.cc: Likewise. + * testsuite/25_algorithms/minmax/3.cc: Likewise. + +2008-09-16 Paolo Carlini + + * include/bits/stl_algo.h (min(initializer_list<>), + min(initializer_list<>, Compare), max(initializer_list<>), + max(initializer_list<>, Compare), minmax(initializer_list<>), + minmax(initializer_list<>, Compare)): Add in C++0x mode. + * include/bits/algorithmfwd.h: Add. + * testsuite/25_algorithms/headers/algorithm/synopsis.cc: Likewise. + 2008-09-13 Chris Fairles * testsuite/30_threads/thread/algorithm/1.cc: Join thread before diff --git a/libstdc++-v3/include/bits/algorithmfwd.h b/libstdc++-v3/include/bits/algorithmfwd.h index 6fefe46b525..95ff72b79d5 100644 --- a/libstdc++-v3/include/bits/algorithmfwd.h +++ b/libstdc++-v3/include/bits/algorithmfwd.h @@ -115,6 +115,7 @@ #include #include #include +#include _GLIBCXX_BEGIN_NAMESPACE(std) @@ -316,6 +317,30 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template pair<_FIter, _FIter> minmax_element(_FIter, _FIter, _Compare); + + template + const _Tp& + min(initializer_list<_Tp>); + + template + const _Tp& + min(initializer_list<_Tp>, _Compare); + + template + const _Tp& + max(initializer_list<_Tp>); + + template + const _Tp& + max(initializer_list<_Tp>, _Compare); + + template + pair + minmax(initializer_list<_Tp>); + + template + pair + minmax(initializer_list<_Tp>, _Compare); #endif // mismatch diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 40ce60b23ef..42ada9986f3 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -67,6 +67,7 @@ #include #include // for _Temporary_buffer #include +#include // See concept_check.h for the __glibcxx_*_requires macros. @@ -4092,6 +4093,45 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return std::make_pair(__min, __max); } + + // N2722. + template + inline const _Tp& + min(initializer_list<_Tp> __l) + { return *std::min_element(__l.begin(), __l.end()); } + + template + inline const _Tp& + min(initializer_list<_Tp> __l, _Compare __comp) + { return *std::min_element(__l.begin(), __l.end(), __comp); } + + template + inline const _Tp& + max(initializer_list<_Tp> __l) + { return *std::max_element(__l.begin(), __l.end()); } + + template + inline const _Tp& + max(initializer_list<_Tp> __l, _Compare __comp) + { return *std::max_element(__l.begin(), __l.end(), __comp); } + + template + inline pair + minmax(initializer_list<_Tp> __l) + { + pair __p = + std::minmax_element(__l.begin(), __l.end()); + return std::make_pair(*__p.first, *__p.second); + } + + template + inline pair + minmax(initializer_list<_Tp> __l, _Compare __comp) + { + pair __p = + std::minmax_element(__l.begin(), __l.end(), __comp); + return std::make_pair(*__p.first, *__p.second); + } #endif // __GXX_EXPERIMENTAL_CXX0X__ _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc index 2d73e6f15bc..3bc8eb2a764 100644 --- a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc +++ b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc @@ -529,8 +529,32 @@ namespace std minmax_element(_FIter, _FIter); template - pair<_FIter, _FIter> + pair<_FIter, _FIter> minmax_element(_FIter, _FIter, _Compare); + + template + const _Tp& + min(initializer_list<_Tp>); + + template + const _Tp& + min(initializer_list<_Tp>, _Compare); + + template + const _Tp& + max(initializer_list<_Tp>); + + template + const _Tp& + max(initializer_list<_Tp>, _Compare); + + template + pair + minmax(initializer_list<_Tp>); + + template + pair + minmax(initializer_list<_Tp>, _Compare); #endif template diff --git a/libstdc++-v3/testsuite/25_algorithms/max/3.cc b/libstdc++-v3/testsuite/25_algorithms/max/3.cc new file mode 100644 index 00000000000..e3a01159c8a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/max/3.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + const int& x = std::max({1, 3, 2}); + const int& y = std::max({4, 3, 2}); + const int& z = std::max({3, 2, 4}); + VERIFY( x == 3 ); + VERIFY( y == 4 ); + VERIFY( z == 4 ); + + const int& xc = std::max({1, 2, 3}, std::greater()); + const int& yc = std::max({4, 3, 2}, std::greater()); + const int& zc = std::max({2, 4, 3}, std::greater()); + VERIFY( xc == 1 ); + VERIFY( yc == 2 ); + VERIFY( zc == 2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/max/4.cc b/libstdc++-v3/testsuite/25_algorithms/max/4.cc new file mode 100644 index 00000000000..523728f5137 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/max/4.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + const int& z = std::max({1, 2, 3, 4, 5, 6, 7}); + const double& w = std::max({2.0, 1.0, 3.2, 4.5, 5.0, 6.0, 7.0}); + const int& y = std::max({2, 3, 1, 4, 5, 6, 7}); + const float& x = std::max({2.0f, 3.0f, 5.0f, 1.0f, 7.0f, 6.0f}); + VERIFY( z == 7 ); + VERIFY( w == 7.0 ); + VERIFY( y == 7 ); + VERIFY( x == 7.0f ); + + const int& zc = std::max({1, 2, 3, 4, 5, 6, 7}, std::greater()); + const double& wc = std::max({2.0, 1.0, 3.2, 4.5, 5.0}, + std::greater()); + const int& yc = std::max({2, 7, 1, 4, 5, 6, 3}, std::greater()); + const float& xc = std::max({2.0f, 3.0f, 5.0f, 1.0f}, + std::greater()); + + VERIFY( zc == 1 ); + VERIFY( wc == 1.0 ); + VERIFY( yc == 1 ); + VERIFY( xc == 1.0f ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/3.cc new file mode 100644 index 00000000000..e4ac6cb607b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/3.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* iterator_type; + typedef std::less compare_type; + + template const value_type& max(initializer_list); + template const value_type& max(initializer_list, compare_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/pod2.cc b/libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/pod2.cc new file mode 100644 index 00000000000..55f2eae6545 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/max/requirements/explicit_instantiation/pod2.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +namespace std +{ + using __gnu_test::pod_int; + + typedef pod_int value_type; + typedef value_type* iterator_type; + typedef std::less compare_type; + + template const value_type& max(initializer_list); + template const value_type& max(initializer_list, compare_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/min/3.cc b/libstdc++-v3/testsuite/25_algorithms/min/3.cc new file mode 100644 index 00000000000..c9617249824 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/min/3.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + const int& z = std::min({1, 3, 2}); + const int& w = std::min({4, 3, 5}); + const int& y = std::min({4, 3, 2}); + VERIFY( z == 1 ); + VERIFY( w == 3 ); + VERIFY( y == 2 ); + + const int& zc = std::min({1, 3, 2}, std::greater()); + const int& wc = std::min({4, 3, 5}, std::greater()); + const int& yc = std::min({4, 3, 2}, std::greater()); + VERIFY( zc == 3 ); + VERIFY( wc == 5 ); + VERIFY( yc == 4 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/min/4.cc b/libstdc++-v3/testsuite/25_algorithms/min/4.cc new file mode 100644 index 00000000000..2d19ac79b03 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/min/4.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + const int& z = std::min({1, 2, 3, 4, 5, 6, 7}); + const double& w = std::min({2.0, 1.0, 3.2, 4.5, 5.0, 6.0, 7.0}); + const int& y = std::min({2, 3, 1, 4, 5, 6, 7}); + const float& x = std::min({2.0f, 3.0f, 5.0f, 1.0f, 7.0f, 6.0f}); + VERIFY( z == 1 ); + VERIFY( w == 1.0 ); + VERIFY( y == 1 ); + VERIFY( x == 1.0f ); + + + const int& zc = std::min({1, 2, 3, 4, 5, 6, 7}, std::greater()); + const double& wc = std::min({2.0, 1.0, 3.2, 4.5, 5.0, 6.0, 7.0}, + std::greater()); + const int& yc = std::min({2, 7, 1, 4, 5, 6, 3}, std::greater()); + const float& xc = std::min({2.0f, 3.0f, 5.0f, 1.0f, 7.0f, 6.0f}, + std::greater()); + + VERIFY( zc == 7 ); + VERIFY( wc == 7.0 ); + VERIFY( yc == 7 ); + VERIFY( xc == 7.0f ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc new file mode 100644 index 00000000000..1d6e7aedeb8 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/3.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* iterator_type; + typedef std::less compare_type; + + template const value_type& min(initializer_list); + template const value_type& min(initializer_list, compare_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/pod2.cc b/libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/pod2.cc new file mode 100644 index 00000000000..98c8413c2a6 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/min/requirements/explicit_instantiation/pod2.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +namespace std +{ + using __gnu_test::pod_int; + + typedef pod_int value_type; + typedef value_type* iterator_type; + typedef std::less compare_type; + + template const value_type& min(initializer_list); + template const value_type& min(initializer_list, compare_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/2.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/2.cc new file mode 100644 index 00000000000..f19782eb45b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/minmax/2.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::pair z = std::minmax({1, 2, 3}); + std::pair w = std::minmax({4, 3, 5, 4}); + std::pair y = std::minmax({4, 5, 3, 7, 3}); + VERIFY( z.first == 1 ); + VERIFY( z.second == 3 ); + VERIFY( w.first == 3 ); + VERIFY( w.second == 5 ); + VERIFY( y.first == 3 ); + VERIFY( y.second == 7 ); + + std::pair zc = + std::minmax({1, 2, 3}, std::greater()); + + std::pair wc = + std::minmax({4, 3, 5, 4}, std::greater()); + + std::pair yc = + std::minmax({4, 5, 3, 7, 3}, std::greater()); + + VERIFY( zc.first == 3 ); + VERIFY( zc.second == 1 ); + VERIFY( wc.first == 5 ); + VERIFY( wc.second == 3 ); + VERIFY( yc.first == 7 ); + VERIFY( yc.second == 3 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/3.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/3.cc new file mode 100644 index 00000000000..0cb438a4360 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/minmax/3.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +struct compare_counter + : std::binary_function +{ + static int count; + + bool operator()(int a, int b) const + { + ++count; + return a < b; + } +}; + +int compare_counter::count = 0; + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::pair z = std::minmax({1, 2, 3, 4, 5, 6, 7, 8}, + compare_counter()); + + // If N is the number of arguments in the minmax function call, + // 25.3.7 specifies that at most 3N/2 comparisons are allowed. + VERIFY(compare_counter::count <= (3 * 8 / 2)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/3.cc new file mode 100644 index 00000000000..71fab66fddd --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/3.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* iterator_type; + typedef std::less compare_type; + + template pair + minmax(initializer_list); + template pair + minmax(initializer_list, compare_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/pod2.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/pod2.cc new file mode 100644 index 00000000000..d5285930ddf --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/minmax/requirements/explicit_instantiation/pod2.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2008-09-16 Chris Fairles + +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +namespace std +{ + using __gnu_test::pod_int; + + typedef pod_int value_type; + typedef value_type* iterator_type; + typedef std::less compare_type; + + template pair + minmax(initializer_list); + template pair + minmax(initializer_list, compare_type); +}