Commit b8a28a06 by Jonathan Wakely

libstdc++: Define __cpp_lib_ranges macro for C++20

Define the feature test macro now that ranges support is complete.

This also changes the preprocessor checks for the __cpp_concepts macro
so that library components depending on concepts are only enabled when
C++20 concepts are supported, and not just for the Concepts TS (which
uses different syntax in places).

	* include/bits/range_cmp.h (__cpp_lib_ranges): Define.
	* include/bits/stl_iterator.h: Check value of __cpp_concepts so that
	C++20 concepts are required.
	* include/bits/stl_iterator_base_types.h: Likewise.
	* include/std/concepts: Likewise.
	* include/std/version: Likewise.
	* testsuite/std/ranges/headers/ranges/synopsis.cc: Check feature test
	macro.
parent 81a8d137
2020-03-27 Jonathan Wakely <jwakely@redhat.com> 2020-03-27 Jonathan Wakely <jwakely@redhat.com>
* include/bits/range_cmp.h (__cpp_lib_ranges): Define.
* include/bits/stl_iterator.h: Check value of __cpp_concepts so that
C++20 concepts are required.
* include/bits/stl_iterator_base_types.h: Likewise.
* include/std/concepts: Likewise.
* include/std/version: Likewise.
* testsuite/std/ranges/headers/ranges/synopsis.cc: Check feature test
macro.
* include/bits/stl_iterator.h (reverse_iterator::iterator_concept) * include/bits/stl_iterator.h (reverse_iterator::iterator_concept)
(reverse_iterator::iterator_category): Define for C++20. (reverse_iterator::iterator_category): Define for C++20.
(reverse_iterator): Define comparison operators correctly for C++20. (reverse_iterator): Define comparison operators correctly for C++20.
......
...@@ -55,6 +55,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -55,6 +55,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}; };
#ifdef __cpp_lib_concepts #ifdef __cpp_lib_concepts
// Define this here, included by all the headers that need to define it.
#define __cpp_lib_ranges 201911L
namespace ranges namespace ranges
{ {
namespace __detail namespace __detail
......
...@@ -214,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -214,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/ */
_GLIBCXX17_CONSTEXPR pointer _GLIBCXX17_CONSTEXPR pointer
operator->() const operator->() const
#if __cplusplus > 201703L && defined __cpp_concepts #if __cplusplus > 201703L && __cpp_concepts >= 201907L
requires is_pointer_v<_Iterator> requires is_pointer_v<_Iterator>
|| requires(const _Iterator __i) { __i.operator->(); } || requires(const _Iterator __i) { __i.operator->(); }
#endif #endif
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
# include <type_traits> // For __void_t, is_convertible # include <type_traits> // For __void_t, is_convertible
#endif #endif
#if __cplusplus > 201703L && __cpp_concepts #if __cplusplus > 201703L && __cpp_concepts >= 201907L
# include <bits/iterator_concepts.h> # include <bits/iterator_concepts.h>
#endif #endif
...@@ -192,7 +192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -192,7 +192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus > 201703L #if __cplusplus > 201703L
/// Partial specialization for object pointer types. /// Partial specialization for object pointer types.
template<typename _Tp> template<typename _Tp>
#if __cpp_concepts #if __cpp_concepts >= 201907L
requires is_object_v<_Tp> requires is_object_v<_Tp>
#endif #endif
struct iterator_traits<_Tp*> struct iterator_traits<_Tp*>
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#ifndef _GLIBCXX_CONCEPTS #ifndef _GLIBCXX_CONCEPTS
#define _GLIBCXX_CONCEPTS 1 #define _GLIBCXX_CONCEPTS 1
#if __cplusplus > 201703L && __cpp_concepts #if __cplusplus > 201703L && __cpp_concepts >= 201907L
#pragma GCC system_header #pragma GCC system_header
......
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
#define __cpp_lib_nonmember_container_access 201411 #define __cpp_lib_nonmember_container_access 201411
#define __cpp_lib_not_fn 201603 #define __cpp_lib_not_fn 201603
#define __cpp_lib_optional 201606L #define __cpp_lib_optional 201606L
#define __cpp_lib_parallel_algorithm 201603L
#define __cpp_lib_raw_memory_algorithms 201606L #define __cpp_lib_raw_memory_algorithms 201606L
#define __cpp_lib_sample 201603 #define __cpp_lib_sample 201603
#ifdef _GLIBCXX_HAS_GTHREADS #ifdef _GLIBCXX_HAS_GTHREADS
...@@ -158,7 +159,6 @@ ...@@ -158,7 +159,6 @@
#define __cpp_lib_unordered_map_insertion 201411 #define __cpp_lib_unordered_map_insertion 201411
#define __cpp_lib_unordered_map_try_emplace 201411 #define __cpp_lib_unordered_map_try_emplace 201411
#define __cpp_lib_variant 201606L #define __cpp_lib_variant 201606L
#define __cpp_lib_parallel_algorithm 201603L
#endif #endif
#if __cplusplus > 201703L #if __cplusplus > 201703L
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
#define __cpp_lib_atomic_value_initialization 201911L #define __cpp_lib_atomic_value_initialization 201911L
#define __cpp_lib_bitops 201907L #define __cpp_lib_bitops 201907L
#define __cpp_lib_bounded_array_traits 201902L #define __cpp_lib_bounded_array_traits 201902L
#if __cpp_concepts #if __cpp_concepts >= 201907L
# define __cpp_lib_concepts 201806L # define __cpp_lib_concepts 201806L
#endif #endif
#if __cpp_impl_destroying_delete #if __cpp_impl_destroying_delete
...@@ -195,6 +195,9 @@ ...@@ -195,6 +195,9 @@
#endif #endif
#define __cpp_lib_list_remove_return_type 201806L #define __cpp_lib_list_remove_return_type 201806L
#define __cpp_lib_math_constants 201907L #define __cpp_lib_math_constants 201907L
#if __cpp_lib_concepts
# define __cpp_lib_ranges 201911L
#endif
#define __cpp_lib_span 202002L #define __cpp_lib_span 202002L
#if __cpp_impl_three_way_comparison >= 201907L && __cpp_lib_concepts #if __cpp_impl_three_way_comparison >= 201907L && __cpp_lib_concepts
# define __cpp_lib_three_way_comparison 201711L # define __cpp_lib_three_way_comparison 201711L
......
...@@ -45,16 +45,17 @@ static_assert(std::input_iterator<move_only_iterator>); ...@@ -45,16 +45,17 @@ static_assert(std::input_iterator<move_only_iterator>);
template<typename T> template<typename T>
concept has_member_base = requires (T t) { std::forward<T>(t).base(); }; concept has_member_base = requires (T t) { std::forward<T>(t).base(); };
static_assert( ! has_member_base<std::move_iterator<move_iterator>&> ); using move_only_move_iterator = std::move_iterator<move_only_iterator>;
static_assert( ! has_member_base<const std::move_iterator<move_iterator>&> );
static_assert( has_member_base<std::move_iterator<move_iterator>> ); static_assert( ! has_member_base<move_only_move_iterator&> );
static_assert( ! has_member_base<const std::move_iterator<move_iterator>> ); static_assert( ! has_member_base<const move_only_move_iterator&> );
static_assert( has_member_base<move_only_move_iterator> );
static_assert( ! has_member_base<const move_only_move_iterator> );
void void
test01() test01()
{ {
std::move_iterator<move_only_iterator> m1, m2; move_only_move_iterator m1 = std::make_move_iterator(move_only_iterator{});
m1 = std::make_move_iterator(move_only_iterator{}); move_only_move_iterator m2;
m2 = std::move(m1); m2 = std::move(m1);
m1.swap(m2);
} }
...@@ -48,15 +48,10 @@ struct Iter ...@@ -48,15 +48,10 @@ struct Iter
template<int N> friend Iter operator-(Iter<N>, difference_type); template<int N> friend Iter operator-(Iter<N>, difference_type);
template<int N> friend difference_type operator-(Iter<N>, Iter<N>); template<int N> friend difference_type operator-(Iter<N>, Iter<N>);
// Define the full set of operators for same-type comparisons template<int N> friend bool operator==(Iter<N>, Iter<N>);
template<int N> friend bool operator==(Iter<N>, Iter<N>); // synthesizes != template<int N> friend std::weak_ordering operator<=>(Iter<N>, Iter<N>);
template<int N> friend bool operator<(Iter<N>, Iter<N>);
template<int N> friend bool operator>(Iter<N>, Iter<N>);
template<int N> friend bool operator<=(Iter<N>, Iter<N>);
template<int N> friend bool operator>=(Iter<N>, Iter<N>);
}; };
static_assert( std::random_access_iterator<Iter<0>> ); static_assert( std::random_access_iterator<Iter<0>> );
int operator==(Iter<0>, long*); int operator==(Iter<0>, long*);
......
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
#include <ranges> #include <ranges>
#ifndef __cpp_lib_ranges
# error "Feature test macro for ranges is missing in <ranges>"
#elif __cpp_lib_ranges < 201911L
# error "Feature test macro for ranges has wrong value in <ranges>"
#endif
struct R { }; struct R { };
template<> constexpr bool std::ranges::disable_sized_range<R> = true; template<> constexpr bool std::ranges::disable_sized_range<R> = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment