Commit Graph

1388 Commits

Author SHA1 Message Date
Jonathan Wakely 7a9942f521 Implement C++20 constexpr changes to std::pair (P1032R1)
* include/bits/stl_pair.h (pair): Add _GLIBCXX20_CONSTEXPR to
	piecewise construction constructor, assignment operators, and swap.
	* include/std/tuple (pair::pair(piecewise_construct_t, tuple, tuple)):
	Add _GLIBCXX20_CONSTEXPR.
	(pair::pair(tuple, tuple, _Index_tuple, _Index_tuple)): Likewise.
	* testsuite/20_util/pair/constexpr_assign.cc: New test.
	* testsuite/20_util/pair/constexpr_swap.cc: New test.

From-SVN: r276154
2019-09-26 17:08:39 +01:00
Jonathan Wakely 8eb60b2f22 Remove include directives for deleted Profile Mode headers
* include/std/array: Remove references to profile mode.
	* include/std/bitset: Likewise.
	* include/std/deque: Likewise.
	* include/std/forward_list: Likewise.
	* include/std/list: Likewise.
	* include/std/map: Likewise.
	* include/std/set: Likewise.
	* include/std/unordered_map: Likewise.
	* include/std/unordered_set: Likewise.
	* include/std/vector: Likewise.
	* testsuite/17_intro/headers/c++1998/profile_mode.cc: New test.
	* testsuite/17_intro/headers/c++2011/profile_mode.cc: New test.

From-SVN: r276152
2019-09-26 17:08:24 +01:00
Jonathan Wakely fe69bee34c Remove check for impossible condition in std::variant::index()
The __index_type is only ever unsigned char or unsigned short, so not
the same type as size_t.

	* include/std/variant (variant::index()): Remove impossible case.

From-SVN: r276100
2019-09-24 15:17:08 +01:00
Jonathan Wakely 1e8822d360 PR libstdc++/91788 improve codegen for std::variant<T...>::index()
If __index_type is a smaller type than size_t, then the result of
size_t(__index_type(-1)) is not equal to size_t(-1), but to an incorrect
value such as size_t(255) or size_t(65535). The old implementation of
variant<T...>::index() uses (size_t(__index_type(_M_index + 1)) - 1)
which is always correct, but generates suboptimal code for many common
cases.

When the __index_type is size_t or valueless variants are not possible
we can just return the value directly.

When the number of alternatives is sufficiently small the result of
converting the _M_index value to the corresponding signed type will be
either non-negative or -1. In those cases converting to the signed type
and then to size_t will either produce the correct positive value or
will sign extend -1 to (size_t)-1 as desired.

For the remaining case we keep the existing arithmetic operations to
ensure the correct result.

	PR libstdc++/91788 (partial)
	* include/std/variant (variant::index()): Improve codegen for cases
	where conversion to size_t already works correctly.

From-SVN: r276056
2019-09-23 16:54:16 +01:00
Jonathan Wakely 0f8b14ee8a Implement std::common_reference for C++20
* include/std/type_traits (__do_common_type_impl): Implement
	additional COND-RES(CREF(D1), CRED(D2)) condition for C++20.
	(basic_common_reference, common_reference, common_reference_t): Define
	for C++20.
	* testsuite/20_util/common_reference/requirements/alias_decl.cc: New
	test.
	* testsuite/20_util/common_reference/requirements/
	explicit_instantiation.cc: New test.
	* testsuite/20_util/common_reference/requirements/typedefs.cc: New
	test.

From-SVN: r275594
2019-09-10 17:28:27 +01:00
Jonathan Wakely 28f0075742 LWG 3266. to_chars(bool) should be deleted
The standard requires overloads of std::to_chars for char and (un)signed
integer types. This means that our constrained function template is
non-conforming, because the difference is observable when using types
that convert to an integer (e.g. wchar_t, which promotes).

As well as defining the deleted bool overload for LWG 3266, replace the
constrained function template with overloads for each type.

	* include/std/charconv (to_chars): Rename to __to_chars_i. Define
	non-template overloads for each signed and unsigned integer type and
	char. Define deleted overload for bool (LWG 3266).
	* testsuite/20_util/to_chars/1_neg.cc: Remove.
	* testsuite/20_util/to_chars/3.cc: New test.
	* testsuite/20_util/to_chars/lwg3266.cc: New test.

From-SVN: r275588
2019-09-10 10:08:20 +01:00
Jonathan Wakely 391d5d2e30 Optimise std::remove_cv and use more helper aliases
Define partial specializations for std::remove_cv so that
std::remove_const and std::remove_volatile don't need to be
instantiated.

	* include/std/type_traits (__remove_cv_t): New alias template.
	(is_void, is_integral, is_floating_point, is_pointer)
	(is_member_object_pointer, is_member_function_pointer, is_null_pointer)
	(is_member_point), __is_signed_integer, __is_unsigned_integer)
	(__make_unsigned_selector, __make_signed_selector, remove_pointer)
	(__decay_selector): Use __remove_cv_t.
	(remove_cv): Add partial specializations for cv-qualified types.
	(__decay_t): New alias template.
	(__decay_and_strip, __common_type_impl, __result_of_impl): Use
	__decay_t.
	(__enable_if_t): Move earlier in the file.
	(_Require): Use __enable_if_t.
	(swap(T&, T&)): Use _Require.
	(swap(T(&)[N])): Use __enable_if_t.

From-SVN: r275562
2019-09-10 08:35:36 +01:00
Edward Smith-Rowland b30ee71a40 Implement C++20 p1424 - 'constexpr' feature macro concerns...
2019-09-09  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p1424 - 'constexpr' feature macro concerns,
	Issue 3256 - Feature testing macro for constexpr algorithms,
	and Issue 3257 - Missing feature testing macro update from P0858.
	* include/std/version (__cpp_lib_constexpr_algorithms): Bump value.
	* include/bits/algorithmfwd.h: Ditto.
	* include/std/utility: Ditto.
	* testsuite/25_algorithms/constexpr_macro.cc: Ditto.
	* testsuite/25_algorithms/cpp_lib_constexpr.cc: New check for
	__cpp_lib_constexpr macro in <algorith>.
	* testsuite/20_util/exchange/constexpr.cc: Add check for
	__cpp_lib_constexpr macro in <utility>.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: Remove check for
	__cpp_lib_constexpr_algorithms.
	* testsuite/25_algorithms/all_of/constexpr.cc: Ditto.
	* testsuite/25_algorithms/any_of/constexpr.cc: Ditto.
	* testsuite/25_algorithms/binary_search/constexpr.cc: Ditto.
	* testsuite/25_algorithms/copy/constexpr.cc: Ditto.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: Ditto.
	* testsuite/25_algorithms/copy_if/constexpr.cc: Ditto.
	* testsuite/25_algorithms/copy_n/constexpr.cc: Ditto.
	* testsuite/25_algorithms/count/constexpr.cc: Ditto.
	* testsuite/25_algorithms/count_if/constexpr.cc: Ditto.
	* testsuite/25_algorithms/equal/constexpr.cc: Ditto.
	* testsuite/25_algorithms/equal_range/constexpr.cc: Ditto.
	* testsuite/25_algorithms/fill/constexpr.cc: Ditto.
	* testsuite/25_algorithms/fill_n/constexpr.cc: Ditto.
	* testsuite/25_algorithms/find/constexpr.cc: Ditto.
	* testsuite/25_algorithms/find_end/constexpr.cc: Ditto.
	* testsuite/25_algorithms/find_first_of/constexpr.cc: Ditto.
	* testsuite/25_algorithms/find_if/constexpr.cc: Ditto.
	* testsuite/25_algorithms/find_if_not/constexpr.cc: Ditto.
	* testsuite/25_algorithms/for_each/constexpr.cc: Ditto.
	* testsuite/25_algorithms/generate/constexpr.cc: Ditto.
	* testsuite/25_algorithms/generate_n/constexpr.cc: Ditto.
	* testsuite/25_algorithms/is_heap/constexpr.cc: Ditto.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: Ditto.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: Ditto.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: Ditto.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: Ditto.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc: Ditto.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: Ditto.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: Ditto.
	* testsuite/25_algorithms/merge/constexpr.cc: Ditto.
	* testsuite/25_algorithms/mismatch/constexpr.cc: Ditto.
	* testsuite/25_algorithms/none_of/constexpr.cc: Ditto.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: Ditto.
	* testsuite/25_algorithms/partition_point/constexpr.cc: Ditto.
	* testsuite/25_algorithms/remove/constexpr.cc: Ditto.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: Ditto.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: Ditto.
	* testsuite/25_algorithms/remove_if/constexpr.cc: Ditto.
	* testsuite/25_algorithms/replace_copy/constexpr.cc: Ditto.
	* testsuite/25_algorithms/replace_copy_if/constexpr.cc: Ditto.
	* testsuite/25_algorithms/replace_if/constexpr.cc: Ditto.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: Ditto.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: Ditto.
	* testsuite/25_algorithms/search/constexpr.cc: Ditto.
	* testsuite/25_algorithms/search_n/constexpr.cc: Ditto.
	* testsuite/25_algorithms/set_difference/constexpr.cc: Ditto.
	* testsuite/25_algorithms/set_intersection/constexpr.cc: Ditto.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: Ditto.
	* testsuite/25_algorithms/set_union/constexpr.cc: Ditto.
	* testsuite/25_algorithms/transform/constexpr.cc: Ditto.
	* testsuite/25_algorithms/unique/constexpr.cc: Ditto.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: Ditto.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: Ditto.

From-SVN: r275560
2019-09-10 03:38:58 +00:00
Jonathan Wakely 27dada7d06 Improve constraints for std::span constructors
This patch simplifies the constraints on the constructors from arrays by
removing the redundant checks that element_type and value_type are
convertible to element_type. The incorrect uses of __adl_data in those
constructors are removed as well (they should use std::data not
std::ranges::data, and the former doesn't use ADL).

The range/container constructors are now constrained to exclude all
specializations of std::span, not just the current instantiation. The
range constructor now also checks s subset of the contiguous_range
requirements.

All relevant constructor constraints now use the _Require helper in
order to short circuit and avoid unnecessary instantiations after the
first failed constraint.

A new constructor supports initialization from different specializations
of std::span<OtherType, OtherExtent>, as specified in the C++20 draft.

	* include/bits/range_access.h (__adl_to_address): Remove.
	* include/std/span (__is_base_derived_safe_convertible_v): Replace
	with span::__is_compatible.
	(__is_std_array_v): Replace with __is_std_array class template and
	partial specializations.
	(__is_std_array, __is_std_span): New class templates and partial
	specializations.
	(span::__is_compatible): New alias template for SFINAE constraints.
	(span::span(element_type (&)[N])): Remove redundant constraints. Do
	not use __adl_data to obtain a pointer.
	(span::span(array<value_type, N>&)): Likewise.
	(span::span(const array<value_type, N>&)): Likewise.
	[_GLIBCXX_P1394] (span::iter_reference_t, span::iterator_t)
	(span::iter_value_t, span::derived_from): New alias templates for
	SFINAE constraints, until the equivalents are supported in <concepts>
	and <iterator>.
	[_GLIBCXX_P1394] (span::__is_compatible_iterator): New alias template
	for SFINAE constraints.
	[_GLIBCXX_P1394] (span::is_compatible_range): New class template for
	SFINAE constraints.
	[_GLIBCXX_P1394] (span::span(Range&&)): Improve constraints.
	[_GLIBCXX_P1394] (span::span(ContiguousIterator, Sentinel)): Likewise.
	Use std::to_address instead of __adl_to_address.
	[_GLIBCXX_P1394] (span::span(ContiguousIterator, size_type)): Likewise.
	[!_GLIBCXX_P1394] (span::__is_compatible_container): New alias
	template for SFINAE constraints.
	[!_GLIBCXX_P1394] (span::span(Container&))
	(span::span(const Container&)): Improve constraints.
	[!_GLIBCXX_P1394] (span::span(pointer, size_type))
	(span::span(pointer, pointer)): Remove redundant cast of pointer.
	(span(const span<OType, OExtent>&)): New constructor.

From-SVN: r275513
2019-09-09 12:12:38 +01:00
Jonathan Wakely b5c433ce11 Improve precondition checks for std::span
* doc/xml/manual/status_cxx2020.xml: Update status for P0122R7 and
	P1024R3. Remove entry for P0920R2.
	* include/std/span  (__cpp_lib_span): Change value.
	(__extent_storage, __extent_storage<dynamic_extent>): Remove default
	constructor.
	(span): Replace __extent_storage base class with data member.
	(span::_S_subspan_extent): New function.
	(span::empty()): Add nodiscard attribute.
	(span::front, span::back, span::operator[]): Check preconditions.
	(span::first, span::last, span::subspan): Add noexcept. Improve
	precondition checks (LWG 3103).
	(get): Remove redundant condition from static_assert.
	(tuple_element<I, span<T, E>>): Fix static_assert message and simplify.
	(as_writable_bytes): Add inline specifier.
	* include/std/version (__cpp_lib_span): Change value.
	* testsuite/23_containers/span/back_neg.cc: Remove stray semi-colon.
	* testsuite/23_containers/span/front_neg.cc: Likewise.
	* testsuite/23_containers/span/index_op_neg.cc: Likewise.
	* testsuite/23_containers/span/last_neg.cc: Improve test.
	* testsuite/23_containers/span/subspan_neg.cc: Likewise.
	* testsuite/23_containers/span/1.cc: New test.
	* testsuite/23_containers/span/2.cc: New test.
	* testsuite/23_containers/span/back_assert_neg.cc: New test.
	* testsuite/23_containers/span/first_2_assert_neg.cc: New test.
	* testsuite/23_containers/span/first_assert_neg.cc: New test.
	* testsuite/23_containers/span/first_neg.cc: New test.
	* testsuite/23_containers/span/front_assert_neg.cc: New test.
	* testsuite/23_containers/span/index_op_assert_neg.cc: New test.
	* testsuite/23_containers/span/last_2_assert_neg.cc: New test.
	* testsuite/23_containers/span/last_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_2_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_3_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_4_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_5_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_6_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_assert_neg.cc: New test.

From-SVN: r275411
2019-09-05 14:48:33 +01:00
JeanHeyd Meneide 95e9a7616d Implement std::span for C++20
2019-09-05  JeanHeyd Meneide  <phdofthehouse@gmail.com>

	* include/Makefile.am: Add <span> header.
	* include/Makefile.in: Regenerate.
	* include/bits/range_access.h (__adl_begin, __adl_end, __adl_cbegin)
	(__adl_cend, __adl_rbegin, __adl_rend, __adl_crbegin, __adl_crend)
	(__adl_data, __adl_cdata, __adl_size, __adl_empty, __adl_to_address):
	New functions for performing argument-dependent lookup of range
	customization points.
	* include/bits/stl_iterator.h (__normal_iterator): Add
	_GLIBCXX20_CONSTEXPR to all functions.
	* include/std/span: New header.
	* include/std/version (__cpp_lib_span): Define feature test macro.
	* testsuite/23_containers/span/contiguous_range_neg.cc: New test.
	* testsuite/23_containers/span/everything.cc: New test.
	* testsuite/23_containers/span/get_neg.cc: New test.
	* testsuite/23_containers/span/last_neg.cc: New test.
	* testsuite/23_containers/span/subspan_neg.cc: New test.
	* testsuite/23_containers/span/tuple_element_dynamic_neg.cc: New test.
	* testsuite/23_containers/span/tuple_element_oob_neg.cc: New test.
	* testsuite/23_containers/span/tuple_size_neg.cc: New test.

From-SVN: r275403
2019-09-05 12:27:45 +01:00
Mike Crowe ad4d1d21ad PR libstdc++/41861 Add full steady_clock support to condition_variable
The pthread_cond_clockwait function is available in glibc since the 2.30
release. If this function is available in the C library it can be used
to fix PR libstdc++/41861 by supporting std::chrono::steady_clock
properly with std::condition_variable.

This means that code using std::condition_variable::wait_for or
std::condition_variable::wait_until with std::chrono::steady_clock is no
longer subject to timing out early or potentially waiting for much
longer if the system clock is warped at an inopportune moment.

If pthread_cond_clockwait is available then std::chrono::steady_clock is
deemed to be the "best" clock available which means that it is used for
the relative wait_for calls and absolute wait_until calls using
user-defined clocks. Calls explicitly using std::chrono::system_clock
continue to use CLOCK_REALTIME via __gthread_cond_timedwait.

If pthread_cond_clockwait is not available then
std::chrono::system_clock is deemed to be the "best" clock available
which means that the previous suboptimal behaviour remains.

2019-09-04  Mike Crowe  <mac@mcrowe.com>

	PR libstdc++/41861
	* acinclude.m4 (GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT): Check for new
	pthread_cond_clockwait function.
	* configure.ac: Use GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT.
	* configure: Regenerate.
	* config.h.in: Regenerate.
	* include/std/condition_variable: (condition_variable): Rename
	__steady_clock_t typedef and add system_clock. Change __clock_t to be
	a typedef for the preferred clock to convert arbitrary other clocks to.
	[_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT] (wait_until): Add a steady_clock
	overload.
	(wait_until): Change __clock_t overload to use system_clock.
	[_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT] (__wait_until_impl): Add
	steady_clock overload that calls pthread_cond_clockwait.
	(__wait_until_impl): Change __clock_t overload to use system_clock.
	(condition_variable_any) [_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT]: Use
	steady_clock for __clock_t if pthread_cond_clockwait is available.

From-SVN: r275390
2019-09-04 23:43:29 +01:00
Jonathan Wakely 6e672b1801 Minor simplifications for std::to_chars implementation
* include/std/charconv (__detail::__to_chars_2_len): Use std::log2p1.
	(__detail::__to_chars_8_len): Remove.
	(__detail::__to_chars_8): Inline length calculation here.
	(__detail::__from_chars_binary): Use numeric_limits instead of
	CHAR_BIT.

From-SVN: r275313
2019-09-02 12:31:25 +01:00
Antony Polukhin 7259a9d577 Optimize std::to_chars
Bunch of micro optimizations for std::to_chars:
* For base == 8 replacing the lookup in __digits table with arithmetic
computations leads to a same CPU cycles for a loop (exchanges two movzx
with 3 bit ops). However this saves 129 bytes of data and totally avoids
a chance of cache misses on __digits.
* For base == 16 replacing the lookup in __digits table with
arithmetic computations leads to a few additional instructions, but
totally avoids a chance of cache misses on __digits (- ~9 cache misses
for worst case) and saves 513 bytes of const data.
* Replacing __first[pos] and __first[pos - 1] with __first[1] and
__first[0] on final iterations saves ~2% of code size.
* Removing trailing '\0' from arrays of digits allows the linker to
merge the symbols (so that "0123456789abcdefghijklmnopqrstuvwxyz" and
"0123456789abcdef" could share the same address). This improves data
locality and reduces binary sizes.
* Using __detail::__to_chars_len_2 instead of a generic
__detail::__to_chars_len makes the operation O(1) instead of O(N). It
also makes the code two times shorter.

In sum: this significantly reduces the size of a binary (for about 4KBs
only for base-8 conversion), deals with latency (CPU cache misses)
without changing the iterations count and without adding costly
instructions into the loops.

2019-08-30  Antony Polukhin  <antoshkka@gmail.com>

	* include/std/charconv (__detail::__to_chars_8)
	__detail::__to_chars_16): Replace array of precomputed digits with
	arithmetic operations to avoid CPU cache misses. Remove zero
	termination from array of digits to allow symbol merge with generic
	implementation of __detail::__to_chars. Replace final offsets with
	constants. Use __detail::__to_chars_len_2 instead of a generic
	__detail::__to_chars_len.
	(__detail::__to_chars): Remove zero termination from array of digits.
	(__detail::__to_chars_2): Leading digit is always '1'.

From-SVN: r275205
2019-08-30 17:25:24 +01:00
Jonathan Wakely eb0e858945 Fix markdown in Doxygen comments for std::reduce
* include/std/numeric (reduce): Fix Doxygen markup.

From-SVN: r274757
2019-08-20 22:34:15 +01:00
Jonathan Wakely 72459cfd86 PR libstdc++/91371 make std::is_function handle other calling conventions
The x86 attributes such as ms_abi, stdcall, fastcall etc. alter the
function type, which means that functions with one of those attributes
do not match any of the partial specializations of std::is_function.

Rather than duplicating the list for every calling convention, use a
much simpler definition of std::is_function.

Also redefine __is_referenceable to not rely on partial specializations
for each type of referenceable function.

	PR libstdc++/91371
	* include/std/type_traits (is_function): Simplify definition. Remove
	partial specializations for function types.
	(__is_referenceable): Simplify definition.
	* testsuite/20_util/bind/91371.cc: New test.
	* testsuite/20_util/is_function/91371.cc: New test.
	* testsuite/20_util/is_function/value.cc: Check more pointer types.
	* testsuite/20_util/is_member_function_pointer/91371.cc: New test.
	* testsuite/20_util/is_object/91371.cc: New test.

From-SVN: r274756
2019-08-20 22:21:15 +01:00
Jonathan Wakely d91f618d15 PR libstdc++/91456 make INVOKE<R> work with uncopyable prvalues
In C++17 a function can return a prvalue of a type that cannot be moved
or copied. The current implementation of std::is_invocable_r uses
std::is_convertible to test the conversion to R required by INVOKE<R>.
That fails for non-copyable prvalues, because std::is_convertible is
defined in terms of std::declval which uses std::add_rvalue_reference.
In C++17 conversion from R to R involves no copies and so is not the
same as conversion from R&& to R.

This commit changes std::is_invocable_r to check the conversion without
using std::is_convertible.

std::function also contains a similar check using std::is_convertible,
which can be fixed by simply reusing std::is_invocable_r (but because
std::is_invocable_r is not defined for C++11 it uses the underlying
std::__is_invocable_impl trait directly).

	PR libstdc++/91456
	* include/bits/std_function.h (__check_func_return_type): Remove.
	(function::_Callable): Use std::__is_invocable_impl instead of
	__check_func_return_type.
	* include/std/type_traits (__is_invocable_impl): Add another defaulted
	template parameter. Define a separate partial specialization for
	INVOKE and INVOKE<void>. For INVOKE<R> replace is_convertible check
	with a check that models delayed temporary materialization.
	* testsuite/20_util/function/91456.cc: New test.
	* testsuite/20_util/is_invocable/91456.cc: New test.

From-SVN: r274542
2019-08-15 17:07:27 +01:00
Jonathan Wakely 07fd852ff1 Deprecate std::__is_nullptr_t type trait
This non-standard extension is redundant and unused by the library.

	* include/std/type_traits (__is_nullptr_t): Add deprecated attribute.

From-SVN: r274491
2019-08-14 20:52:06 +01:00
Edward Smith-Rowland 7a91c71099 Implement C++20 p0879 - Constexpr for swap and swap related functions.
2019-08-14  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0879 - Constexpr for swap and swap related functions.
	* include/std/version (__cpp_lib_constexpr_swap_algorithms): New macro.
	* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
	New macro.
	(iter_swap, make_heap, next_permutation, partial_sort_copy, pop_heap)
	(prev_permutation, push_heap, reverse, rotate, sort_heap, swap)
	(swap_ranges, nth_element, partial_sort, sort): Add constexpr.
	* include/bits/move.h (swap): Add constexpr.
	* include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse)
	(__gcd, __rotate, rotate, __partition, __heap_select)
	(__partial_sort_copy, partial_sort_copy, __unguarded_partition)
	(__unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort)
	(__introselect, __chunk_insertion_sort, next_permutation)
	(prev_permutation, partition, partial_sort, nth_element, sort)
	(__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr.
	* include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap)
	(swap_ranges): Add constexpr.
	* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
	__pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap):
	Add constexpr.
	* include/std/type_traits (swap): Add constexpr.
	* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Add constexpr.
	* testsuite/25_algorithms/iter_swap/constexpr.cc: New test.
	* testsuite/25_algorithms/make_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/next_permutation/constexpr.cc: New test.
	* testsuite/25_algorithms/nth_element/constexpr.cc: New test.
	* testsuite/25_algorithms/partial_sort/constexpr.cc: New test.
	* testsuite/25_algorithms/partial_sort_copy/constexpr.cc: New test.
	* testsuite/25_algorithms/partition/constexpr.cc: New test.
	* testsuite/25_algorithms/pop_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/prev_permutation/constexpr.cc: New test.
	* testsuite/25_algorithms/push_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/reverse/constexpr.cc: New test.
	* testsuite/25_algorithms/rotate/constexpr.cc: New test.
	* testsuite/25_algorithms/sort/constexpr.cc: New test.
	* testsuite/25_algorithms/sort_heap/constexpr.cc: New test.
	* testsuite/25_algorithms/swap/constexpr.cc: New test.
	* testsuite/25_algorithms/swap_ranges/constexpr.cc: New test.

From-SVN: r274488
2019-08-14 17:54:15 +00:00
Jonathan Wakely 6fd4b25b50 Add noexcept-specifier to std::apply and std::make_from_tuple
When unpacking a std::tuple we know that the std::get calls are
noexcept, so only the invocation (for std::apply) and construction (for
std::make_from_tuple) can throw.

We also know the std::get calls won't throw for a std::array, but this
patch doesn't specialize the variable template for std::array. For an
arbitrary tuple-like type we don't know if the std::get calls will
throw, and so just use a potentially-throwing noexcept-specifier.

	* include/std/tuple (__unpack_std_tuple): New variable template and
	partial specializations.
	(apply, make_from_tuple): Add noexcept-specifier.
	* testsuite/20_util/tuple/apply/2.cc: New test.
	* testsuite/20_util/tuple/make_from_tuple/2.cc: New test.

From-SVN: r274312
2019-08-12 15:54:12 +01:00
Jonathan Wakely cb0de9b60c P0325R4 to_array from LFTS with updates
As an extension to what the standard requires, this also adds
conditional noexcept-specifiers to the std::to_array functions.

	P0325R4 to_array from LFTS with updates
	* include/experimental/array (to_array): Qualify call to __to_array.
	* include/std/array (__cpp_lib_to_array, to_array): Define for C++20.
	* include/std/version (__cpp_lib_to_array): Likewise.
	* testsuite/23_containers/array/creation/1.cc: New test.
	* testsuite/23_containers/array/creation/2.cc: New test.
	* testsuite/23_containers/array/creation/3_neg.cc: New test.
	* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
	Use zero for dg-error line number.

From-SVN: r274209
2019-08-08 11:18:53 +01:00
Jonathan Wakely ffc500dd41 P1651R0 bind_front should not unwrap reference_wrapper
P1651R0 bind_front should not unwrap reference_wrapper
	* include/std/functional (bind_front): Don't unwrap reference_wrapper.
	* include/std/version (__cpp_lib_bind_front): Update value.
	* testsuite/20_util/function_objects/bind_front/1.cc: Fix test for
	feature test macro.
	* testsuite/20_util/function_objects/bind_front/2.cc: New test.

From-SVN: r274146
2019-08-06 16:57:55 +01:00
Jonathan Wakely a38b51bc3a Specialize std::numbers constants for __float128
* include/std/numbers [!__STRICT_ANSI__ && _GLIBCXX_USE_FLOAT128]
	(e_v, log2e_v, log10e_v, pi_v, inv_pi_v, inv_sqrtpi_v, ln2_v, ln10_v)
	(sqrt2_v, sqrt3_v, inv_sqrt3, egamma_v, phi_v): Add explicit
	specializations for __float128.
	* testsuite/26_numerics/numbers/float128.cc: New test.

From-SVN: r274145
2019-08-06 16:57:51 +01:00
Edward Smith-Rowland 3a66e68ad9 Implement C++20 p0202 - Add Constexpr Modifiers to Functions in <algorithm> and <utility> Headers.
2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0202 - Add Constexpr Modifiers to Functions
	in <algorithm> and <utility> Headers.
	Implement C++20 p1023 - constexpr comparison operators for std::array.
	* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
	copy_backward, copy_if, copy_n, equal_range, fill, find_end,
	find_if_not, includes, is_heap, is_heap_until, is_partitioned,
	is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
	none_of, partition_copy, partition_point, remove, remove_if,
	remove_copy, remove_copy_if, replace_copy, replace_copy_if,
	reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
	count_if, equal, find, find_first_of, find_if, for_each, generate,
	generate_n, lexicographical_compare, merge, mismatch, replace,
	replace_if, search, search_n, set_difference, set_intersection,
	set_symmetric_difference, set_union, transform, unique_copy):
	Mark constexpr.
	* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
	* include/bits/predefined_ops.h (_Iter_less_val::operator(),
	_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
	_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
	 Use const ref instead of ref arg;
	(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
	__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
	_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
	_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
	_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
	__iter_comp_iter): Mark constexpr.
	* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
	__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
	none_of, any_of, find_if_not, is_partitioned, partition_point,
	__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
	copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
	__unique, unique, __unique_copy, reverse_copy, rotate_copy,
	__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
	__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
	__equal_range, equal_range, binary_search, __includes, includes,
	__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
	replace_copy_if, __count_if, is_sorted, __is_sorted_until,
	is_sorted_until, __is_permutation, is_permutation, for_each, find,
	find_if, find_first_of, adjacent_find, count, count_if, search,
	search_n, transform, replace, replace_if, generate, generate_n,
	unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
	set_intersection, __set_difference, set_difference,
	__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
	* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
	wrappers around __builtin_memmove and __builtin_memcmp
	respectively;
	(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
	copy, move, __copy_move_b, __copy_move_backward_a,
	__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
	__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
	__lexicographical_compare_impl, __lexicographical_compare,
	__lexicographical_compare<true>::__lc, __lexicographical_compare_aux,
	__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
	__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark constexpr.
	* include/std/array: Make comparison ops constexpr.
	* include/std/utility: Make exchange constexpr.
	* include/std/version (__cpp_lib_constexpr_algorithms): New macro.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_neg.cc: Adjust.
	* testsuite/20_util/exchange/constexpr.cc: New.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
	* testsuite/25_algorithms/constexpr_macro.cc: New.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
	* testsuite/25_algorithms/all_of/constexpr.cc: New.
	* testsuite/25_algorithms/any_of/constexpr.cc: New.
	* testsuite/25_algorithms/binary_search/constexpr.cc: New.
	* testsuite/25_algorithms/copy/constexpr.cc: New.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: New.
	* testsuite/25_algorithms/copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/copy_n/constexpr.cc: New.
	* testsuite/25_algorithms/count/constexpr.cc: New.
	* testsuite/25_algorithms/count_if/constexpr.cc: New.
	* testsuite/25_algorithms/equal/constexpr.cc: New.
	* testsuite/25_algorithms/equal_range/constexpr.cc: New.
	* testsuite/25_algorithms/fill/constexpr.cc: New.
	* testsuite/25_algorithms/fill_n/constexpr.cc: New.
	* testsuite/25_algorithms/find/constexpr.cc: New.
	* testsuite/25_algorithms/find_end/constexpr.cc: New.
	* testsuite/25_algorithms/find_first_of/constexpr.cc: New.
	* testsuite/25_algorithms/find_if/constexpr.cc: New.
	* testsuite/25_algorithms/find_if_not/constexpr.cc: New.
	* testsuite/25_algorithms/for_each/constexpr.cc: New.
	* testsuite/25_algorithms/generate/constexpr.cc: New.
	* testsuite/25_algorithms/generate_n/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: New.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: New.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc: New.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: New.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: New.
	* testsuite/25_algorithms/merge/constexpr.cc: New.
	* testsuite/25_algorithms/mismatch/constexpr.cc: New.
	* testsuite/25_algorithms/none_of/constexpr.cc: New.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: New.
	* testsuite/25_algorithms/partition_point/constexpr.cc: New.
	* testsuite/25_algorithms/remove/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/remove_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_if/constexpr.cc: New.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: New.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: New.
	* testsuite/25_algorithms/search/constexpr.cc: New.
	* testsuite/25_algorithms/search_n/constexpr.cc: New.
	* testsuite/25_algorithms/set_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_intersection/constexpr.cc: New.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_union/constexpr.cc: New.
	* testsuite/25_algorithms/transform/constexpr.cc: New.
	* testsuite/25_algorithms/unique/constexpr.cc: New.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: New.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: New.

From-SVN: r273975
2019-08-01 15:25:42 +00:00
Jonathan Wakely 3090082cbe Qualify call to prevent ADL
* include/std/memory (make_obj_using_allocator): Qualify call to
	uses_allocator_construction_args.

From-SVN: r273945
2019-07-31 20:08:56 +01:00
Jonathan Wakely 960b9ae05a Implement "P0631R4 Math Constants" for C++20
The values of the constants are taken from Glibc where the equivalent
constant exists, or by rounding the actual constant to the same number
of digits as the Glibc constants have.

	P0631R4 Math Constants
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Include new header.
	* include/std/numbers: New header.
	* include/std/version (__cpp_lib_math_constants): Define.
	* testsuite/26_numerics/numbers/1.cc: New test.
	* testsuite/26_numerics/numbers/2.cc: New test.
	* testsuite/26_numerics/numbers/3.cc: New test.
	* testsuite/26_numerics/numbers/nonfloat_neg.cc: New test.

From-SVN: r273940
2019-07-31 17:40:39 +01:00
Jonathan Wakely 27e6c1f406 Add Doxygen comments to <bit> header
* include/std/bit: Add Doxygen comments.

From-SVN: r273938
2019-07-31 15:38:50 +01:00
Jonathan Wakely a5378f9b60 Define __cpp_lib_endian feature test macro
This macro was added as part of moving std::endian from <type_traits> to
<bit>.

	* include/std/bit (__cpp_lib_endian): Define.
	* include/std/version (__cpp_lib_endian): Define.
	* testsuite/26_numerics/endian/2.cc: New.
	* testsuite/26_numerics/endian/3.cc: New.
	* testsuite/26_numerics/endian/4.cc: New.

From-SVN: r273828
2019-07-26 14:30:42 +01:00
Jonathan Wakely 45c7215c1e Relocate std::endian from <type_traits> to <bit>
This change to an early C++2a feature was just approved (P1612R1).

	* include/std/bit (endian): Move definition here as per P1612R1.
	* include/std/type_traits (endian): Remove definition from here.
	* testsuite/20_util/endian/1.cc: Rename to ...
	* testsuite/26_numerics/endian/1.cc: ... here. Adjust header.

From-SVN: r273816
2019-07-25 21:30:25 +01:00
Jonathan Wakely f35da524a2 Adjust std::rotl, std::rotr etc to match final P0553R4 proposal
This proposal has now been accepted for C++20, with a few changes. This
patch adjusts std::rotl and std::rotr to match the final specification
and declares the additions for C++2a mode even when __STRICT_ANSI__ is
defined.

	* include/std/bit (__rotl, __rotr): Change second parameter from
	unsigned int to int and handle negative values.
	(rotl, rotr): Remove check for __STRICT_ANSI__. Change second
	parameter from unsigned int to int. Add nodiscard attribute.
	* testsuite/26_numerics/bit/bitops.rot/rotl.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Here. Test negative
	shifts.
	* testsuite/26_numerics/bit/bitops.rot/rotr.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.rotate/rotr.cc: Here. Test negative
	shifts.

From-SVN: r273706
2019-07-22 17:53:36 +01:00
Jonathan Wakely 281ab2fbff Change std::ceil2 to be undefined if the result can't be represented
* include/std/bit (__ceil2): Make unrepresentable results undefined,
	as per P1355R2. Add debug assertion. Perform one left shift, not two,
	so that out of range values cause undefined behaviour. Ensure that
	shift will still be undefined if left operand is promoted.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Replace checks for
	unrepresentable values with checks that they are not core constant
	expressions.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: New test.

From-SVN: r273705
2019-07-22 17:53:27 +01:00
Jason Merrill e6c847fb8f Add parens around constraint in <memory>.
C++20 concepts require parens around atomic constraints that are not
primary-expressions.

	* include/std/memory (uses_allocator_construction_args): Add parens
	around constraint.

From-SVN: r273515
2019-07-16 04:54:47 -04:00
Jonathan Wakely 0d67cd380d Define __type_identity_t alias and use for string_view
This defines the equivalent of C++2a's std::type_identity_t alias but
for use in C++11 and later. This can be used to replace __detail::__idt
in the string_view headers, which previously used common_type_t because
the one argument specialization of common_type_t was simply the identity
transform (which is no longer true).

	* include/experimental/string_view (__detail::__idt): Remove.
	(operator==, operator!=, operator<, operator>, operator<=, operator>=):
	Use __type_identity_t instead of __detail::__idt;
	* include/std/string_view (__detail::__idt): Remove.
	(operator==, operator!=, operator<, operator>, operator<=, operator>=):
	Use __type_identity_t instead of __detail::__idt;
	* include/std/type_traits (__type_identity_t): New alias template.

From-SVN: r273442
2019-07-12 12:43:22 +01:00
Jonathan Wakely a90fe12c80 Define std::atomic_ref and std::atomic<floating-point> for C++20
This adds the new atomic types from C++2a, as proposed by P0019 and
P0020. To reduce duplication the calls to the compiler's atomic
built-ins are wrapped in new functions in the __atomic_impl namespace.
These functions are currently only used by std::atomic<floating-point>
and std::atomic_ref but could also be used for all other specializations
of std::atomic.

	* include/bits/atomic_base.h (__atomic_impl): New namespace for
	wrappers around atomic built-ins.
	(__atomic_float, __atomic_ref): New class templates for use as base
	classes.
	* include/std/atomic (atomic<float>, atomic<double>)
	(atomic<long double>): New explicit specializations.
	(atomic_ref): New class template.
	(__cpp_lib_atomic_ref): Define.
	* include/std/version (__cpp_lib_atomic_ref): Define.
	* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error.
    	* testsuite/29_atomics/atomic_float/1.cc: New test.
    	* testsuite/29_atomics/atomic_float/requirements.cc: New test.
    	* testsuite/29_atomics/atomic_ref/deduction.cc: New test.
    	* testsuite/29_atomics/atomic_ref/float.cc: New test.
    	* testsuite/29_atomics/atomic_ref/generic.cc: New test.
    	* testsuite/29_atomics/atomic_ref/integral.cc: New test.
    	* testsuite/29_atomics/atomic_ref/pointer.cc: New test.
    	* testsuite/29_atomics/atomic_ref/requirements.cc: New test.

From-SVN: r273420
2019-07-11 20:43:25 +01:00
Jonathan Wakely 22ff8929d7 Define std::chars_format enumeration type
This type isn't used anywhere yet, but will be needed for the
floating-point overloads of to_chars and from_chars.

	* include/std/charconv (chars_format): Define bitmask type.
	* testsuite/20_util/to_chars/chars_format.cc: New test.

From-SVN: r272718
2019-06-26 23:54:38 +01:00
Jonathan Wakely 47f7905440 Add new helper traits for signed/unsigned integer types
Reuse the __is_one_of alias in additional places, and define traits to
check for signed/unsigned integer types so we don't have to duplicate
those checks elsewhere.

The additional overloads for std::byte in <bit> were reviewed by LEWG
and considered undesirable, so this patch removes them.

	* include/bits/fs_path.h (path::__is_encoded_char): Use __is_one_of.
	* include/std/bit (_If_is_unsigned_integer_type): Remove.
	(_If_is_unsigned_integer): Use __is_unsigned_integer.
	(rotl(byte, unsigned), rotr(byte, unsigned), countl_zero(byte))
	(countl_one(byte), countr_zero(byte), countr_one(byte))
	(popcount(byte), ispow2(byte), ceil2(byte), floor2(byte))
	(log2p1(byte)): Remove.
	* include/std/charconv (__detail::__is_one_of): Move to <type_traits>.
	(__detail::__is_int_to_chars_type): Remove.
	(__detail::__integer_to_chars_result_type): Use __is_signed_integer
	and __is_unsigned_integer.
	* include/std/type_traits (__is_one_of): Move here from <charconv>.
	(__is_signed_integer, __is_unsigned_integer): New helpers.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Remove test for
	std::byte overload.
	* testsuite/26_numerics/bit/bit.pow.two/floor2.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/countl_one.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/countl_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/countr_one.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/countr_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/popcount.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.rot/rotl.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.rot/rotr.cc: Likewise.

From-SVN: r272695
2019-06-26 15:38:23 +01:00
Jonathan Wakely e88d863cbd Fix non-portable use of std::abs(double) in constexpr function
Although libstdc++ adds 'constexpr' to its std::abs(floating-point)
overloads (as a non-conforming extension), those overloads are not used
if the target libc provides them, which is the case on Solaris.

The fix is to avoid std::abs and simply apply the negation when needed.

	* include/std/numeric (midpoint(T, T)): Avoid std::abs in constexpr
	function.

From-SVN: r272653
2019-06-25 14:18:36 +01:00
Jonathan Wakely a3c8d7fbe2 Fix std::midpoint for denormal values
* include/std/numeric (midpoint(T, T)): Change implementation for
	floating-point types to avoid incorrect rounding of denormals.
	* testsuite/26_numerics/midpoint/floating.cc: Add check for correct
	rounding with denormals.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Adjust dg-error line numbers.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.

From-SVN: r272616
2019-06-24 13:09:51 +01:00
Jonathan Wakely d306dee31d Qualify calls to __never_valueless in <variant>
* include/std/variant (_Variant_storage, _Extra_visit_slot_needed):
	Qualify calls to __never_valueless.

From-SVN: r272508
2019-06-20 15:17:51 +01:00
Jonathan Wakely 74fda2dc9f Fix value category bugs in std::reduce
* include/std/numeric (reduce(Iter, Iter, T, BinOp)): Fix value
	category used in invocable check.
	(reduce(Iter, Iter, T)): Pass initial value as rvalue.
	* testsuite/26_numerics/reduce/2.cc: New test.

From-SVN: r272477
2019-06-19 16:29:49 +01:00
Jonathan Wakely ed920373a5 Implement new serial algorithms from Parallelism TS (P0024R2)
These new (non-parallel) algorithms were added to C++17 along with the
parallel algorithms, but were missing from libstdc++.

	* include/bits/algorithmfwd.h: Change title of doc group.
	* include/bits/stl_algo.h (for_each_n): Add new C++17 algorithm from
	P0024R2.
	* include/bits/stl_numeric.h: Define doc group and add algos to it.
	* include/std/numeric (__is_random_access_iter): New internal trait.
	(reduce, transform_reduce, exclusive_scan, inclusive_scan)
	(transform_exclusive_scan, transform_inclusive_scan): Likewise.
	* testsuite/25_algorithms/for_each/for_each_n.cc: New test.
	* testsuite/26_numerics/exclusive_scan/1.cc: New test.
	* testsuite/26_numerics/inclusive_scan/1.cc: New test.
	* testsuite/26_numerics/reduce/1.cc: New test.
	* testsuite/26_numerics/transform_exclusive_scan/1.cc: New test.
	* testsuite/26_numerics/transform_inclusive_scan/1.cc: New test.
	* testsuite/26_numerics/transform_reduce/1.cc: New test.
	* testsuite/util/testsuite_iterators.h (test_container::size()): New
	member function.

From-SVN: r272459
2019-06-19 00:01:16 +01:00
Jonathan Wakely cc28d23496 Disable -Wctor-dtor-privacy warnings for some standard types
* include/experimental/type_traits (experimental::nonesuch): Use
	pragma to disable -Wctor-dtor-privacy warnings.
	* include/std/type_traits (__is_convertible_helper<From, To, false>)
	(__is_nt_convertible_helper<From, To, false>, __nonesuch): Likewise.

From-SVN: r272289
2019-06-14 15:03:20 +01:00
Jonathan Wakely c68c4c982d Add __cpp_lib_bind_front macro to <version> header
* include/std/version (__cpp_lib_bind_front): Add missing macro.

From-SVN: r272288
2019-06-14 15:03:16 +01:00
Jonathan Wakely 95b3d0fda3 Fix incorrect __cpp_lib_parallel_algorithm macro definitions
* include/std/algorithm (__cpp_lib_parallel_algorithm): Fix value.
	* include/std/memory (__cpp_lib_parallel_algorithm): Likewise.
	* include/std/numeric (__cpp_lib_parallel_algorithm): Likewise.
	* testsuite/25_algorithms/pstl/feature_test.cc: New test.

From-SVN: r272216
2019-06-12 21:16:03 +01:00
Jonathan Wakely 801b2266de Improve static_assert messages for std::variant
Also fix a warning with -Wunused-parameter -Wsystem-headers.

	* include/std/variant (get<T>, get<N>, get_if<N>, get_if<T>)
	(variant::emplace): Change static_assert messages from "should be"
	to "must be".
	(hash<monostate>::operator()): Remove name of unused parameter.

From-SVN: r272188
2019-06-12 15:52:09 +01:00
Jonathan Wakely ce657a7414 Simplify std::scoped_lock destructor
* include/std/mutex (scoped_lock::~scoped_lock()): Use fold
	expression.

From-SVN: r272187
2019-06-12 15:52:06 +01:00
Jonathan Wakely cd0b94e650 Replace std::to_string for integers with optimized version
The std::to_chars functions from C++17 can be used to implement
std::to_string with much better performance than calling snprintf. Only
the __detail::__to_chars_len and __detail::__to_chars_10 functions are
needed for to_string, because it always outputs base 10 representations.

The return type of __detail::__to_chars_10 should not be declared before
C++17, so the function body is extracted into a new function that can be
reused by to_string and __detail::__to_chars_10.

The existing tests for to_chars rely on to_string to check for correct
answers. Now that they use the same code that doesn't actually ensure
correctness, so add new tests for std::to_string that compare against
printf output.

	* include/Makefile.am: Add new <bits/charconv.h> header.
	* include/Makefile.in: Regenerate.
	* include/bits/basic_string.h (to_string(int), to_string(unsigned))
	(to_string(long), to_string(unsigned long), to_string(long long))
	(to_string(unsigned long long)): Rewrite to use __to_chars_10_impl.
	* include/bits/charconv.h: New header.
	(__detail::__to_chars_len): Move here from <charconv>.
	(__detail::__to_chars_10_impl): New function extracted from
	__detail::__to_chars_10.
	* include/std/charconv (__cpp_lib_to_chars): Add, but comment out.
	(__to_chars_unsigned_type): New class template that reuses
	__make_unsigned_selector_base::__select to pick a type.
	(__unsigned_least_t): Redefine as __to_chars_unsigned_type<T>::type.
	(__detail::__to_chars_len): Move to new header.
	(__detail::__to_chars_10): Add inline specifier. Move code doing the
	output to __detail::__to_chars_10_impl and call that.
	* include/std/version (__cpp_lib_to_chars): Add, but comment out.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	to_string.cc: Fix reference in comment. Remove unused variable.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	to_string_int.cc: New test.

From-SVN: r272186
2019-06-12 15:52:02 +01:00
Thomas Rodgers f32ee8a25e Synchronize libstdc++ PSTL with upstream LLVM PSTL
Rename PSTL macro's consistent with libstdc++ (and llvm upstream
	project) standards.
	* include/bits/c++config: Rename all macros of the form __PSTL* to
	_PSTL*.
	* include/std/algorithm: Likewise.
	* include/std/execution: Likewise.
	* include/std/numeric: Likewise.
	* include/std/memory: Likewise.
	* include/pstl/glue_memory_impl.h: Likewise.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/glue_memory_defs.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/utils.h: Likewise.
	* include/pstl/algorithm_fwd.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/parallel_impl.h: Likewise.
	* include/pstl/memory_impl.h: Likewise.
	* include/pstl/glue_numeric_defs.h: Likewise.
	* include/pstl/parallel_backend_utils.h: Likewise.
	* include/pstl/glue_algorithm_defs.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/glue_numeric_impl.h: Likewise.
	* include/pstl/parallel_backend_tbb.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* testsuite/util/pstl/pstl_test_config.h: Likewise.
	* testsuite/util/pstl/test_utils.h: Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_construct.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_copy_move.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/adjacent_difference.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/scan.cc: Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/transform_scan.cc: Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/reduce.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/nth_element.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_if.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/none_of.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/count.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/equal.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/all_of.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_first_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/is_heap.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/lexicographical_compare.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/merge.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique_copy_equal.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/replace_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/is_partitioned.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/remove.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_if.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_move.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/any_of.cc: Likewise.

	Rename header guards to be consistent with upstream project's
	conventions.
	* include/pstl/glue_memory_impl.h: Rename all macros of the form
	_PSTL_(.*)_H to _PSTL_\U\1_H.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/glue_memory_defs.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/utils.h: Likewise.
	* include/pstl/algorithm_fwd.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/parallel_impl.h: Likewise.
	* include/pstl/memory_impl.h: Likewise.
	* include/pstl/glue_numeric_defs.h: Likewise.
	* include/pstl/parallel_backend_utils.h: Likewise.
	* include/pstl/glue_algorithm_defs.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/glue_numeric_impl.h: Likewise.
	* include/pstl/parallel_backend_tbb.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* testsuite/util/pstl/pstl_test_config.h: Likewise.

	Synchronize libstdc++ parallel algorithms with upstream
	project.
	* include/pstl/algorithm_fwd.h: Synchronize with
	upstream PSTL project.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/parallel_backend_serial.h: New file.
	* include/Makefile.am (pstl_headers): Add
	parallel_backend_serial.h.
	* include/Makefile.in: Regenerate.

	Clean up non-conforming names
	* include/pstl/algorithm_impl.h (__parallel_set_union_op):
	Uglfiy copy_range1 and copy_range2
	(__pattern_walk2_n): Rename local n to __n
	* include/pstl/parallel_backend_tbb.h (struct __binary_no_op):
	Rename parameter _T to _Tp.

	Integrate non-TBB serial backend support
	* include/bits/c++config: Adjust TBB detection logic to select serial
	PSTL backend if no TBB present.
	* testsuite/utils/pstl/test_utils.h: Remove check for
	_PSTL_USE_PAR_POLICIES

From-SVN: r272056
2019-06-07 22:01:16 +00:00
Jonathan Wakely beb0086f59 Avoid unnecessary inclusion of <stdexcept> header
This can greatly reduce the amount of preprocessed code that is included
by other headers, because <stdexcept> depends on <string> which is huge.

	* include/std/array: Do not include <stdexcept>.
	* include/std/optional: Include <exception> and
	<bits/exception_defines.h> instead of <stdexcept>.
	* testsuite/20_util/function_objects/searchers.cc: Include <cctype>
	for std::isalnum.
	* testsuite/20_util/tuple/cons/deduction.cc: Include <memory> for
	std::allocator.
	* testsuite/23_containers/map/erasure.cc: Include <string>.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.

From-SVN: r272011
2019-06-06 16:34:56 +01:00
Jonathan Wakely 209ee62421 Remove redundant static assertions in [meta.unary.prop] traits
The type property predicates that are implemented by a compiler builtin
already do the right checks in the compiler. The checks for complete
type or unbounded arrays were wrong for these types anyway.

	* include/std/type_traits (is_empty, is_polymorphic, is_final)
	(is_abstract, is_aggregate): Remove static_assert.
	* testsuite/20_util/is_abstract/incomplete_neg.cc: Check for error
	from builtin only.
	* testsuite/20_util/is_aggregate/incomplete_neg.cc: Likewise. Add
	missing -std=gnu++17 option.
	* testsuite/20_util/is_empty/incomplete_neg.cc: New test.
	* testsuite/20_util/is_final/incomplete_neg.cc: New test.
	* testsuite/20_util/is_polymorphic/incomplete_neg.cc: Check for error
	from builtin only.

From-SVN: r272000
2019-06-06 13:13:47 +01:00