gcc/libstdc++-v3/testsuite/20_util/function_objects/constexpr.cc
Ville Voutilainen 8dff34fe8e re PR libstdc++/60271 ([DR2369] [C++1y] std::max(initializer_list<T>) cannot use std::max_element)
2014-12-22  Ville Voutilainen  <ville.voutilainen@gmail.com>

	PR libstdc++/60271
	C++14 constexpr min, max, minmax, min_element, max_element
	and minmax_element. Also constexpr for 20.9.5-20.9.9,
	aka various library functors.
	* include/bits/c++config: Add _GLIBCXX14_CONSTEXPR.
	* include/bits/algorithmfwd.h (min, max, minmax, min_element,
	max_element): Use it.
	* include/bits/predefined_ops.h (_Iter_less_iter, __iter_less_iter,
	_Iter_comp_iter, __iter_comp_iter): Likewise.
	* include/bits/stl_algo.h (minmax, __minmax_element, minmax_element,
	min, max, __min_element, min_element, __max_element, max_element)
	Likewise.
	* include/bits/stl_algobase.h (min, max): Likewise.
	* include/bits/stl_function.h (plus, minus, multiplies, divides,
	modulus, negate, equal_to, not_equal_to, greater, less, greater_equal,
	less_equal, logical_and, logical_or, logical_not, bit_and, bit_or,
	bit_xor, bit_not, unary_negate, not1, binary_negate, not2): Likewise.
	* testsuite/20_util/function_objects/constexpr.cc: New.
	* testsuite/25_algorithms/max/constexpr.cc: Likewise.
	* testsuite/25_algorithms/max_element/constexpr.cc: Likewise.
	* testsuite/25_algorithms/min/constexpr.cc: Likewise.
	* testsuite/25_algorithms/min_element/constexpr.cc: Likewise.
	* testsuite/25_algorithms/minmax/constexpr.cc: Likewise.
	* testsuite/25_algorithms/minmax_element/constexpr.cc: Likewise.
	* testsuite/ext/profile/mutex_extensions_neg.cc: Adjust dg-error.

From-SVN: r219015
2014-12-22 16:00:16 +00:00

78 lines
3.0 KiB
C++

// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2014 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 3, 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 COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 20.9.5-20.9.9
#include <functional>
static_assert(std::plus<int>()(1,2)==3, "");
static_assert(std::minus<int>()(3,2)==1, "");
static_assert(std::multiplies<int>()(3,2)==6, "");
static_assert(std::divides<int>()(6,2)==3, "");
static_assert(std::modulus<int>()(7,2)==1, "");
static_assert(std::negate<int>()(-5)==5, "");
static_assert(std::plus<void>()(1,2)==3, "");
static_assert(std::minus<void>()(3,2)==1, "");
static_assert(std::multiplies<void>()(3,2)==6, "");
static_assert(std::divides<void>()(6,2)==3, "");
static_assert(std::modulus<void>()(7,2)==1, "");
static_assert(std::negate<void>()(-5)==5, "");
static_assert(std::equal_to<int>()(2,2), "");
static_assert(std::not_equal_to<int>()(1,2), "");
static_assert(std::greater<int>()(2,1), "");
static_assert(std::less<int>()(1,2), "");
static_assert(std::greater_equal<int>()(2,2), "");
static_assert(std::less_equal<int>()(2,2), "");
static_assert(std::equal_to<void>()(2,2), "");
static_assert(std::not_equal_to<void>()(1,2), "");
static_assert(std::greater<void>()(2,1), "");
static_assert(std::less<void>()(1,2), "");
static_assert(std::greater_equal<void>()(2,2), "");
static_assert(std::less_equal<void>()(2,2), "");
static_assert(std::logical_and<int>()(1,1), "");
static_assert(std::logical_or<int>()(0,1), "");
static_assert(std::logical_not<int>()(0), "");
static_assert(std::logical_and<void>()(1,1), "");
static_assert(std::logical_or<void>()(0,1), "");
static_assert(std::logical_not<void>()(0), "");
static_assert(std::bit_and<int>()(3,2)==2, "");
static_assert(std::bit_or<int>()(1,2)==3, "");
static_assert(std::bit_xor<int>()(1,1)==0, "");
static_assert(std::bit_not<int>()(std::bit_not<int>()(0))==0, "");
static_assert(std::bit_and<void>()(3,2)==2, "");
static_assert(std::bit_or<void>()(1,2)==3, "");
static_assert(std::bit_xor<void>()(1,1)==0, "");
static_assert(std::bit_not<void>()(std::bit_not<void>()(0))==0, "");
static_assert(std::unary_negate<std::logical_not<int>>
(std::logical_not<int>())(1), "");
static_assert(std::not1(std::logical_not<int>())(1), "");
static_assert(std::binary_negate<std::logical_and<int>>
(std::logical_and<int>())(0,0), "");
static_assert(std::not2(std::logical_and<int>())(0,0), "");