Commit 8017d95c by Jonathan Wakely

libstdc++: Add __maybe_const_t and __maybe_empty_t aliases

This introduces a couple of convenience alias templates to be used for
some repeated patterns using std::conditional_t.

	* include/std/ranges (__detail::__maybe_empty_t): Define new helper
	alias.
	(__detail::__maybe_const_t): Likewise.
	(__adaptor::_RangeAdaptor): Use __maybe_empty_t.
	(transform_view, take_view, take_while_view, elements_view): Use
	__maybe_const_t.
	(join_view, split_view): Use both.
parent 4a305fa2
2020-02-26 Jonathan Wakely <jwakely@redhat.com>
* include/std/ranges (__detail::__maybe_empty_t): Define new helper
alias.
(__detail::__maybe_const_t): Likewise.
(__adaptor::_RangeAdaptor): Use __maybe_empty_t.
(transform_view, take_view, take_while_view, elements_view): Use
__maybe_const_t.
(join_view, split_view): Use both.
2020-02-25 Patrick Palka <ppalka@redhat.com> 2020-02-25 Patrick Palka <ppalka@redhat.com>
LWG 3397 basic_istream_view::iterator should not provide LWG 3397 basic_istream_view::iterator should not provide
......
...@@ -1029,6 +1029,13 @@ namespace views ...@@ -1029,6 +1029,13 @@ namespace views
namespace __detail namespace __detail
{ {
struct _Empty { }; struct _Empty { };
template<bool _NonEmpty, typename _Tp>
using __maybe_empty_t = conditional_t<_NonEmpty, _Tp, _Empty>;
template<bool _Const, typename _Tp>
using __maybe_const_t = conditional_t<_Const, const _Tp, _Tp>;
} // namespace __detail } // namespace __detail
namespace views namespace views
...@@ -1058,8 +1065,8 @@ namespace views ...@@ -1058,8 +1065,8 @@ namespace views
{ {
protected: protected:
[[no_unique_address]] [[no_unique_address]]
conditional_t<!is_default_constructible_v<_Callable>, __detail::__maybe_empty_t<!is_default_constructible_v<_Callable>,
_Callable, __detail::_Empty> _M_callable; _Callable> _M_callable;
public: public:
constexpr constexpr
...@@ -1552,9 +1559,8 @@ namespace views ...@@ -1552,9 +1559,8 @@ namespace views
struct _Iterator struct _Iterator
{ {
private: private:
using _Parent using _Parent = __detail::__maybe_const_t<_Const, transform_view>;
= conditional_t<_Const, const transform_view, transform_view>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
using _Base = conditional_t<_Const, const _Vp, _Vp>;
static constexpr auto static constexpr auto
_S_iter_concept() _S_iter_concept()
...@@ -1760,9 +1766,8 @@ namespace views ...@@ -1760,9 +1766,8 @@ namespace views
struct _Sentinel struct _Sentinel
{ {
private: private:
using _Parent using _Parent = __detail::__maybe_const_t<_Const, transform_view>;
= conditional_t<_Const, const transform_view, transform_view>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
using _Base = conditional_t<_Const, const _Vp, _Vp>;
constexpr range_difference_t<_Base> constexpr range_difference_t<_Base>
__distance_from(const _Iterator<_Const>& __i) const __distance_from(const _Iterator<_Const>& __i) const
...@@ -1886,7 +1891,7 @@ namespace views ...@@ -1886,7 +1891,7 @@ namespace views
struct _Sentinel struct _Sentinel
{ {
private: private:
using _Base = conditional_t<_Const, const _Vp, _Vp>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
using _CI = counted_iterator<iterator_t<_Base>>; using _CI = counted_iterator<iterator_t<_Base>>;
sentinel_t<_Base> _M_end = sentinel_t<_Base>(); sentinel_t<_Base> _M_end = sentinel_t<_Base>();
...@@ -2025,7 +2030,7 @@ namespace views ...@@ -2025,7 +2030,7 @@ namespace views
struct _Sentinel struct _Sentinel
{ {
private: private:
using _Base = conditional_t<_Const, const _Vp, _Vp>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
sentinel_t<_Base> _M_end = sentinel_t<_Base>(); sentinel_t<_Base> _M_end = sentinel_t<_Base>();
const _Pred* _M_pred = nullptr; const _Pred* _M_pred = nullptr;
...@@ -2258,8 +2263,8 @@ namespace views ...@@ -2258,8 +2263,8 @@ namespace views
struct _Iterator struct _Iterator
{ {
private: private:
using _Parent = conditional_t<_Const, const join_view, join_view>; using _Parent = __detail::__maybe_const_t<_Const, join_view>;
using _Base = conditional_t<_Const, const _Vp, _Vp>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
static constexpr bool _S_ref_is_glvalue static constexpr bool _S_ref_is_glvalue
= is_reference_v<range_reference_t<_Base>>; = is_reference_v<range_reference_t<_Base>>;
...@@ -2450,8 +2455,8 @@ namespace views ...@@ -2450,8 +2455,8 @@ namespace views
struct _Sentinel struct _Sentinel
{ {
private: private:
using _Parent = conditional_t<_Const, const join_view, join_view>; using _Parent = __detail::__maybe_const_t<_Const, join_view>;
using _Base = conditional_t<_Const, const _Vp, _Vp>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
constexpr bool constexpr bool
__equal(const _Iterator<_Const>& __i) const __equal(const _Iterator<_Const>& __i) const
...@@ -2482,8 +2487,8 @@ namespace views ...@@ -2482,8 +2487,8 @@ namespace views
// XXX: _M_inner is "present only when !is_reference_v<_InnerRange>" // XXX: _M_inner is "present only when !is_reference_v<_InnerRange>"
[[no_unique_address]] [[no_unique_address]]
conditional_t<!is_reference_v<_InnerRange>, __detail::__maybe_empty_t<!is_reference_v<_InnerRange>,
views::all_t<_InnerRange>, __detail::_Empty> _M_inner; views::all_t<_InnerRange>> _M_inner;
public: public:
join_view() = default; join_view() = default;
...@@ -2585,8 +2590,8 @@ namespace views ...@@ -2585,8 +2590,8 @@ namespace views
struct _OuterIter struct _OuterIter
{ {
private: private:
using _Parent = conditional_t<_Const, const split_view, split_view>; using _Parent = __detail::__maybe_const_t<_Const, split_view>;
using _Base = conditional_t<_Const, const _Vp, _Vp>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
constexpr bool constexpr bool
__at_end() const __at_end() const
...@@ -2618,8 +2623,8 @@ namespace views ...@@ -2618,8 +2623,8 @@ namespace views
// XXX: _M_current is present only if "V models forward_range" // XXX: _M_current is present only if "V models forward_range"
[[no_unique_address]] [[no_unique_address]]
conditional_t<forward_range<_Vp>, __detail::__maybe_empty_t<forward_range<_Vp>,
iterator_t<_Base>, __detail::_Empty> _M_current; iterator_t<_Base>> _M_current;
public: public:
using iterator_concept = conditional_t<forward_range<_Base>, using iterator_concept = conditional_t<forward_range<_Base>,
...@@ -2732,7 +2737,7 @@ namespace views ...@@ -2732,7 +2737,7 @@ namespace views
struct _InnerIter struct _InnerIter
{ {
private: private:
using _Base = conditional_t<_Const, const _Vp, _Vp>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
constexpr bool constexpr bool
__at_end() const __at_end() const
...@@ -2858,8 +2863,8 @@ namespace views ...@@ -2858,8 +2863,8 @@ namespace views
// XXX: _M_current is "present only if !forward_range<V>" // XXX: _M_current is "present only if !forward_range<V>"
[[no_unique_address]] [[no_unique_address]]
conditional_t<!forward_range<_Vp>, __detail::__maybe_empty_t<!forward_range<_Vp>, iterator_t<_Vp>>
iterator_t<_Vp>, __detail::_Empty> _M_current; _M_current;
public: public:
...@@ -3223,7 +3228,7 @@ namespace views ...@@ -3223,7 +3228,7 @@ namespace views
template<bool _Const> template<bool _Const>
struct _Iterator struct _Iterator
{ {
using _Base = conditional_t<_Const, const _Vp, _Vp>; using _Base = __detail::__maybe_const_t<_Const, _Vp>;
iterator_t<_Base> _M_current = iterator_t<_Base>(); iterator_t<_Base> _M_current = iterator_t<_Base>();
......
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