2 // { dg-options "-std=c++14 -O3" }
4 #define enum enum __attribute((mode(SI)))
7 inline namespace __cxx11 {}
8 template <typename...> using _Require = void;
9 template <typename> using __void_t = void;
10 template <typename, typename, template <typename...> class, typename...>
14 template <typename _Default, template <typename...> class _Op,
16 struct A<_Default, __void_t<_Op<_Args...>>, _Op, _Args...> {
17 using type = _Op<_Args...>;
19 template <typename _Default, template <typename...> class _Op,
21 using __detected_or = A<_Default, void, _Op, _Args...>;
22 template <typename _Default, template <typename...> class _Op,
24 using __detected_or_t = typename __detected_or<_Default, _Op, _Args...>::type;
25 template <template <typename...> class _Default,
26 template <typename...> class _Op, typename... _Args>
27 using __detected_or_t_ = __detected_or_t<_Default<_Args...>, _Op, _Args...>;
28 template <typename _InputIterator> void __distance(_InputIterator p1) { ++p1; }
29 template <typename _InputIterator>
30 void distance(_InputIterator p1, _InputIterator) {
33 template <typename, typename> using __replace_first_arg_t = int;
35 template <typename _Up> using rebind = _Up *;
37 template <typename, typename> using __ptr_rebind = B;
38 template <typename _Tp> _Tp max(_Tp p1, _Tp) { return p1; }
40 void *operator new(__SIZE_TYPE__, void *p2) { return p2; }
41 template <typename _Tp> struct C {
43 pointer allocate(int p1) {
44 return static_cast<_Tp *>(operator new(p1 * sizeof(_Tp)));
46 template <typename _Up> void construct(_Up *p1) { new (p1) _Up; }
49 template <typename _Tp> using __allocator_base = C<_Tp>;
50 template <typename _Tp> struct allocator : __allocator_base<_Tp> {
51 typedef __SIZE_TYPE__ size_type;
52 template <typename _Tp1> struct rebind { typedef allocator<_Tp1> other; };
55 template <typename _Alloc, typename _Up>
56 using __rebind = typename _Alloc::template rebind<_Up>::other;
57 template <typename _Tp> using __pointer = typename _Tp::pointer;
58 template <typename _Tp> using __c_pointer = typename _Tp::const_pointer;
59 template <typename _Tp> using __size_type = typename _Tp::size_type;
61 template <typename _Alloc, typename _Up>
62 using __alloc_rebind =
63 __detected_or_t_<__replace_first_arg_t, D::__rebind, _Alloc, _Up>;
64 template <typename _Alloc> struct K : D {
65 typedef _Alloc value_type;
66 using pointer = __detected_or_t<value_type, __pointer, _Alloc>;
68 __detected_or_t<__ptr_rebind<pointer, value_type>, __c_pointer>;
69 using size_type = __detected_or_t<int, __size_type, _Alloc>;
70 template <typename _Tp> using rebind_alloc = __alloc_rebind<_Alloc, _Tp>;
71 template <typename _Tp> static _Require<> _S_construct(_Tp p1) {
75 static pointer allocate(_Alloc p1, size_type p2) { return p1.allocate(p2); }
76 template <typename _Tp, typename _Args>
77 static auto construct(_Alloc, _Tp p2, _Args) {
82 template <typename _Alloc> struct O : std::K<_Alloc> {
83 template <typename _Tp> struct rebind {
84 typedef typename std::K<_Alloc>::template rebind_alloc<_Tp> other;
88 template <typename _ForwardIterator, typename _Tp, typename _Allocator>
89 void __uninitialized_fill_a(_ForwardIterator p1, _ForwardIterator, _Tp,
91 O<_Allocator>::construct(p4, p1, 0);
94 size_t __deque_buf_size(size_t p1) { return 1 ? 512 / p1 : 0; }
95 template <typename _Tp, typename _Ref, typename> struct F {
96 template <typename _Up> using __ptr_to = B::rebind<_Up>;
97 template <typename _CvTp> using __iter = F<_Tp, _CvTp &, __ptr_to<_CvTp>>;
98 typedef __ptr_to<_Tp> _Elt_pointer;
99 typedef __ptr_to<_Elt_pointer> _Map_pointer;
101 _Elt_pointer _M_first;
102 _Elt_pointer _M_last;
103 _Map_pointer _M_node;
105 F(__iter<_Tp> &p1) : _M_cur(p1._M_cur), _M_node(p1._M_node) {}
106 _Ref operator*() { return *_M_cur; }
108 _M_set_node(_M_node + 1);
111 void _M_set_node(_Map_pointer p1) {
117 template <typename _Tp, typename _Ref, typename _Ptr>
118 int operator==(F<_Tp, _Ref, _Ptr> p1, F<_Tp, _Ref, _Ptr> p2) {
119 return p1._M_cur == p2._M_cur;
121 template <typename _Tp, typename _Ref, typename _Ptr>
122 int operator!=(F<_Tp, _Ref, _Ptr> p1, F<_Tp, _Ref, _Ptr> p2) {
125 template <typename _Tp, typename _Alloc> struct _Deque_base {
126 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
127 typedef O<_Tp_alloc_type> _Alloc_traits;
128 typedef typename _Alloc_traits::pointer _Ptr;
129 typedef typename _Alloc_traits::template rebind<_Ptr>::other _Map_alloc_type;
130 typedef F<_Tp, _Tp &, _Ptr> iterator;
131 typedef F<_Tp, _Tp &, typename _Alloc_traits::const_pointer> const_iterator;
132 _Deque_base(_Alloc p1, size_t) : _M_impl(p1) { _M_initialize_map(0); }
133 ~_Deque_base() noexcept;
134 typedef typename iterator::_Map_pointer _Map_pointer;
135 struct L : _Tp_alloc_type {
142 _Tp_alloc_type _M_get_Tp_allocator() { return _M_impl; }
143 _Ptr _M_allocate_node() { return O<_Tp_alloc_type>::allocate(_M_impl, 1); }
144 _Map_pointer _M_allocate_map(size_t p1) {
145 _Map_alloc_type __map_alloc;
146 return O<_Map_alloc_type>::allocate(__map_alloc, p1);
148 void _M_initialize_map(size_t);
149 void _M_create_nodes(_Map_pointer, _Map_pointer);
150 enum { _S_initial_map_size = 8 };
153 template <typename _Tp, typename _Alloc>
154 _Deque_base<_Tp, _Alloc>::~_Deque_base() noexcept {}
155 template <typename _Tp, typename _Alloc>
156 void _Deque_base<_Tp, _Alloc>::_M_initialize_map(size_t) {
157 size_t __num_nodes(__deque_buf_size(sizeof(_Tp)));
158 _M_impl._M_map_size = max((size_t)_S_initial_map_size, 0);
159 _M_impl._M_map = _M_allocate_map(_M_impl._M_map_size);
160 _Map_pointer __nstart(_M_impl._M_map);
161 _Map_pointer __nfinish = __nstart + __num_nodes;
163 _M_create_nodes(__nstart, __nfinish);
166 _M_impl._M_start._M_set_node(__nstart);
167 _M_impl._M_finish._M_set_node(__nfinish - 1);
168 _M_impl._M_start._M_cur = _M_impl._M_start._M_first;
169 _M_impl._M_finish._M_cur = _M_impl._M_finish._M_first;
171 template <typename _Tp, typename _Alloc>
172 void _Deque_base<_Tp, _Alloc>::_M_create_nodes(_Map_pointer __nstart,
173 _Map_pointer __nfinish) {
176 for (__cur = __nstart; __cur < __nfinish; ++__cur)
177 *__cur = _M_allocate_node();
181 template <typename _Tp, typename _Alloc = allocator<_Tp>>
182 struct deque : _Deque_base<_Tp, _Alloc> {
183 typedef _Deque_base<_Tp, _Alloc> _Base;
184 typedef typename _Base::_Map_pointer _Map_pointer;
185 typedef _Tp value_type;
186 typedef typename _Base::const_iterator const_iterator;
187 typedef size_t size_type;
188 typedef _Alloc allocator_type;
189 using _Base::_M_get_Tp_allocator;
190 deque(size_type, value_type __value, allocator_type __a = allocator_type())
192 _M_fill_initialize(__value);
194 const_iterator begin() { return this->_M_impl._M_start; }
195 const_iterator end() { return this->_M_impl._M_finish; }
196 void _M_fill_initialize(const value_type &);
198 template <typename _Container> auto begin(_Container p1) { return p1.begin(); }
199 template <typename _Container> auto end(_Container p1) { return p1.end(); }
200 template <typename _Container> auto cbegin(_Container p1) { return begin(p1); }
201 template <typename _Container> auto cend(_Container p1) { return end(p1); }
202 template <typename _Tp, typename _Alloc>
203 void deque<_Tp, _Alloc>::_M_fill_initialize(const value_type &) {
206 for (__cur = this->_M_impl._M_start._M_node;
207 __cur < this->_M_impl._M_finish._M_node; ++__cur)
208 __uninitialized_fill_a(*__cur, *__cur, 0, _M_get_Tp_allocator());
212 template <class> struct char_traits;
214 template <typename _CharT, typename = char_traits<_CharT>,
215 typename = allocator<_CharT>>
217 typedef basic_string<char> string;
219 template <> struct char_traits<char> {
220 typedef char char_type;
221 static int compare(char_type, char_type *p2, size_t p3) {
222 return __builtin_memcmp(0, p2, p3);
226 template <typename, typename, typename> struct basic_string {
227 typedef O<allocator<char>> _Alloc_traits;
228 typedef _Alloc_traits::size_type size_type;
229 typedef _Alloc_traits::pointer pointer;
230 struct _Alloc_hider {
231 _Alloc_hider(pointer, allocator<char> && = allocator<char>());
233 size_type _M_string_length = 0;
234 enum { _S_local_capacity = 15 } _M_local_buf[_S_local_capacity];
235 basic_string() : _M_dataplus(0) {}
236 basic_string(const basic_string &) : _M_dataplus(0) {}
237 size_type size() { return _M_string_length; }
238 char *data() const { return 0; }
240 //template<> basic_string<char, std::char_traits<char>, std::allocator<char>>::
241 //_Alloc_hider::_Alloc_hider(char*, std::allocator<char>&&) {}
243 _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderC1EPcOS3_ (...) {}
245 template <typename _CharT>
246 int operator==(basic_string<_CharT> &p1, const basic_string<_CharT> &p2) {
247 return p1.size() && char_traits<_CharT>::compare(0, p2.data(), p1.size());
251 template <class Facade> static void increment(Facade p1) { p1.increment(); }
253 template <class Derived> struct H {
254 Derived derived() { return *static_cast<Derived *>(this); }
256 Derived __trans_tmp_1 = derived();
257 G::increment(__trans_tmp_1);
260 template <class Derived> struct I { typedef H<Derived> type; };
261 template <class Derived, class Base> struct M : I<Derived>::type {
262 M(Base p1) : m_iterator(p1) {}
263 Base base() { return m_iterator; }
264 Base &base_reference() { return m_iterator; }
267 template <class, class> struct N;
268 template <class Predicate, class Iterator> struct J {
269 typedef M<N<Predicate, Iterator>, Iterator> type;
271 template <class Predicate, class Iterator>
272 struct N : J<Predicate, Iterator>::type {
273 typedef typename J<Predicate, Iterator>::type super_t;
274 N(Predicate p1, Iterator p2, Iterator p3)
275 : super_t(p2), m_predicate(p1), m_end(p3) {}
277 while (this->base() != m_end && !m_predicate(*this->base()))
278 ++this->base_reference();
280 Predicate m_predicate;
283 template <class Predicate, class Iterator>
284 N<Predicate, Iterator> make_filter_iterator(Predicate p1, Iterator p2,
286 return N<Predicate, Iterator>(p1, p2, p3);
292 std::deque<Foo> foos(0, {});
294 auto p = [test](auto &foo) { return foo.bar == test; };
295 auto begin = make_filter_iterator(p, cbegin(foos), cend(foos));
296 auto end = make_filter_iterator(p, cend(foos), cend(foos));
297 distance(begin, end);