| 1 |
// { dg-do run } |
| 2 |
// { dg-options "-std=c++14 -O3" } |
| 3 |
|
| 4 |
#define enum enum __attribute((mode(SI))) |
| 5 |
namespace std { |
| 6 |
typedef int size_t; |
| 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...> |
| 11 |
struct A { |
| 12 |
using type = int; |
| 13 |
}; |
| 14 |
template <typename _Default, template <typename...> class _Op, |
| 15 |
typename... _Args> |
| 16 |
struct A<_Default, __void_t<_Op<_Args...>>, _Op, _Args...> { |
| 17 |
using type = _Op<_Args...>; |
| 18 |
}; |
| 19 |
template <typename _Default, template <typename...> class _Op, |
| 20 |
typename... _Args> |
| 21 |
using __detected_or = A<_Default, void, _Op, _Args...>; |
| 22 |
template <typename _Default, template <typename...> class _Op, |
| 23 |
typename... _Args> |
| 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) { |
| 31 |
__distance(p1); |
| 32 |
} |
| 33 |
template <typename, typename> using __replace_first_arg_t = int; |
| 34 |
struct B { |
| 35 |
template <typename _Up> using rebind = _Up *; |
| 36 |
}; |
| 37 |
template <typename, typename> using __ptr_rebind = B; |
| 38 |
template <typename _Tp> _Tp max(_Tp p1, _Tp) { return p1; } |
| 39 |
} |
| 40 |
void *operator new(__SIZE_TYPE__, void *p2) { return p2; } |
| 41 |
template <typename _Tp> struct C { |
| 42 |
typedef _Tp *pointer; |
| 43 |
pointer allocate(int p1) { |
| 44 |
return static_cast<_Tp *>(operator new(p1 * sizeof(_Tp))); |
| 45 |
} |
| 46 |
template <typename _Up> void construct(_Up *p1) { new (p1) _Up; } |
| 47 |
}; |
| 48 |
namespace std { |
| 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; }; |
| 53 |
}; |
| 54 |
struct D { |
| 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; |
| 60 |
}; |
| 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>; |
| 67 |
using const_pointer = |
| 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) { |
| 72 |
_Alloc __a; |
| 73 |
__a.construct(p1); |
| 74 |
} |
| 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) { |
| 78 |
_S_construct(p2); |
| 79 |
} |
| 80 |
}; |
| 81 |
} |
| 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; |
| 85 |
}; |
| 86 |
}; |
| 87 |
namespace std { |
| 88 |
template <typename _ForwardIterator, typename _Tp, typename _Allocator> |
| 89 |
void __uninitialized_fill_a(_ForwardIterator p1, _ForwardIterator, _Tp, |
| 90 |
_Allocator p4) try { |
| 91 |
O<_Allocator>::construct(p4, p1, 0); |
| 92 |
} catch (...) { |
| 93 |
} |
| 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; |
| 100 |
_Elt_pointer _M_cur; |
| 101 |
_Elt_pointer _M_first; |
| 102 |
_Elt_pointer _M_last; |
| 103 |
_Map_pointer _M_node; |
| 104 |
F() {} |
| 105 |
F(__iter<_Tp> &p1) : _M_cur(p1._M_cur), _M_node(p1._M_node) {} |
| 106 |
_Ref operator*() { return *_M_cur; } |
| 107 |
void operator++() { |
| 108 |
_M_set_node(_M_node + 1); |
| 109 |
_M_cur = _M_first; |
| 110 |
} |
| 111 |
void _M_set_node(_Map_pointer p1) { |
| 112 |
_M_node = p1; |
| 113 |
_M_first = *p1; |
| 114 |
_M_last = _M_first; |
| 115 |
} |
| 116 |
}; |
| 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; |
| 120 |
} |
| 121 |
template <typename _Tp, typename _Ref, typename _Ptr> |
| 122 |
int operator!=(F<_Tp, _Ref, _Ptr> p1, F<_Tp, _Ref, _Ptr> p2) { |
| 123 |
return !(p1 == p2); |
| 124 |
} |
| 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 { |
| 136 |
_Map_pointer _M_map; |
| 137 |
size_t _M_map_size; |
| 138 |
iterator _M_start; |
| 139 |
iterator _M_finish; |
| 140 |
L(_Tp_alloc_type) {} |
| 141 |
}; |
| 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); |
| 147 |
} |
| 148 |
void _M_initialize_map(size_t); |
| 149 |
void _M_create_nodes(_Map_pointer, _Map_pointer); |
| 150 |
enum { _S_initial_map_size = 8 }; |
| 151 |
L _M_impl; |
| 152 |
}; |
| 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; |
| 162 |
try { |
| 163 |
_M_create_nodes(__nstart, __nfinish); |
| 164 |
} catch (...) { |
| 165 |
} |
| 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; |
| 170 |
} |
| 171 |
template <typename _Tp, typename _Alloc> |
| 172 |
void _Deque_base<_Tp, _Alloc>::_M_create_nodes(_Map_pointer __nstart, |
| 173 |
_Map_pointer __nfinish) { |
| 174 |
_Map_pointer __cur; |
| 175 |
try { |
| 176 |
for (__cur = __nstart; __cur < __nfinish; ++__cur) |
| 177 |
*__cur = _M_allocate_node(); |
| 178 |
} catch (...) { |
| 179 |
} |
| 180 |
} |
| 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()) |
| 191 |
: _Base(__a, 0) { |
| 192 |
_M_fill_initialize(__value); |
| 193 |
} |
| 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 &); |
| 197 |
}; |
| 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 &) { |
| 204 |
_Map_pointer __cur; |
| 205 |
try { |
| 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()); |
| 209 |
} catch (...) { |
| 210 |
} |
| 211 |
} |
| 212 |
template <class> struct char_traits; |
| 213 |
namespace __cxx11 { |
| 214 |
template <typename _CharT, typename = char_traits<_CharT>, |
| 215 |
typename = allocator<_CharT>> |
| 216 |
struct basic_string; |
| 217 |
typedef basic_string<char> string; |
| 218 |
} |
| 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); |
| 223 |
} |
| 224 |
}; |
| 225 |
namespace __cxx11 { |
| 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>()); |
| 232 |
} _M_dataplus; |
| 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; } |
| 239 |
}; |
| 240 |
//template<> basic_string<char, std::char_traits<char>, std::allocator<char>>:: |
| 241 |
//_Alloc_hider::_Alloc_hider(char*, std::allocator<char>&&) {} |
| 242 |
extern "C" void |
| 243 |
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderC1EPcOS3_ (...) {} |
| 244 |
} |
| 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()); |
| 248 |
} |
| 249 |
} |
| 250 |
struct G { |
| 251 |
template <class Facade> static void increment(Facade p1) { p1.increment(); } |
| 252 |
}; |
| 253 |
template <class Derived> struct H { |
| 254 |
Derived derived() { return *static_cast<Derived *>(this); } |
| 255 |
void operator++() { |
| 256 |
Derived __trans_tmp_1 = derived(); |
| 257 |
G::increment(__trans_tmp_1); |
| 258 |
} |
| 259 |
}; |
| 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; } |
| 265 |
Base m_iterator; |
| 266 |
}; |
| 267 |
template <class, class> struct N; |
| 268 |
template <class Predicate, class Iterator> struct J { |
| 269 |
typedef M<N<Predicate, Iterator>, Iterator> type; |
| 270 |
}; |
| 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) {} |
| 276 |
void increment() { |
| 277 |
while (this->base() != m_end && !m_predicate(*this->base())) |
| 278 |
++this->base_reference(); |
| 279 |
} |
| 280 |
Predicate m_predicate; |
| 281 |
Iterator m_end; |
| 282 |
}; |
| 283 |
template <class Predicate, class Iterator> |
| 284 |
N<Predicate, Iterator> make_filter_iterator(Predicate p1, Iterator p2, |
| 285 |
Iterator p3) { |
| 286 |
return N<Predicate, Iterator>(p1, p2, p3); |
| 287 |
} |
| 288 |
struct Foo { |
| 289 |
std::string bar; |
| 290 |
}; |
| 291 |
int main() { |
| 292 |
std::deque<Foo> foos(0, {}); |
| 293 |
std::string test; |
| 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); |
| 298 |
} |