OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [functional] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
//  -*- C++ -*-
2
 
3
// Copyright (C) 2001-2012 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
 
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// .
24
 
25
/*
26
 * Copyright (c) 1997
27
 * Silicon Graphics Computer Systems, Inc.
28
 *
29
 * Permission to use, copy, modify, distribute and sell this software
30
 * and its documentation for any purpose is hereby granted without fee,
31
 * provided that the above copyright notice appear in all copies and
32
 * that both that copyright notice and this permission notice appear
33
 * in supporting documentation.  Silicon Graphics makes no
34
 * representations about the suitability of this software for any
35
 * purpose.  It is provided "as is" without express or implied warranty.
36
 *
37
 */
38
 
39
/** @file include/functional
40
 *  This is a Standard C++ Library header.
41
 */
42
 
43
#ifndef _GLIBCXX_FUNCTIONAL
44
#define _GLIBCXX_FUNCTIONAL 1
45
 
46
#pragma GCC system_header
47
 
48
#include 
49
#include 
50
 
51
#if __cplusplus >= 201103L
52
 
53
#include 
54
#include 
55
#include 
56
#include 
57
#include 
58
#include 
59
 
60
namespace std _GLIBCXX_VISIBILITY(default)
61
{
62
_GLIBCXX_BEGIN_NAMESPACE_VERSION
63
 
64
  template
65
    class _Mem_fn;
66
  template
67
    _Mem_fn<_Tp _Class::*>
68
    mem_fn(_Tp _Class::*) noexcept;
69
 
70
_GLIBCXX_HAS_NESTED_TYPE(result_type)
71
 
72
  /// If we have found a result_type, extract it.
73
  template
74
    struct _Maybe_get_result_type
75
    { };
76
 
77
  template
78
    struct _Maybe_get_result_type
79
    { typedef typename _Functor::result_type result_type; };
80
 
81
  /**
82
   *  Base class for any function object that has a weak result type, as
83
   *  defined in 3.3/3 of TR1.
84
  */
85
  template
86
    struct _Weak_result_type_impl
87
    : _Maybe_get_result_type<__has_result_type<_Functor>::value, _Functor>
88
    { };
89
 
90
  /// Retrieve the result type for a function type.
91
  template
92
    struct _Weak_result_type_impl<_Res(_ArgTypes...)>
93
    { typedef _Res result_type; };
94
 
95
  template
96
    struct _Weak_result_type_impl<_Res(_ArgTypes......)>
97
    { typedef _Res result_type; };
98
 
99
  template
100
    struct _Weak_result_type_impl<_Res(_ArgTypes...) const>
101
    { typedef _Res result_type; };
102
 
103
  template
104
    struct _Weak_result_type_impl<_Res(_ArgTypes......) const>
105
    { typedef _Res result_type; };
106
 
107
  template
108
    struct _Weak_result_type_impl<_Res(_ArgTypes...) volatile>
109
    { typedef _Res result_type; };
110
 
111
  template
112
    struct _Weak_result_type_impl<_Res(_ArgTypes......) volatile>
113
    { typedef _Res result_type; };
114
 
115
  template
116
    struct _Weak_result_type_impl<_Res(_ArgTypes...) const volatile>
117
    { typedef _Res result_type; };
118
 
119
  template
120
    struct _Weak_result_type_impl<_Res(_ArgTypes......) const volatile>
121
    { typedef _Res result_type; };
122
 
123
  /// Retrieve the result type for a function reference.
124
  template
125
    struct _Weak_result_type_impl<_Res(&)(_ArgTypes...)>
126
    { typedef _Res result_type; };
127
 
128
  template
129
    struct _Weak_result_type_impl<_Res(&)(_ArgTypes......)>
130
    { typedef _Res result_type; };
131
 
132
  /// Retrieve the result type for a function pointer.
133
  template
134
    struct _Weak_result_type_impl<_Res(*)(_ArgTypes...)>
135
    { typedef _Res result_type; };
136
 
137
  template
138
    struct _Weak_result_type_impl<_Res(*)(_ArgTypes......)>
139
    { typedef _Res result_type; };
140
 
141
  /// Retrieve result type for a member function pointer.
142
  template
143
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)>
144
    { typedef _Res result_type; };
145
 
146
  template
147
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes......)>
148
    { typedef _Res result_type; };
149
 
150
  /// Retrieve result type for a const member function pointer.
151
  template
152
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) const>
153
    { typedef _Res result_type; };
154
 
155
  template
156
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes......) const>
157
    { typedef _Res result_type; };
158
 
159
  /// Retrieve result type for a volatile member function pointer.
160
  template
161
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) volatile>
162
    { typedef _Res result_type; };
163
 
164
  template
165
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes......) volatile>
166
    { typedef _Res result_type; };
167
 
168
  /// Retrieve result type for a const volatile member function pointer.
169
  template
170
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)
171
                                  const volatile>
172
    { typedef _Res result_type; };
173
 
174
  template
175
    struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes......)
176
                                  const volatile>
177
    { typedef _Res result_type; };
178
 
179
  /**
180
   *  Strip top-level cv-qualifiers from the function object and let
181
   *  _Weak_result_type_impl perform the real work.
182
  */
183
  template
184
    struct _Weak_result_type
185
    : _Weak_result_type_impl::type>
186
    { };
187
 
188
  /// Determines if the type _Tp derives from unary_function.
189
  template
190
    struct _Derives_from_unary_function : __sfinae_types
191
    {
192
    private:
193
      template
194
        static __one __test(const volatile unary_function<_T1, _Res>*);
195
 
196
      // It's tempting to change "..." to const volatile void*, but
197
      // that fails when _Tp is a function type.
198
      static __two __test(...);
199
 
200
    public:
201
      static const bool value = sizeof(__test((_Tp*)0)) == 1;
202
    };
203
 
204
  /// Determines if the type _Tp derives from binary_function.
205
  template
206
    struct _Derives_from_binary_function : __sfinae_types
207
    {
208
    private:
209
      template
210
        static __one __test(const volatile binary_function<_T1, _T2, _Res>*);
211
 
212
      // It's tempting to change "..." to const volatile void*, but
213
      // that fails when _Tp is a function type.
214
      static __two __test(...);
215
 
216
    public:
217
      static const bool value = sizeof(__test((_Tp*)0)) == 1;
218
    };
219
 
220
  /**
221
   * Invoke a function object, which may be either a member pointer or a
222
   * function object. The first parameter will tell which.
223
   */
224
  template
225
    inline
226
    typename enable_if<
227
             (!is_member_pointer<_Functor>::value
228
              && !is_function<_Functor>::value
229
              && !is_function::type>::value),
230
             typename result_of<_Functor(_Args&&...)>::type
231
           >::type
232
    __invoke(_Functor& __f, _Args&&... __args)
233
    {
234
      return __f(std::forward<_Args>(__args)...);
235
    }
236
 
237
  template
238
    inline
239
    typename enable_if<
240
             (is_member_pointer<_Functor>::value
241
              && !is_function<_Functor>::value
242
              && !is_function::type>::value),
243
             typename result_of<_Functor(_Args&&...)>::type
244
           >::type
245
    __invoke(_Functor& __f, _Args&&... __args)
246
    {
247
      return std::mem_fn(__f)(std::forward<_Args>(__args)...);
248
    }
249
 
250
  // To pick up function references (that will become function pointers)
251
  template
252
    inline
253
    typename enable_if<
254
             (is_pointer<_Functor>::value
255
              && is_function::type>::value),
256
             typename result_of<_Functor(_Args&&...)>::type
257
           >::type
258
    __invoke(_Functor __f, _Args&&... __args)
259
    {
260
      return __f(std::forward<_Args>(__args)...);
261
    }
262
 
263
  /**
264
   *  Knowing which of unary_function and binary_function _Tp derives
265
   *  from, derives from the same and ensures that reference_wrapper
266
   *  will have a weak result type. See cases below.
267
   */
268
  template
269
    struct _Reference_wrapper_base_impl;
270
 
271
  // None of the nested argument types.
272
  template
273
    struct _Reference_wrapper_base_impl
274
    : _Weak_result_type<_Tp>
275
    { };
276
 
277
  // Nested argument_type only.
278
  template
279
    struct _Reference_wrapper_base_impl
280
    : _Weak_result_type<_Tp>
281
    {
282
      typedef typename _Tp::argument_type argument_type;
283
    };
284
 
285
  // Nested first_argument_type and second_argument_type only.
286
  template
287
    struct _Reference_wrapper_base_impl
288
    : _Weak_result_type<_Tp>
289
    {
290
      typedef typename _Tp::first_argument_type first_argument_type;
291
      typedef typename _Tp::second_argument_type second_argument_type;
292
    };
293
 
294
  // All the nested argument types.
295
   template
296
    struct _Reference_wrapper_base_impl
297
    : _Weak_result_type<_Tp>
298
    {
299
      typedef typename _Tp::argument_type argument_type;
300
      typedef typename _Tp::first_argument_type first_argument_type;
301
      typedef typename _Tp::second_argument_type second_argument_type;
302
    };
303
 
304
  _GLIBCXX_HAS_NESTED_TYPE(argument_type)
305
  _GLIBCXX_HAS_NESTED_TYPE(first_argument_type)
306
  _GLIBCXX_HAS_NESTED_TYPE(second_argument_type)
307
 
308
  /**
309
   *  Derives from unary_function or binary_function when it
310
   *  can. Specializations handle all of the easy cases. The primary
311
   *  template determines what to do with a class type, which may
312
   *  derive from both unary_function and binary_function.
313
  */
314
  template
315
    struct _Reference_wrapper_base
316
    : _Reference_wrapper_base_impl<
317
      __has_argument_type<_Tp>::value,
318
      __has_first_argument_type<_Tp>::value
319
      && __has_second_argument_type<_Tp>::value,
320
      _Tp>
321
    { };
322
 
323
  // - a function type (unary)
324
  template
325
    struct _Reference_wrapper_base<_Res(_T1)>
326
    : unary_function<_T1, _Res>
327
    { };
328
 
329
  template
330
    struct _Reference_wrapper_base<_Res(_T1) const>
331
    : unary_function<_T1, _Res>
332
    { };
333
 
334
  template
335
    struct _Reference_wrapper_base<_Res(_T1) volatile>
336
    : unary_function<_T1, _Res>
337
    { };
338
 
339
  template
340
    struct _Reference_wrapper_base<_Res(_T1) const volatile>
341
    : unary_function<_T1, _Res>
342
    { };
343
 
344
  // - a function type (binary)
345
  template
346
    struct _Reference_wrapper_base<_Res(_T1, _T2)>
347
    : binary_function<_T1, _T2, _Res>
348
    { };
349
 
350
  template
351
    struct _Reference_wrapper_base<_Res(_T1, _T2) const>
352
    : binary_function<_T1, _T2, _Res>
353
    { };
354
 
355
  template
356
    struct _Reference_wrapper_base<_Res(_T1, _T2) volatile>
357
    : binary_function<_T1, _T2, _Res>
358
    { };
359
 
360
  template
361
    struct _Reference_wrapper_base<_Res(_T1, _T2) const volatile>
362
    : binary_function<_T1, _T2, _Res>
363
    { };
364
 
365
  // - a function pointer type (unary)
366
  template
367
    struct _Reference_wrapper_base<_Res(*)(_T1)>
368
    : unary_function<_T1, _Res>
369
    { };
370
 
371
  // - a function pointer type (binary)
372
  template
373
    struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>
374
    : binary_function<_T1, _T2, _Res>
375
    { };
376
 
377
  // - a pointer to member function type (unary, no qualifiers)
378
  template
379
    struct _Reference_wrapper_base<_Res (_T1::*)()>
380
    : unary_function<_T1*, _Res>
381
    { };
382
 
383
  // - a pointer to member function type (binary, no qualifiers)
384
  template
385
    struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>
386
    : binary_function<_T1*, _T2, _Res>
387
    { };
388
 
389
  // - a pointer to member function type (unary, const)
390
  template
391
    struct _Reference_wrapper_base<_Res (_T1::*)() const>
392
    : unary_function
393
    { };
394
 
395
  // - a pointer to member function type (binary, const)
396
  template
397
    struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>
398
    : binary_function
399
    { };
400
 
401
  // - a pointer to member function type (unary, volatile)
402
  template
403
    struct _Reference_wrapper_base<_Res (_T1::*)() volatile>
404
    : unary_function
405
    { };
406
 
407
  // - a pointer to member function type (binary, volatile)
408
  template
409
    struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>
410
    : binary_function
411
    { };
412
 
413
  // - a pointer to member function type (unary, const volatile)
414
  template
415
    struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>
416
    : unary_function
417
    { };
418
 
419
  // - a pointer to member function type (binary, const volatile)
420
  template
421
    struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>
422
    : binary_function
423
    { };
424
 
425
  /**
426
   *  @brief Primary class template for reference_wrapper.
427
   *  @ingroup functors
428
   *  @{
429
   */
430
  template
431
    class reference_wrapper
432
    : public _Reference_wrapper_base::type>
433
    {
434
      _Tp* _M_data;
435
 
436
    public:
437
      typedef _Tp type;
438
 
439
      reference_wrapper(_Tp& __indata) noexcept
440
      : _M_data(std::__addressof(__indata))
441
      { }
442
 
443
      reference_wrapper(_Tp&&) = delete;
444
 
445
      reference_wrapper(const reference_wrapper<_Tp>& __inref) noexcept
446
      : _M_data(__inref._M_data)
447
      { }
448
 
449
      reference_wrapper&
450
      operator=(const reference_wrapper<_Tp>& __inref) noexcept
451
      {
452
        _M_data = __inref._M_data;
453
        return *this;
454
      }
455
 
456
      operator _Tp&() const noexcept
457
      { return this->get(); }
458
 
459
      _Tp&
460
      get() const noexcept
461
      { return *_M_data; }
462
 
463
      template
464
        typename result_of<_Tp&(_Args&&...)>::type
465
        operator()(_Args&&... __args) const
466
        {
467
          return __invoke(get(), std::forward<_Args>(__args)...);
468
        }
469
    };
470
 
471
 
472
  /// Denotes a reference should be taken to a variable.
473
  template
474
    inline reference_wrapper<_Tp>
475
    ref(_Tp& __t) noexcept
476
    { return reference_wrapper<_Tp>(__t); }
477
 
478
  /// Denotes a const reference should be taken to a variable.
479
  template
480
    inline reference_wrapper
481
    cref(const _Tp& __t) noexcept
482
    { return reference_wrapper(__t); }
483
 
484
  template
485
    void ref(const _Tp&&) = delete;
486
 
487
  template
488
    void cref(const _Tp&&) = delete;
489
 
490
  /// Partial specialization.
491
  template
492
    inline reference_wrapper<_Tp>
493
    ref(reference_wrapper<_Tp> __t) noexcept
494
    { return ref(__t.get()); }
495
 
496
  /// Partial specialization.
497
  template
498
    inline reference_wrapper
499
    cref(reference_wrapper<_Tp> __t) noexcept
500
    { return cref(__t.get()); }
501
 
502
  // @} group functors
503
 
504
  template
505
    using _Require = typename enable_if<__and_<_Cond...>::value>::type;
506
 
507
  template
508
    struct _Pack : integral_constant
509
    { };
510
 
511
  template
512
    struct _AllConvertible : false_type
513
    { };
514
 
515
  template
516
    struct _AllConvertible<_Pack<_From...>, _Pack<_To...>, true>
517
    : __and_...>
518
    { };
519
 
520
  template
521
    using _NotSame = __not_::type,
522
                                    typename std::decay<_Tp2>::type>>;
523
 
524
  /**
525
   * Derives from @c unary_function or @c binary_function, or perhaps
526
   * nothing, depending on the number of arguments provided. The
527
   * primary template is the basis case, which derives nothing.
528
   */
529
  template
530
    struct _Maybe_unary_or_binary_function { };
531
 
532
  /// Derives from @c unary_function, as appropriate.
533
  template
534
    struct _Maybe_unary_or_binary_function<_Res, _T1>
535
    : std::unary_function<_T1, _Res> { };
536
 
537
  /// Derives from @c binary_function, as appropriate.
538
  template
539
    struct _Maybe_unary_or_binary_function<_Res, _T1, _T2>
540
    : std::binary_function<_T1, _T2, _Res> { };
541
 
542
  /// Implementation of @c mem_fn for member function pointers.
543
  template
544
    class _Mem_fn<_Res (_Class::*)(_ArgTypes...)>
545
    : public _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>
546
    {
547
      typedef _Res (_Class::*_Functor)(_ArgTypes...);
548
 
549
      template
550
        _Res
551
        _M_call(_Tp&& __object, const volatile _Class *,
552
                _Args&&... __args) const
553
        {
554
          return (std::forward<_Tp>(__object).*__pmf)
555
            (std::forward<_Args>(__args)...);
556
        }
557
 
558
      template
559
        _Res
560
        _M_call(_Tp&& __ptr, const volatile void *, _Args&&... __args) const
561
        { return ((*__ptr).*__pmf)(std::forward<_Args>(__args)...); }
562
 
563
      // Require each _Args to be convertible to corresponding _ArgTypes
564
      template
565
        using _RequireValidArgs
566
          = _Require<_AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
567
 
568
      // Require each _Args to be convertible to corresponding _ArgTypes
569
      // and require _Tp is not _Class, _Class& or _Class*
570
      template
571
        using _RequireValidArgs2
572
          = _Require<_NotSame<_Class, _Tp>, _NotSame<_Class*, _Tp>,
573
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
574
 
575
      // Require each _Args to be convertible to corresponding _ArgTypes
576
      // and require _Tp is _Class or derived from _Class
577
      template
578
        using _RequireValidArgs3
579
          = _Require,
580
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
581
 
582
    public:
583
      typedef _Res result_type;
584
 
585
      explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
586
 
587
      // Handle objects
588
      template>
589
        _Res
590
        operator()(_Class& __object, _Args&&... __args) const
591
        { return (__object.*__pmf)(std::forward<_Args>(__args)...); }
592
 
593
      template>
594
        _Res
595
        operator()(_Class&& __object, _Args&&... __args) const
596
        {
597
          return (std::move(__object).*__pmf)(std::forward<_Args>(__args)...);
598
        }
599
 
600
      // Handle pointers
601
      template>
602
        _Res
603
        operator()(_Class* __object, _Args&&... __args) const
604
        { return (__object->*__pmf)(std::forward<_Args>(__args)...); }
605
 
606
      // Handle smart pointers, references and pointers to derived
607
      template
608
               typename _Req = _RequireValidArgs2<_Tp, _Args...>>
609
        _Res
610
        operator()(_Tp&& __object, _Args&&... __args) const
611
        {
612
          return _M_call(std::forward<_Tp>(__object), &__object,
613
              std::forward<_Args>(__args)...);
614
        }
615
 
616
      template
617
               typename _Req = _RequireValidArgs3<_Tp, _Args...>>
618
        _Res
619
        operator()(reference_wrapper<_Tp> __ref, _Args&&... __args) const
620
        { return operator()(__ref.get(), std::forward<_Args>(__args)...); }
621
 
622
    private:
623
      _Functor __pmf;
624
    };
625
 
626
  /// Implementation of @c mem_fn for const member function pointers.
627
  template
628
    class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const>
629
    : public _Maybe_unary_or_binary_function<_Res, const _Class*,
630
                                             _ArgTypes...>
631
    {
632
      typedef _Res (_Class::*_Functor)(_ArgTypes...) const;
633
 
634
      template
635
        _Res
636
        _M_call(_Tp&& __object, const volatile _Class *,
637
                _Args&&... __args) const
638
        {
639
          return (std::forward<_Tp>(__object).*__pmf)
640
            (std::forward<_Args>(__args)...);
641
        }
642
 
643
      template
644
        _Res
645
        _M_call(_Tp&& __ptr, const volatile void *, _Args&&... __args) const
646
        { return ((*__ptr).*__pmf)(std::forward<_Args>(__args)...); }
647
 
648
      template
649
        using _RequireValidArgs
650
          = _Require<_AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
651
 
652
      template
653
        using _RequireValidArgs2
654
          = _Require<_NotSame<_Class, _Tp>, _NotSame<_Class*, _Tp>,
655
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
656
 
657
      template
658
        using _RequireValidArgs3
659
          = _Require,
660
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
661
 
662
    public:
663
      typedef _Res result_type;
664
 
665
      explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
666
 
667
      // Handle objects
668
      template>
669
        _Res
670
        operator()(const _Class& __object, _Args&&... __args) const
671
        { return (__object.*__pmf)(std::forward<_Args>(__args)...); }
672
 
673
      template>
674
        _Res
675
        operator()(const _Class&& __object, _Args&&... __args) const
676
        {
677
          return (std::move(__object).*__pmf)(std::forward<_Args>(__args)...);
678
        }
679
 
680
      // Handle pointers
681
      template>
682
        _Res
683
        operator()(const _Class* __object, _Args&&... __args) const
684
        { return (__object->*__pmf)(std::forward<_Args>(__args)...); }
685
 
686
      // Handle smart pointers, references and pointers to derived
687
      template
688
               typename _Req = _RequireValidArgs2<_Tp, _Args...>>
689
        _Res operator()(_Tp&& __object, _Args&&... __args) const
690
        {
691
          return _M_call(std::forward<_Tp>(__object), &__object,
692
              std::forward<_Args>(__args)...);
693
        }
694
 
695
      template
696
               typename _Req = _RequireValidArgs3<_Tp, _Args...>>
697
        _Res
698
        operator()(reference_wrapper<_Tp> __ref, _Args&&... __args) const
699
        { return operator()(__ref.get(), std::forward<_Args>(__args)...); }
700
 
701
    private:
702
      _Functor __pmf;
703
    };
704
 
705
  /// Implementation of @c mem_fn for volatile member function pointers.
706
  template
707
    class _Mem_fn<_Res (_Class::*)(_ArgTypes...) volatile>
708
    : public _Maybe_unary_or_binary_function<_Res, volatile _Class*,
709
                                             _ArgTypes...>
710
    {
711
      typedef _Res (_Class::*_Functor)(_ArgTypes...) volatile;
712
 
713
      template
714
        _Res
715
        _M_call(_Tp&& __object, const volatile _Class *,
716
                _Args&&... __args) const
717
        {
718
          return (std::forward<_Tp>(__object).*__pmf)
719
            (std::forward<_Args>(__args)...);
720
        }
721
 
722
      template
723
        _Res
724
        _M_call(_Tp&& __ptr, const volatile void *, _Args&&... __args) const
725
        { return ((*__ptr).*__pmf)(std::forward<_Args>(__args)...); }
726
 
727
      template
728
        using _RequireValidArgs
729
          = _Require<_AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
730
 
731
      template
732
        using _RequireValidArgs2
733
          = _Require<_NotSame<_Class, _Tp>, _NotSame<_Class*, _Tp>,
734
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
735
 
736
      template
737
        using _RequireValidArgs3
738
          = _Require,
739
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
740
 
741
    public:
742
      typedef _Res result_type;
743
 
744
      explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
745
 
746
      // Handle objects
747
      template>
748
        _Res
749
        operator()(volatile _Class& __object, _Args&&... __args) const
750
        { return (__object.*__pmf)(std::forward<_Args>(__args)...); }
751
 
752
      template>
753
        _Res
754
        operator()(volatile _Class&& __object, _Args&&... __args) const
755
        {
756
          return (std::move(__object).*__pmf)(std::forward<_Args>(__args)...);
757
        }
758
 
759
      // Handle pointers
760
      template>
761
        _Res
762
        operator()(volatile _Class* __object, _Args&&... __args) const
763
        { return (__object->*__pmf)(std::forward<_Args>(__args)...); }
764
 
765
      // Handle smart pointers, references and pointers to derived
766
      template
767
               typename _Req = _RequireValidArgs2<_Tp, _Args...>>
768
        _Res
769
        operator()(_Tp&& __object, _Args&&... __args) const
770
        {
771
          return _M_call(std::forward<_Tp>(__object), &__object,
772
              std::forward<_Args>(__args)...);
773
        }
774
 
775
      template
776
               typename _Req = _RequireValidArgs3<_Tp, _Args...>>
777
        _Res
778
        operator()(reference_wrapper<_Tp> __ref, _Args&&... __args) const
779
        { return operator()(__ref.get(), std::forward<_Args>(__args)...); }
780
 
781
    private:
782
      _Functor __pmf;
783
    };
784
 
785
  /// Implementation of @c mem_fn for const volatile member function pointers.
786
  template
787
    class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const volatile>
788
    : public _Maybe_unary_or_binary_function<_Res, const volatile _Class*,
789
                                             _ArgTypes...>
790
    {
791
      typedef _Res (_Class::*_Functor)(_ArgTypes...) const volatile;
792
 
793
      template
794
        _Res
795
        _M_call(_Tp&& __object, const volatile _Class *,
796
                _Args&&... __args) const
797
        {
798
          return (std::forward<_Tp>(__object).*__pmf)
799
            (std::forward<_Args>(__args)...);
800
        }
801
 
802
      template
803
        _Res
804
        _M_call(_Tp&& __ptr, const volatile void *, _Args&&... __args) const
805
        { return ((*__ptr).*__pmf)(std::forward<_Args>(__args)...); }
806
 
807
      template
808
        using _RequireValidArgs
809
          = _Require<_AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
810
 
811
      template
812
        using _RequireValidArgs2
813
          = _Require<_NotSame<_Class, _Tp>, _NotSame<_Class*, _Tp>,
814
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
815
 
816
      template
817
        using _RequireValidArgs3
818
          = _Require,
819
                     _AllConvertible<_Pack<_Args...>, _Pack<_ArgTypes...>>>;
820
 
821
    public:
822
      typedef _Res result_type;
823
 
824
      explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
825
 
826
      // Handle objects
827
      template>
828
        _Res
829
        operator()(const volatile _Class& __object, _Args&&... __args) const
830
        { return (__object.*__pmf)(std::forward<_Args>(__args)...); }
831
 
832
      template>
833
        _Res
834
        operator()(const volatile _Class&& __object, _Args&&... __args) const
835
        {
836
          return (std::move(__object).*__pmf)(std::forward<_Args>(__args)...);
837
        }
838
 
839
      // Handle pointers
840
      template>
841
        _Res
842
        operator()(const volatile _Class* __object, _Args&&... __args) const
843
        { return (__object->*__pmf)(std::forward<_Args>(__args)...); }
844
 
845
      // Handle smart pointers, references and pointers to derived
846
      template
847
               typename _Req = _RequireValidArgs2<_Tp, _Args...>>
848
        _Res operator()(_Tp&& __object, _Args&&... __args) const
849
        {
850
          return _M_call(std::forward<_Tp>(__object), &__object,
851
              std::forward<_Args>(__args)...);
852
        }
853
 
854
      template
855
               typename _Req = _RequireValidArgs3<_Tp, _Args...>>
856
        _Res
857
        operator()(reference_wrapper<_Tp> __ref, _Args&&... __args) const
858
        { return operator()(__ref.get(), std::forward<_Args>(__args)...); }
859
 
860
    private:
861
      _Functor __pmf;
862
    };
863
 
864
 
865
  template
866
    struct _Mem_fn_const_or_non
867
    {
868
      typedef const _Tp& type;
869
    };
870
 
871
  template
872
    struct _Mem_fn_const_or_non<_Tp, false>
873
    {
874
      typedef _Tp& type;
875
    };
876
 
877
  template
878
    class _Mem_fn<_Res _Class::*>
879
    {
880
      using __pm_type = _Res _Class::*;
881
 
882
      // This bit of genius is due to Peter Dimov, improved slightly by
883
      // Douglas Gregor.
884
      // Made less elegant to support perfect forwarding and noexcept.
885
      template
886
        auto
887
        _M_call(_Tp&& __object, const _Class *) const noexcept
888
        -> decltype(std::forward<_Tp>(__object).*std::declval<__pm_type&>())
889
        { return std::forward<_Tp>(__object).*__pm; }
890
 
891
      template
892
        auto
893
        _M_call(_Tp&& __object, _Up * const *) const noexcept
894
        -> decltype((*std::forward<_Tp>(__object)).*std::declval<__pm_type&>())
895
        { return (*std::forward<_Tp>(__object)).*__pm; }
896
 
897
      template
898
        auto
899
        _M_call(_Tp&& __ptr, const volatile void*) const
900
        noexcept(noexcept((*__ptr).*std::declval<__pm_type&>()))
901
        -> decltype((*__ptr).*std::declval<__pm_type&>())
902
        { return (*__ptr).*__pm; }
903
 
904
    public:
905
      explicit
906
      _Mem_fn(_Res _Class::*__pm) noexcept : __pm(__pm) { }
907
 
908
      // Handle objects
909
      _Res&
910
      operator()(_Class& __object) const noexcept
911
      { return __object.*__pm; }
912
 
913
      const _Res&
914
      operator()(const _Class& __object) const noexcept
915
      { return __object.*__pm; }
916
 
917
      _Res&&
918
      operator()(_Class&& __object) const noexcept
919
      { return std::forward<_Class>(__object).*__pm; }
920
 
921
      const _Res&&
922
      operator()(const _Class&& __object) const noexcept
923
      { return std::forward(__object).*__pm; }
924
 
925
      // Handle pointers
926
      _Res&
927
      operator()(_Class* __object) const noexcept
928
      { return __object->*__pm; }
929
 
930
      const _Res&
931
      operator()(const _Class* __object) const noexcept
932
      { return __object->*__pm; }
933
 
934
      // Handle smart pointers and derived
935
      template>>
936
        auto
937
        operator()(_Tp&& __unknown) const
938
        noexcept(noexcept(std::declval<_Mem_fn*>()->_M_call
939
                          (std::forward<_Tp>(__unknown), &__unknown)))
940
        -> decltype(this->_M_call(std::forward<_Tp>(__unknown), &__unknown))
941
        { return _M_call(std::forward<_Tp>(__unknown), &__unknown); }
942
 
943
      template>>
944
        auto
945
        operator()(reference_wrapper<_Tp> __ref) const
946
        noexcept(noexcept(std::declval<_Mem_fn&>()(__ref.get())))
947
        -> decltype((*this)(__ref.get()))
948
        { return (*this)(__ref.get()); }
949
 
950
    private:
951
      _Res _Class::*__pm;
952
    };
953
 
954
  // _GLIBCXX_RESOLVE_LIB_DEFECTS
955
  // 2048.  Unnecessary mem_fn overloads
956
  /**
957
   *  @brief Returns a function object that forwards to the member
958
   *  pointer @a pm.
959
   *  @ingroup functors
960
   */
961
  template
962
    inline _Mem_fn<_Tp _Class::*>
963
    mem_fn(_Tp _Class::* __pm) noexcept
964
    {
965
      return _Mem_fn<_Tp _Class::*>(__pm);
966
    }
967
 
968
  /**
969
   *  @brief Determines if the given type _Tp is a function object
970
   *  should be treated as a subexpression when evaluating calls to
971
   *  function objects returned by bind(). [TR1 3.6.1]
972
   *  @ingroup binders
973
   */
974
  template
975
    struct is_bind_expression
976
    : public false_type { };
977
 
978
  /**
979
   *  @brief Determines if the given type _Tp is a placeholder in a
980
   *  bind() expression and, if so, which placeholder it is. [TR1 3.6.2]
981
   *  @ingroup binders
982
   */
983
  template
984
    struct is_placeholder
985
    : public integral_constant
986
    { };
987
 
988
  /** @brief The type of placeholder objects defined by libstdc++.
989
   *  @ingroup binders
990
   */
991
  template struct _Placeholder { };
992
 
993
  _GLIBCXX_END_NAMESPACE_VERSION
994
 
995
  /** @namespace std::placeholders
996
   *  @brief ISO C++11 entities sub-namespace for functional.
997
   *  @ingroup binders
998
   */
999
  namespace placeholders
1000
  {
1001
  _GLIBCXX_BEGIN_NAMESPACE_VERSION
1002
  /* Define a large number of placeholders. There is no way to
1003
   * simplify this with variadic templates, because we're introducing
1004
   * unique names for each.
1005
   */
1006
    extern const _Placeholder<1> _1;
1007
    extern const _Placeholder<2> _2;
1008
    extern const _Placeholder<3> _3;
1009
    extern const _Placeholder<4> _4;
1010
    extern const _Placeholder<5> _5;
1011
    extern const _Placeholder<6> _6;
1012
    extern const _Placeholder<7> _7;
1013
    extern const _Placeholder<8> _8;
1014
    extern const _Placeholder<9> _9;
1015
    extern const _Placeholder<10> _10;
1016
    extern const _Placeholder<11> _11;
1017
    extern const _Placeholder<12> _12;
1018
    extern const _Placeholder<13> _13;
1019
    extern const _Placeholder<14> _14;
1020
    extern const _Placeholder<15> _15;
1021
    extern const _Placeholder<16> _16;
1022
    extern const _Placeholder<17> _17;
1023
    extern const _Placeholder<18> _18;
1024
    extern const _Placeholder<19> _19;
1025
    extern const _Placeholder<20> _20;
1026
    extern const _Placeholder<21> _21;
1027
    extern const _Placeholder<22> _22;
1028
    extern const _Placeholder<23> _23;
1029
    extern const _Placeholder<24> _24;
1030
    extern const _Placeholder<25> _25;
1031
    extern const _Placeholder<26> _26;
1032
    extern const _Placeholder<27> _27;
1033
    extern const _Placeholder<28> _28;
1034
    extern const _Placeholder<29> _29;
1035
  _GLIBCXX_END_NAMESPACE_VERSION
1036
  }
1037
 
1038
  _GLIBCXX_BEGIN_NAMESPACE_VERSION
1039
 
1040
  /**
1041
   *  Partial specialization of is_placeholder that provides the placeholder
1042
   *  number for the placeholder objects defined by libstdc++.
1043
   *  @ingroup binders
1044
   */
1045
  template
1046
    struct is_placeholder<_Placeholder<_Num> >
1047
    : public integral_constant
1048
    { };
1049
 
1050
  template
1051
    struct is_placeholder >
1052
    : public integral_constant
1053
    { };
1054
 
1055
  /**
1056
   * Used by _Safe_tuple_element to indicate that there is no tuple
1057
   * element at this position.
1058
   */
1059
  struct _No_tuple_element;
1060
 
1061
  /**
1062
   * Implementation helper for _Safe_tuple_element. This primary
1063
   * template handles the case where it is safe to use @c
1064
   * tuple_element.
1065
   */
1066
  template
1067
    struct _Safe_tuple_element_impl
1068
    : tuple_element<__i, _Tuple> { };
1069
 
1070
  /**
1071
   * Implementation helper for _Safe_tuple_element. This partial
1072
   * specialization handles the case where it is not safe to use @c
1073
   * tuple_element. We just return @c _No_tuple_element.
1074
   */
1075
  template
1076
    struct _Safe_tuple_element_impl<__i, _Tuple, false>
1077
    {
1078
      typedef _No_tuple_element type;
1079
    };
1080
 
1081
  /**
1082
   * Like tuple_element, but returns @c _No_tuple_element when
1083
   * tuple_element would return an error.
1084
   */
1085
 template
1086
   struct _Safe_tuple_element
1087
   : _Safe_tuple_element_impl<__i, _Tuple,
1088
                              (__i < tuple_size<_Tuple>::value)>
1089
   { };
1090
 
1091
  /**
1092
   *  Maps an argument to bind() into an actual argument to the bound
1093
   *  function object [TR1 3.6.3/5]. Only the first parameter should
1094
   *  be specified: the rest are used to determine among the various
1095
   *  implementations. Note that, although this class is a function
1096
   *  object, it isn't entirely normal because it takes only two
1097
   *  parameters regardless of the number of parameters passed to the
1098
   *  bind expression. The first parameter is the bound argument and
1099
   *  the second parameter is a tuple containing references to the
1100
   *  rest of the arguments.
1101
   */
1102
  template
1103
           bool _IsBindExp = is_bind_expression<_Arg>::value,
1104
           bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
1105
    class _Mu;
1106
 
1107
  /**
1108
   *  If the argument is reference_wrapper<_Tp>, returns the
1109
   *  underlying reference. [TR1 3.6.3/5 bullet 1]
1110
   */
1111
  template
1112
    class _Mu, false, false>
1113
    {
1114
    public:
1115
      typedef _Tp& result_type;
1116
 
1117
      /* Note: This won't actually work for const volatile
1118
       * reference_wrappers, because reference_wrapper::get() is const
1119
       * but not volatile-qualified. This might be a defect in the TR.
1120
       */
1121
      template
1122
        result_type
1123
        operator()(_CVRef& __arg, _Tuple&) const volatile
1124
        { return __arg.get(); }
1125
    };
1126
 
1127
  /**
1128
   *  If the argument is a bind expression, we invoke the underlying
1129
   *  function object with the same cv-qualifiers as we are given and
1130
   *  pass along all of our arguments (unwrapped). [TR1 3.6.3/5 bullet 2]
1131
   */
1132
  template
1133
    class _Mu<_Arg, true, false>
1134
    {
1135
    public:
1136
      template
1137
        auto
1138
        operator()(_CVArg& __arg,
1139
                   tuple<_Args...>& __tuple) const volatile
1140
        -> decltype(__arg(declval<_Args>()...))
1141
        {
1142
          // Construct an index tuple and forward to __call
1143
          typedef typename _Build_index_tuple::__type
1144
            _Indexes;
1145
          return this->__call(__arg, __tuple, _Indexes());
1146
        }
1147
 
1148
    private:
1149
      // Invokes the underlying function object __arg by unpacking all
1150
      // of the arguments in the tuple.
1151
      template
1152
        auto
1153
        __call(_CVArg& __arg, tuple<_Args...>& __tuple,
1154
               const _Index_tuple<_Indexes...>&) const volatile
1155
        -> decltype(__arg(declval<_Args>()...))
1156
        {
1157
          return __arg(std::forward<_Args>(get<_Indexes>(__tuple))...);
1158
        }
1159
    };
1160
 
1161
  /**
1162
   *  If the argument is a placeholder for the Nth argument, returns
1163
   *  a reference to the Nth argument to the bind function object.
1164
   *  [TR1 3.6.3/5 bullet 3]
1165
   */
1166
  template
1167
    class _Mu<_Arg, false, true>
1168
    {
1169
    public:
1170
      template class result;
1171
 
1172
      template
1173
        class result<_CVMu(_CVArg, _Tuple)>
1174
        {
1175
          // Add a reference, if it hasn't already been done for us.
1176
          // This allows us to be a little bit sloppy in constructing
1177
          // the tuple that we pass to result_of<...>.
1178
          typedef typename _Safe_tuple_element<(is_placeholder<_Arg>::value
1179
                                                - 1), _Tuple>::type
1180
            __base_type;
1181
 
1182
        public:
1183
          typedef typename add_rvalue_reference<__base_type>::type type;
1184
        };
1185
 
1186
      template
1187
        typename result<_Mu(_Arg, _Tuple)>::type
1188
        operator()(const volatile _Arg&, _Tuple& __tuple) const volatile
1189
        {
1190
          return std::forward::type>(
1191
              ::std::get<(is_placeholder<_Arg>::value - 1)>(__tuple));
1192
        }
1193
    };
1194
 
1195
  /**
1196
   *  If the argument is just a value, returns a reference to that
1197
   *  value. The cv-qualifiers on the reference are the same as the
1198
   *  cv-qualifiers on the _Mu object. [TR1 3.6.3/5 bullet 4]
1199
   */
1200
  template
1201
    class _Mu<_Arg, false, false>
1202
    {
1203
    public:
1204
      template struct result;
1205
 
1206
      template
1207
        struct result<_CVMu(_CVArg, _Tuple)>
1208
        {
1209
          typedef typename add_lvalue_reference<_CVArg>::type type;
1210
        };
1211
 
1212
      // Pick up the cv-qualifiers of the argument
1213
      template
1214
        _CVArg&&
1215
        operator()(_CVArg&& __arg, _Tuple&) const volatile
1216
        { return std::forward<_CVArg>(__arg); }
1217
    };
1218
 
1219
  /**
1220
   *  Maps member pointers into instances of _Mem_fn but leaves all
1221
   *  other function objects untouched. Used by tr1::bind(). The
1222
   *  primary template handles the non--member-pointer case.
1223
   */
1224
  template
1225
    struct _Maybe_wrap_member_pointer
1226
    {
1227
      typedef _Tp type;
1228
 
1229
      static const _Tp&
1230
      __do_wrap(const _Tp& __x)
1231
      { return __x; }
1232
 
1233
      static _Tp&&
1234
      __do_wrap(_Tp&& __x)
1235
      { return static_cast<_Tp&&>(__x); }
1236
    };
1237
 
1238
  /**
1239
   *  Maps member pointers into instances of _Mem_fn but leaves all
1240
   *  other function objects untouched. Used by tr1::bind(). This
1241
   *  partial specialization handles the member pointer case.
1242
   */
1243
  template
1244
    struct _Maybe_wrap_member_pointer<_Tp _Class::*>
1245
    {
1246
      typedef _Mem_fn<_Tp _Class::*> type;
1247
 
1248
      static type
1249
      __do_wrap(_Tp _Class::* __pm)
1250
      { return type(__pm); }
1251
    };
1252
 
1253
  // Specialization needed to prevent "forming reference to void" errors when
1254
  // bind() is called, because argument deduction instantiates
1255
  // _Maybe_wrap_member_pointer outside the immediate context where
1256
  // SFINAE applies.
1257
  template<>
1258
    struct _Maybe_wrap_member_pointer
1259
    {
1260
      typedef void type;
1261
    };
1262
 
1263
  // std::get for volatile-qualified tuples
1264
  template
1265
    inline auto
1266
    __volget(volatile tuple<_Tp...>& __tuple)
1267
    -> typename tuple_element<_Ind, tuple<_Tp...>>::type volatile&
1268
    { return std::get<_Ind>(const_cast&>(__tuple)); }
1269
 
1270
  // std::get for const-volatile-qualified tuples
1271
  template
1272
    inline auto
1273
    __volget(const volatile tuple<_Tp...>& __tuple)
1274
    -> typename tuple_element<_Ind, tuple<_Tp...>>::type const volatile&
1275
    { return std::get<_Ind>(const_cast&>(__tuple)); }
1276
 
1277
  /// Type of the function object returned from bind().
1278
  template
1279
    struct _Bind;
1280
 
1281
   template
1282
    class _Bind<_Functor(_Bound_args...)>
1283
    : public _Weak_result_type<_Functor>
1284
    {
1285
      typedef _Bind __self_type;
1286
      typedef typename _Build_index_tuple::__type
1287
        _Bound_indexes;
1288
 
1289
      _Functor _M_f;
1290
      tuple<_Bound_args...> _M_bound_args;
1291
 
1292
      // Call unqualified
1293
      template
1294
        _Result
1295
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>)
1296
        {
1297
          return _M_f(_Mu<_Bound_args>()
1298
                      (get<_Indexes>(_M_bound_args), __args)...);
1299
        }
1300
 
1301
      // Call as const
1302
      template
1303
        _Result
1304
        __call_c(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) const
1305
        {
1306
          return _M_f(_Mu<_Bound_args>()
1307
                      (get<_Indexes>(_M_bound_args), __args)...);
1308
        }
1309
 
1310
      // Call as volatile
1311
      template
1312
        _Result
1313
        __call_v(tuple<_Args...>&& __args,
1314
                 _Index_tuple<_Indexes...>) volatile
1315
        {
1316
          return _M_f(_Mu<_Bound_args>()
1317
                      (__volget<_Indexes>(_M_bound_args), __args)...);
1318
        }
1319
 
1320
      // Call as const volatile
1321
      template
1322
        _Result
1323
        __call_c_v(tuple<_Args...>&& __args,
1324
                   _Index_tuple<_Indexes...>) const volatile
1325
        {
1326
          return _M_f(_Mu<_Bound_args>()
1327
                      (__volget<_Indexes>(_M_bound_args), __args)...);
1328
        }
1329
 
1330
     public:
1331
      template
1332
        explicit _Bind(const _Functor& __f, _Args&&... __args)
1333
        : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
1334
        { }
1335
 
1336
      template
1337
        explicit _Bind(_Functor&& __f, _Args&&... __args)
1338
        : _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
1339
        { }
1340
 
1341
      _Bind(const _Bind&) = default;
1342
 
1343
      _Bind(_Bind&& __b)
1344
      : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
1345
      { }
1346
 
1347
      // Call unqualified
1348
      template
1349
        = decltype( std::declval<_Functor>()(
1350
              _Mu<_Bound_args>()( std::declval<_Bound_args&>(),
1351
                                  std::declval&>() )... ) )>
1352
        _Result
1353
        operator()(_Args&&... __args)
1354
        {
1355
          return this->__call<_Result>(
1356
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1357
              _Bound_indexes());
1358
        }
1359
 
1360
      // Call as const
1361
      template
1362
        = decltype( std::declval= 0),
1363
                       typename add_const<_Functor>::type>::type>()(
1364
              _Mu<_Bound_args>()( std::declval(),
1365
                                  std::declval&>() )... ) )>
1366
        _Result
1367
        operator()(_Args&&... __args) const
1368
        {
1369
          return this->__call_c<_Result>(
1370
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1371
              _Bound_indexes());
1372
        }
1373
 
1374
      // Call as volatile
1375
      template
1376
        = decltype( std::declval= 0),
1377
                       typename add_volatile<_Functor>::type>::type>()(
1378
              _Mu<_Bound_args>()( std::declval(),
1379
                                  std::declval&>() )... ) )>
1380
        _Result
1381
        operator()(_Args&&... __args) volatile
1382
        {
1383
          return this->__call_v<_Result>(
1384
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1385
              _Bound_indexes());
1386
        }
1387
 
1388
      // Call as const volatile
1389
      template
1390
        = decltype( std::declval= 0),
1391
                       typename add_cv<_Functor>::type>::type>()(
1392
              _Mu<_Bound_args>()( std::declval(),
1393
                                  std::declval&>() )... ) )>
1394
        _Result
1395
        operator()(_Args&&... __args) const volatile
1396
        {
1397
          return this->__call_c_v<_Result>(
1398
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1399
              _Bound_indexes());
1400
        }
1401
    };
1402
 
1403
  /// Type of the function object returned from bind().
1404
  template
1405
    struct _Bind_result;
1406
 
1407
  template
1408
    class _Bind_result<_Result, _Functor(_Bound_args...)>
1409
    {
1410
      typedef _Bind_result __self_type;
1411
      typedef typename _Build_index_tuple::__type
1412
        _Bound_indexes;
1413
 
1414
      _Functor _M_f;
1415
      tuple<_Bound_args...> _M_bound_args;
1416
 
1417
      // sfinae types
1418
      template
1419
        struct __enable_if_void : enable_if::value, int> { };
1420
      template
1421
        struct __disable_if_void : enable_if::value, int> { };
1422
 
1423
      // Call unqualified
1424
      template
1425
        _Result
1426
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1427
            typename __disable_if_void<_Res>::type = 0)
1428
        {
1429
          return _M_f(_Mu<_Bound_args>()
1430
                      (get<_Indexes>(_M_bound_args), __args)...);
1431
        }
1432
 
1433
      // Call unqualified, return void
1434
      template
1435
        void
1436
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1437
            typename __enable_if_void<_Res>::type = 0)
1438
        {
1439
          _M_f(_Mu<_Bound_args>()
1440
               (get<_Indexes>(_M_bound_args), __args)...);
1441
        }
1442
 
1443
      // Call as const
1444
      template
1445
        _Result
1446
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1447
            typename __disable_if_void<_Res>::type = 0) const
1448
        {
1449
          return _M_f(_Mu<_Bound_args>()
1450
                      (get<_Indexes>(_M_bound_args), __args)...);
1451
        }
1452
 
1453
      // Call as const, return void
1454
      template
1455
        void
1456
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1457
            typename __enable_if_void<_Res>::type = 0) const
1458
        {
1459
          _M_f(_Mu<_Bound_args>()
1460
               (get<_Indexes>(_M_bound_args),  __args)...);
1461
        }
1462
 
1463
      // Call as volatile
1464
      template
1465
        _Result
1466
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1467
            typename __disable_if_void<_Res>::type = 0) volatile
1468
        {
1469
          return _M_f(_Mu<_Bound_args>()
1470
                      (__volget<_Indexes>(_M_bound_args), __args)...);
1471
        }
1472
 
1473
      // Call as volatile, return void
1474
      template
1475
        void
1476
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1477
            typename __enable_if_void<_Res>::type = 0) volatile
1478
        {
1479
          _M_f(_Mu<_Bound_args>()
1480
               (__volget<_Indexes>(_M_bound_args), __args)...);
1481
        }
1482
 
1483
      // Call as const volatile
1484
      template
1485
        _Result
1486
        __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1487
            typename __disable_if_void<_Res>::type = 0) const volatile
1488
        {
1489
          return _M_f(_Mu<_Bound_args>()
1490
                      (__volget<_Indexes>(_M_bound_args), __args)...);
1491
        }
1492
 
1493
      // Call as const volatile, return void
1494
      template
1495
        void
1496
        __call(tuple<_Args...>&& __args,
1497
               _Index_tuple<_Indexes...>,
1498
            typename __enable_if_void<_Res>::type = 0) const volatile
1499
        {
1500
          _M_f(_Mu<_Bound_args>()
1501
               (__volget<_Indexes>(_M_bound_args), __args)...);
1502
        }
1503
 
1504
    public:
1505
      typedef _Result result_type;
1506
 
1507
      template
1508
        explicit _Bind_result(const _Functor& __f, _Args&&... __args)
1509
        : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
1510
        { }
1511
 
1512
      template
1513
        explicit _Bind_result(_Functor&& __f, _Args&&... __args)
1514
        : _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
1515
        { }
1516
 
1517
      _Bind_result(const _Bind_result&) = default;
1518
 
1519
      _Bind_result(_Bind_result&& __b)
1520
      : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
1521
      { }
1522
 
1523
      // Call unqualified
1524
      template
1525
        result_type
1526
        operator()(_Args&&... __args)
1527
        {
1528
          return this->__call<_Result>(
1529
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1530
              _Bound_indexes());
1531
        }
1532
 
1533
      // Call as const
1534
      template
1535
        result_type
1536
        operator()(_Args&&... __args) const
1537
        {
1538
          return this->__call<_Result>(
1539
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1540
              _Bound_indexes());
1541
        }
1542
 
1543
      // Call as volatile
1544
      template
1545
        result_type
1546
        operator()(_Args&&... __args) volatile
1547
        {
1548
          return this->__call<_Result>(
1549
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1550
              _Bound_indexes());
1551
        }
1552
 
1553
      // Call as const volatile
1554
      template
1555
        result_type
1556
        operator()(_Args&&... __args) const volatile
1557
        {
1558
          return this->__call<_Result>(
1559
              std::forward_as_tuple(std::forward<_Args>(__args)...),
1560
              _Bound_indexes());
1561
        }
1562
    };
1563
 
1564
  /**
1565
   *  @brief Class template _Bind is always a bind expression.
1566
   *  @ingroup binders
1567
   */
1568
  template
1569
    struct is_bind_expression<_Bind<_Signature> >
1570
    : public true_type { };
1571
 
1572
  /**
1573
   *  @brief Class template _Bind is always a bind expression.
1574
   *  @ingroup binders
1575
   */
1576
  template
1577
    struct is_bind_expression >
1578
    : public true_type { };
1579
 
1580
  /**
1581
   *  @brief Class template _Bind is always a bind expression.
1582
   *  @ingroup binders
1583
   */
1584
  template
1585
    struct is_bind_expression >
1586
    : public true_type { };
1587
 
1588
  /**
1589
   *  @brief Class template _Bind is always a bind expression.
1590
   *  @ingroup binders
1591
   */
1592
  template
1593
    struct is_bind_expression>
1594
    : public true_type { };
1595
 
1596
  /**
1597
   *  @brief Class template _Bind_result is always a bind expression.
1598
   *  @ingroup binders
1599
   */
1600
  template
1601
    struct is_bind_expression<_Bind_result<_Result, _Signature>>
1602
    : public true_type { };
1603
 
1604
  /**
1605
   *  @brief Class template _Bind_result is always a bind expression.
1606
   *  @ingroup binders
1607
   */
1608
  template
1609
    struct is_bind_expression>
1610
    : public true_type { };
1611
 
1612
  /**
1613
   *  @brief Class template _Bind_result is always a bind expression.
1614
   *  @ingroup binders
1615
   */
1616
  template
1617
    struct is_bind_expression>
1618
    : public true_type { };
1619
 
1620
  /**
1621
   *  @brief Class template _Bind_result is always a bind expression.
1622
   *  @ingroup binders
1623
   */
1624
  template
1625
    struct is_bind_expression>
1626
    : public true_type { };
1627
 
1628
  // Trait type used to remove std::bind() from overload set via SFINAE
1629
  // when first argument has integer type, so that std::bind() will
1630
  // not be a better match than ::bind() from the BSD Sockets API.
1631
  template::type>
1632
    using __is_socketlike = __or_, is_enum<_Tp2>>;
1633
 
1634
  template
1635
    struct _Bind_helper
1636
    {
1637
      typedef _Maybe_wrap_member_pointer::type>
1638
        __maybe_type;
1639
      typedef typename __maybe_type::type __func_type;
1640
      typedef _Bind<__func_type(typename decay<_BoundArgs>::type...)> type;
1641
    };
1642
 
1643
  // Partial specialization for is_socketlike == true, does not define
1644
  // nested type so std::bind() will not participate in overload resolution
1645
  // when the first argument might be a socket file descriptor.
1646
  template
1647
    struct _Bind_helper
1648
    { };
1649
 
1650
  /**
1651
   *  @brief Function template for std::bind.
1652
   *  @ingroup binders
1653
   */
1654
  template
1655
    inline typename
1656
    _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
1657
    bind(_Func&& __f, _BoundArgs&&... __args)
1658
    {
1659
      typedef _Bind_helper __helper_type;
1660
      typedef typename __helper_type::__maybe_type __maybe_type;
1661
      typedef typename __helper_type::type __result_type;
1662
      return __result_type(__maybe_type::__do_wrap(std::forward<_Func>(__f)),
1663
                           std::forward<_BoundArgs>(__args)...);
1664
    }
1665
 
1666
  template
1667
    struct _Bindres_helper
1668
    {
1669
      typedef _Maybe_wrap_member_pointer::type>
1670
        __maybe_type;
1671
      typedef typename __maybe_type::type __functor_type;
1672
      typedef _Bind_result<_Result,
1673
                           __functor_type(typename decay<_BoundArgs>::type...)>
1674
        type;
1675
    };
1676
 
1677
  /**
1678
   *  @brief Function template for std::bind.
1679
   *  @ingroup binders
1680
   */
1681
  template
1682
    inline
1683
    typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
1684
    bind(_Func&& __f, _BoundArgs&&... __args)
1685
    {
1686
      typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
1687
      typedef typename __helper_type::__maybe_type __maybe_type;
1688
      typedef typename __helper_type::type __result_type;
1689
      return __result_type(__maybe_type::__do_wrap(std::forward<_Func>(__f)),
1690
                           std::forward<_BoundArgs>(__args)...);
1691
    }
1692
 
1693
  template
1694
    struct _Bind_simple;
1695
 
1696
  template
1697
    struct _Bind_simple<_Callable(_Args...)>
1698
    {
1699
      typedef typename result_of<_Callable(_Args...)>::type result_type;
1700
 
1701
      template
1702
               enable_if< sizeof...(_Args) == sizeof...(_Args2)>::type>
1703
        explicit
1704
        _Bind_simple(const _Callable& __callable, _Args2&&... __args)
1705
        : _M_bound(__callable, std::forward<_Args2>(__args)...)
1706
        { }
1707
 
1708
      template
1709
               enable_if< sizeof...(_Args) == sizeof...(_Args2)>::type>
1710
        explicit
1711
        _Bind_simple(_Callable&& __callable, _Args2&&... __args)
1712
        : _M_bound(std::move(__callable), std::forward<_Args2>(__args)...)
1713
        { }
1714
 
1715
      _Bind_simple(const _Bind_simple&) = default;
1716
      _Bind_simple(_Bind_simple&&) = default;
1717
 
1718
      result_type
1719
      operator()()
1720
      {
1721
        typedef typename _Build_index_tuple::__type _Indices;
1722
        return _M_invoke(_Indices());
1723
      }
1724
 
1725
    private:
1726
 
1727
      template
1728
        typename result_of<_Callable(_Args...)>::type
1729
        _M_invoke(_Index_tuple<_Indices...>)
1730
        {
1731
          // std::bind always forwards bound arguments as lvalues,
1732
          // but this type can call functions which only accept rvalues.
1733
          return std::forward<_Callable>(std::get<0>(_M_bound))(
1734
              std::forward<_Args>(std::get<_Indices+1>(_M_bound))...);
1735
        }
1736
 
1737
      std::tuple<_Callable, _Args...> _M_bound;
1738
    };
1739
 
1740
  template
1741
    struct _Bind_simple_helper
1742
    {
1743
      typedef _Maybe_wrap_member_pointer::type>
1744
        __maybe_type;
1745
      typedef typename __maybe_type::type __func_type;
1746
      typedef _Bind_simple<__func_type(typename decay<_BoundArgs>::type...)>
1747
        __type;
1748
    };
1749
 
1750
  // Simplified version of std::bind for internal use, without support for
1751
  // unbound arguments, placeholders or nested bind expressions.
1752
  template
1753
    typename _Bind_simple_helper<_Callable, _Args...>::__type
1754
    __bind_simple(_Callable&& __callable, _Args&&... __args)
1755
    {
1756
      typedef _Bind_simple_helper<_Callable, _Args...> __helper_type;
1757
      typedef typename __helper_type::__maybe_type __maybe_type;
1758
      typedef typename __helper_type::__type __result_type;
1759
      return __result_type(
1760
          __maybe_type::__do_wrap( std::forward<_Callable>(__callable)),
1761
          std::forward<_Args>(__args)...);
1762
    }
1763
 
1764
  /**
1765
   *  @brief Exception class thrown when class template function's
1766
   *  operator() is called with an empty target.
1767
   *  @ingroup exceptions
1768
   */
1769
  class bad_function_call : public std::exception
1770
  {
1771
  public:
1772
    virtual ~bad_function_call() noexcept;
1773
  };
1774
 
1775
  /**
1776
   *  Trait identifying "location-invariant" types, meaning that the
1777
   *  address of the object (or any of its members) will not escape.
1778
   *  Also implies a trivial copy constructor and assignment operator.
1779
   */
1780
  template
1781
    struct __is_location_invariant
1782
    : integral_constant::value
1783
                               || is_member_pointer<_Tp>::value)>
1784
    { };
1785
 
1786
  class _Undefined_class;
1787
 
1788
  union _Nocopy_types
1789
  {
1790
    void*       _M_object;
1791
    const void* _M_const_object;
1792
    void (*_M_function_pointer)();
1793
    void (_Undefined_class::*_M_member_pointer)();
1794
  };
1795
 
1796
  union _Any_data
1797
  {
1798
    void*       _M_access()       { return &_M_pod_data[0]; }
1799
    const void* _M_access() const { return &_M_pod_data[0]; }
1800
 
1801
    template
1802
      _Tp&
1803
      _M_access()
1804
      { return *static_cast<_Tp*>(_M_access()); }
1805
 
1806
    template
1807
      const _Tp&
1808
      _M_access() const
1809
      { return *static_cast(_M_access()); }
1810
 
1811
    _Nocopy_types _M_unused;
1812
    char _M_pod_data[sizeof(_Nocopy_types)];
1813
  };
1814
 
1815
  enum _Manager_operation
1816
  {
1817
    __get_type_info,
1818
    __get_functor_ptr,
1819
    __clone_functor,
1820
    __destroy_functor
1821
  };
1822
 
1823
  // Simple type wrapper that helps avoid annoying const problems
1824
  // when casting between void pointers and pointers-to-pointers.
1825
  template
1826
    struct _Simple_type_wrapper
1827
    {
1828
      _Simple_type_wrapper(_Tp __value) : __value(__value) { }
1829
 
1830
      _Tp __value;
1831
    };
1832
 
1833
  template
1834
    struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
1835
    : __is_location_invariant<_Tp>
1836
    { };
1837
 
1838
  // Converts a reference to a function object into a callable
1839
  // function object.
1840
  template
1841
    inline _Functor&
1842
    __callable_functor(_Functor& __f)
1843
    { return __f; }
1844
 
1845
  template
1846
    inline _Mem_fn<_Member _Class::*>
1847
    __callable_functor(_Member _Class::* &__p)
1848
    { return std::mem_fn(__p); }
1849
 
1850
  template
1851
    inline _Mem_fn<_Member _Class::*>
1852
    __callable_functor(_Member _Class::* const &__p)
1853
    { return std::mem_fn(__p); }
1854
 
1855
  template
1856
    inline _Mem_fn<_Member _Class::*>
1857
    __callable_functor(_Member _Class::* volatile &__p)
1858
    { return std::mem_fn(__p); }
1859
 
1860
  template
1861
    inline _Mem_fn<_Member _Class::*>
1862
    __callable_functor(_Member _Class::* const volatile &__p)
1863
    { return std::mem_fn(__p); }
1864
 
1865
  template
1866
    class function;
1867
 
1868
  /// Base class of all polymorphic function object wrappers.
1869
  class _Function_base
1870
  {
1871
  public:
1872
    static const std::size_t _M_max_size = sizeof(_Nocopy_types);
1873
    static const std::size_t _M_max_align = __alignof__(_Nocopy_types);
1874
 
1875
    template
1876
      class _Base_manager
1877
      {
1878
      protected:
1879
        static const bool __stored_locally =
1880
        (__is_location_invariant<_Functor>::value
1881
         && sizeof(_Functor) <= _M_max_size
1882
         && __alignof__(_Functor) <= _M_max_align
1883
         && (_M_max_align % __alignof__(_Functor) == 0));
1884
 
1885
        typedef integral_constant _Local_storage;
1886
 
1887
        // Retrieve a pointer to the function object
1888
        static _Functor*
1889
        _M_get_pointer(const _Any_data& __source)
1890
        {
1891
          const _Functor* __ptr =
1892
            __stored_locally? std::__addressof(__source._M_access<_Functor>())
1893
            /* have stored a pointer */ : __source._M_access<_Functor*>();
1894
          return const_cast<_Functor*>(__ptr);
1895
        }
1896
 
1897
        // Clone a location-invariant function object that fits within
1898
        // an _Any_data structure.
1899
        static void
1900
        _M_clone(_Any_data& __dest, const _Any_data& __source, true_type)
1901
        {
1902
          new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
1903
        }
1904
 
1905
        // Clone a function object that is not location-invariant or
1906
        // that cannot fit into an _Any_data structure.
1907
        static void
1908
        _M_clone(_Any_data& __dest, const _Any_data& __source, false_type)
1909
        {
1910
          __dest._M_access<_Functor*>() =
1911
            new _Functor(*__source._M_access<_Functor*>());
1912
        }
1913
 
1914
        // Destroying a location-invariant object may still require
1915
        // destruction.
1916
        static void
1917
        _M_destroy(_Any_data& __victim, true_type)
1918
        {
1919
          __victim._M_access<_Functor>().~_Functor();
1920
        }
1921
 
1922
        // Destroying an object located on the heap.
1923
        static void
1924
        _M_destroy(_Any_data& __victim, false_type)
1925
        {
1926
          delete __victim._M_access<_Functor*>();
1927
        }
1928
 
1929
      public:
1930
        static bool
1931
        _M_manager(_Any_data& __dest, const _Any_data& __source,
1932
                   _Manager_operation __op)
1933
        {
1934
          switch (__op)
1935
            {
1936
#ifdef __GXX_RTTI
1937
            case __get_type_info:
1938
              __dest._M_access() = &typeid(_Functor);
1939
              break;
1940
#endif
1941
            case __get_functor_ptr:
1942
              __dest._M_access<_Functor*>() = _M_get_pointer(__source);
1943
              break;
1944
 
1945
            case __clone_functor:
1946
              _M_clone(__dest, __source, _Local_storage());
1947
              break;
1948
 
1949
            case __destroy_functor:
1950
              _M_destroy(__dest, _Local_storage());
1951
              break;
1952
            }
1953
          return false;
1954
        }
1955
 
1956
        static void
1957
        _M_init_functor(_Any_data& __functor, _Functor&& __f)
1958
        { _M_init_functor(__functor, std::move(__f), _Local_storage()); }
1959
 
1960
        template
1961
          static bool
1962
          _M_not_empty_function(const function<_Signature>& __f)
1963
          { return static_cast(__f); }
1964
 
1965
        template
1966
          static bool
1967
          _M_not_empty_function(const _Tp*& __fp)
1968
          { return __fp; }
1969
 
1970
        template
1971
          static bool
1972
          _M_not_empty_function(_Tp _Class::* const& __mp)
1973
          { return __mp; }
1974
 
1975
        template
1976
          static bool
1977
          _M_not_empty_function(const _Tp&)
1978
          { return true; }
1979
 
1980
      private:
1981
        static void
1982
        _M_init_functor(_Any_data& __functor, _Functor&& __f, true_type)
1983
        { new (__functor._M_access()) _Functor(std::move(__f)); }
1984
 
1985
        static void
1986
        _M_init_functor(_Any_data& __functor, _Functor&& __f, false_type)
1987
        { __functor._M_access<_Functor*>() = new _Functor(std::move(__f)); }
1988
      };
1989
 
1990
    template
1991
      class _Ref_manager : public _Base_manager<_Functor*>
1992
      {
1993
        typedef _Function_base::_Base_manager<_Functor*> _Base;
1994
 
1995
      public:
1996
        static bool
1997
        _M_manager(_Any_data& __dest, const _Any_data& __source,
1998
                   _Manager_operation __op)
1999
        {
2000
          switch (__op)
2001
            {
2002
#ifdef __GXX_RTTI
2003
            case __get_type_info:
2004
              __dest._M_access() = &typeid(_Functor);
2005
              break;
2006
#endif
2007
            case __get_functor_ptr:
2008
              __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source);
2009
              return is_const<_Functor>::value;
2010
              break;
2011
 
2012
            default:
2013
              _Base::_M_manager(__dest, __source, __op);
2014
            }
2015
          return false;
2016
        }
2017
 
2018
        static void
2019
        _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
2020
        {
2021
          _Base::_M_init_functor(__functor, std::__addressof(__f.get()));
2022
        }
2023
      };
2024
 
2025
    _Function_base() : _M_manager(0) { }
2026
 
2027
    ~_Function_base()
2028
    {
2029
      if (_M_manager)
2030
        _M_manager(_M_functor, _M_functor, __destroy_functor);
2031
    }
2032
 
2033
 
2034
    bool _M_empty() const { return !_M_manager; }
2035
 
2036
    typedef bool (*_Manager_type)(_Any_data&, const _Any_data&,
2037
                                  _Manager_operation);
2038
 
2039
    _Any_data     _M_functor;
2040
    _Manager_type _M_manager;
2041
  };
2042
 
2043
  template
2044
    class _Function_handler;
2045
 
2046
  template
2047
    class _Function_handler<_Res(_ArgTypes...), _Functor>
2048
    : public _Function_base::_Base_manager<_Functor>
2049
    {
2050
      typedef _Function_base::_Base_manager<_Functor> _Base;
2051
 
2052
    public:
2053
      static _Res
2054
      _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
2055
      {
2056
        return (*_Base::_M_get_pointer(__functor))(
2057
            std::forward<_ArgTypes>(__args)...);
2058
      }
2059
    };
2060
 
2061
  template
2062
    class _Function_handler
2063
    : public _Function_base::_Base_manager<_Functor>
2064
    {
2065
      typedef _Function_base::_Base_manager<_Functor> _Base;
2066
 
2067
     public:
2068
      static void
2069
      _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
2070
      {
2071
        (*_Base::_M_get_pointer(__functor))(
2072
            std::forward<_ArgTypes>(__args)...);
2073
      }
2074
    };
2075
 
2076
  template
2077
    class _Function_handler<_Res(_ArgTypes...), reference_wrapper<_Functor> >
2078
    : public _Function_base::_Ref_manager<_Functor>
2079
    {
2080
      typedef _Function_base::_Ref_manager<_Functor> _Base;
2081
 
2082
     public:
2083
      static _Res
2084
      _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
2085
      {
2086
        return __callable_functor(**_Base::_M_get_pointer(__functor))(
2087
              std::forward<_ArgTypes>(__args)...);
2088
      }
2089
    };
2090
 
2091
  template
2092
    class _Function_handler >
2093
    : public _Function_base::_Ref_manager<_Functor>
2094
    {
2095
      typedef _Function_base::_Ref_manager<_Functor> _Base;
2096
 
2097
     public:
2098
      static void
2099
      _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
2100
      {
2101
        __callable_functor(**_Base::_M_get_pointer(__functor))(
2102
            std::forward<_ArgTypes>(__args)...);
2103
      }
2104
    };
2105
 
2106
  template
2107
           typename... _ArgTypes>
2108
    class _Function_handler<_Res(_ArgTypes...), _Member _Class::*>
2109
    : public _Function_handler
2110
    {
2111
      typedef _Function_handler
2112
        _Base;
2113
 
2114
     public:
2115
      static _Res
2116
      _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
2117
      {
2118
        return std::mem_fn(_Base::_M_get_pointer(__functor)->__value)(
2119
            std::forward<_ArgTypes>(__args)...);
2120
      }
2121
    };
2122
 
2123
  template
2124
    class _Function_handler
2125
    : public _Function_base::_Base_manager<
2126
                 _Simple_type_wrapper< _Member _Class::* > >
2127
    {
2128
      typedef _Member _Class::* _Functor;
2129
      typedef _Simple_type_wrapper<_Functor> _Wrapper;
2130
      typedef _Function_base::_Base_manager<_Wrapper> _Base;
2131
 
2132
    public:
2133
      static bool
2134
      _M_manager(_Any_data& __dest, const _Any_data& __source,
2135
                 _Manager_operation __op)
2136
      {
2137
        switch (__op)
2138
          {
2139
#ifdef __GXX_RTTI
2140
          case __get_type_info:
2141
            __dest._M_access() = &typeid(_Functor);
2142
            break;
2143
#endif
2144
          case __get_functor_ptr:
2145
            __dest._M_access<_Functor*>() =
2146
              &_Base::_M_get_pointer(__source)->__value;
2147
            break;
2148
 
2149
          default:
2150
            _Base::_M_manager(__dest, __source, __op);
2151
          }
2152
        return false;
2153
      }
2154
 
2155
      static void
2156
      _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
2157
      {
2158
        std::mem_fn(_Base::_M_get_pointer(__functor)->__value)(
2159
            std::forward<_ArgTypes>(__args)...);
2160
      }
2161
    };
2162
 
2163
  /**
2164
   *  @brief Primary class template for std::function.
2165
   *  @ingroup functors
2166
   *
2167
   *  Polymorphic function wrapper.
2168
   */
2169
  template
2170
    class function<_Res(_ArgTypes...)>
2171
    : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>,
2172
      private _Function_base
2173
    {
2174
      typedef _Res _Signature_type(_ArgTypes...);
2175
 
2176
      template
2177
        using _Invoke = decltype(__callable_functor(std::declval<_Functor&>())
2178
                                 (std::declval<_ArgTypes>()...) );
2179
 
2180
      template
2181
        struct _CheckResult
2182
        : is_convertible<_CallRes, _Res1> { };
2183
 
2184
      template
2185
        struct _CheckResult<_CallRes, void>
2186
        : true_type { };
2187
 
2188
      template
2189
        using _Callable = _CheckResult<_Invoke<_Functor>, _Res>;
2190
 
2191
      template
2192
        using _Requires = typename enable_if<_Cond::value, _Tp>::type;
2193
 
2194
    public:
2195
      typedef _Res result_type;
2196
 
2197
      // [3.7.2.1] construct/copy/destroy
2198
 
2199
      /**
2200
       *  @brief Default construct creates an empty function call wrapper.
2201
       *  @post @c !(bool)*this
2202
       */
2203
      function() noexcept
2204
      : _Function_base() { }
2205
 
2206
      /**
2207
       *  @brief Creates an empty function call wrapper.
2208
       *  @post @c !(bool)*this
2209
       */
2210
      function(nullptr_t) noexcept
2211
      : _Function_base() { }
2212
 
2213
      /**
2214
       *  @brief %Function copy constructor.
2215
       *  @param __x A %function object with identical call signature.
2216
       *  @post @c bool(*this) == bool(__x)
2217
       *
2218
       *  The newly-created %function contains a copy of the target of @a
2219
       *  __x (if it has one).
2220
       */
2221
      function(const function& __x);
2222
 
2223
      /**
2224
       *  @brief %Function move constructor.
2225
       *  @param __x A %function object rvalue with identical call signature.
2226
       *
2227
       *  The newly-created %function contains the target of @a __x
2228
       *  (if it has one).
2229
       */
2230
      function(function&& __x) : _Function_base()
2231
      {
2232
        __x.swap(*this);
2233
      }
2234
 
2235
      // TODO: needs allocator_arg_t
2236
 
2237
      /**
2238
       *  @brief Builds a %function that targets a copy of the incoming
2239
       *  function object.
2240
       *  @param __f A %function object that is callable with parameters of
2241
       *  type @c T1, @c T2, ..., @c TN and returns a value convertible
2242
       *  to @c Res.
2243
       *
2244
       *  The newly-created %function object will target a copy of
2245
       *  @a __f. If @a __f is @c reference_wrapper, then this function
2246
       *  object will contain a reference to the function object @c
2247
       *  __f.get(). If @a __f is a NULL function pointer or NULL
2248
       *  pointer-to-member, the newly-created object will be empty.
2249
       *
2250
       *  If @a __f is a non-NULL function pointer or an object of type @c
2251
       *  reference_wrapper, this function will not throw.
2252
       */
2253
      template
2254
               typename = _Requires<_Callable<_Functor>, void>>
2255
        function(_Functor);
2256
 
2257
      /**
2258
       *  @brief %Function assignment operator.
2259
       *  @param __x A %function with identical call signature.
2260
       *  @post @c (bool)*this == (bool)x
2261
       *  @returns @c *this
2262
       *
2263
       *  The target of @a __x is copied to @c *this. If @a __x has no
2264
       *  target, then @c *this will be empty.
2265
       *
2266
       *  If @a __x targets a function pointer or a reference to a function
2267
       *  object, then this operation will not throw an %exception.
2268
       */
2269
      function&
2270
      operator=(const function& __x)
2271
      {
2272
        function(__x).swap(*this);
2273
        return *this;
2274
      }
2275
 
2276
      /**
2277
       *  @brief %Function move-assignment operator.
2278
       *  @param __x A %function rvalue with identical call signature.
2279
       *  @returns @c *this
2280
       *
2281
       *  The target of @a __x is moved to @c *this. If @a __x has no
2282
       *  target, then @c *this will be empty.
2283
       *
2284
       *  If @a __x targets a function pointer or a reference to a function
2285
       *  object, then this operation will not throw an %exception.
2286
       */
2287
      function&
2288
      operator=(function&& __x)
2289
      {
2290
        function(std::move(__x)).swap(*this);
2291
        return *this;
2292
      }
2293
 
2294
      /**
2295
       *  @brief %Function assignment to zero.
2296
       *  @post @c !(bool)*this
2297
       *  @returns @c *this
2298
       *
2299
       *  The target of @c *this is deallocated, leaving it empty.
2300
       */
2301
      function&
2302
      operator=(nullptr_t)
2303
      {
2304
        if (_M_manager)
2305
          {
2306
            _M_manager(_M_functor, _M_functor, __destroy_functor);
2307
            _M_manager = 0;
2308
            _M_invoker = 0;
2309
          }
2310
        return *this;
2311
      }
2312
 
2313
      /**
2314
       *  @brief %Function assignment to a new target.
2315
       *  @param __f A %function object that is callable with parameters of
2316
       *  type @c T1, @c T2, ..., @c TN and returns a value convertible
2317
       *  to @c Res.
2318
       *  @return @c *this
2319
       *
2320
       *  This  %function object wrapper will target a copy of @a
2321
       *  __f. If @a __f is @c reference_wrapper, then this function
2322
       *  object will contain a reference to the function object @c
2323
       *  __f.get(). If @a __f is a NULL function pointer or NULL
2324
       *  pointer-to-member, @c this object will be empty.
2325
       *
2326
       *  If @a __f is a non-NULL function pointer or an object of type @c
2327
       *  reference_wrapper, this function will not throw.
2328
       */
2329
      template
2330
        _Requires<_Callable<_Functor>, function&>
2331
        operator=(_Functor&& __f)
2332
        {
2333
          function(std::forward<_Functor>(__f)).swap(*this);
2334
          return *this;
2335
        }
2336
 
2337
      /// @overload
2338
      template
2339
        function&
2340
        operator=(reference_wrapper<_Functor> __f) noexcept
2341
        {
2342
          function(__f).swap(*this);
2343
          return *this;
2344
        }
2345
 
2346
      // [3.7.2.2] function modifiers
2347
 
2348
      /**
2349
       *  @brief Swap the targets of two %function objects.
2350
       *  @param __x A %function with identical call signature.
2351
       *
2352
       *  Swap the targets of @c this function object and @a __f. This
2353
       *  function will not throw an %exception.
2354
       */
2355
      void swap(function& __x)
2356
      {
2357
        std::swap(_M_functor, __x._M_functor);
2358
        std::swap(_M_manager, __x._M_manager);
2359
        std::swap(_M_invoker, __x._M_invoker);
2360
      }
2361
 
2362
      // TODO: needs allocator_arg_t
2363
      /*
2364
      template
2365
        void
2366
        assign(_Functor&& __f, const _Alloc& __a)
2367
        {
2368
          function(allocator_arg, __a,
2369
                   std::forward<_Functor>(__f)).swap(*this);
2370
        }
2371
      */
2372
 
2373
      // [3.7.2.3] function capacity
2374
 
2375
      /**
2376
       *  @brief Determine if the %function wrapper has a target.
2377
       *
2378
       *  @return @c true when this %function object contains a target,
2379
       *  or @c false when it is empty.
2380
       *
2381
       *  This function will not throw an %exception.
2382
       */
2383
      explicit operator bool() const noexcept
2384
      { return !_M_empty(); }
2385
 
2386
      // [3.7.2.4] function invocation
2387
 
2388
      /**
2389
       *  @brief Invokes the function targeted by @c *this.
2390
       *  @returns the result of the target.
2391
       *  @throws bad_function_call when @c !(bool)*this
2392
       *
2393
       *  The function call operator invokes the target function object
2394
       *  stored by @c this.
2395
       */
2396
      _Res operator()(_ArgTypes... __args) const;
2397
 
2398
#ifdef __GXX_RTTI
2399
      // [3.7.2.5] function target access
2400
      /**
2401
       *  @brief Determine the type of the target of this function object
2402
       *  wrapper.
2403
       *
2404
       *  @returns the type identifier of the target function object, or
2405
       *  @c typeid(void) if @c !(bool)*this.
2406
       *
2407
       *  This function will not throw an %exception.
2408
       */
2409
      const type_info& target_type() const noexcept;
2410
 
2411
      /**
2412
       *  @brief Access the stored target function object.
2413
       *
2414
       *  @return Returns a pointer to the stored target function object,
2415
       *  if @c typeid(Functor).equals(target_type()); otherwise, a NULL
2416
       *  pointer.
2417
       *
2418
       * This function will not throw an %exception.
2419
       */
2420
      template       _Functor* target() noexcept;
2421
 
2422
      /// @overload
2423
      template const _Functor* target() const noexcept;
2424
#endif
2425
 
2426
    private:
2427
      typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...);
2428
      _Invoker_type _M_invoker;
2429
  };
2430
 
2431
  // Out-of-line member definitions.
2432
  template
2433
    function<_Res(_ArgTypes...)>::
2434
    function(const function& __x)
2435
    : _Function_base()
2436
    {
2437
      if (static_cast(__x))
2438
        {
2439
          _M_invoker = __x._M_invoker;
2440
          _M_manager = __x._M_manager;
2441
          __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
2442
        }
2443
    }
2444
 
2445
  template
2446
    template
2447
      function<_Res(_ArgTypes...)>::
2448
      function(_Functor __f)
2449
      : _Function_base()
2450
      {
2451
        typedef _Function_handler<_Signature_type, _Functor> _My_handler;
2452
 
2453
        if (_My_handler::_M_not_empty_function(__f))
2454
          {
2455
            _My_handler::_M_init_functor(_M_functor, std::move(__f));
2456
            _M_invoker = &_My_handler::_M_invoke;
2457
            _M_manager = &_My_handler::_M_manager;
2458
          }
2459
      }
2460
 
2461
  template
2462
    _Res
2463
    function<_Res(_ArgTypes...)>::
2464
    operator()(_ArgTypes... __args) const
2465
    {
2466
      if (_M_empty())
2467
        __throw_bad_function_call();
2468
      return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
2469
    }
2470
 
2471
#ifdef __GXX_RTTI
2472
  template
2473
    const type_info&
2474
    function<_Res(_ArgTypes...)>::
2475
    target_type() const noexcept
2476
    {
2477
      if (_M_manager)
2478
        {
2479
          _Any_data __typeinfo_result;
2480
          _M_manager(__typeinfo_result, _M_functor, __get_type_info);
2481
          return *__typeinfo_result._M_access();
2482
        }
2483
      else
2484
        return typeid(void);
2485
    }
2486
 
2487
  template
2488
    template
2489
      _Functor*
2490
      function<_Res(_ArgTypes...)>::
2491
      target() noexcept
2492
      {
2493
        if (typeid(_Functor) == target_type() && _M_manager)
2494
          {
2495
            _Any_data __ptr;
2496
            if (_M_manager(__ptr, _M_functor, __get_functor_ptr)
2497
                && !is_const<_Functor>::value)
2498
              return 0;
2499
            else
2500
              return __ptr._M_access<_Functor*>();
2501
          }
2502
        else
2503
          return 0;
2504
      }
2505
 
2506
  template
2507
    template
2508
      const _Functor*
2509
      function<_Res(_ArgTypes...)>::
2510
      target() const noexcept
2511
      {
2512
        if (typeid(_Functor) == target_type() && _M_manager)
2513
          {
2514
            _Any_data __ptr;
2515
            _M_manager(__ptr, _M_functor, __get_functor_ptr);
2516
            return __ptr._M_access();
2517
          }
2518
        else
2519
          return 0;
2520
      }
2521
#endif
2522
 
2523
  // [20.7.15.2.6] null pointer comparisons
2524
 
2525
  /**
2526
   *  @brief Compares a polymorphic function object wrapper against 0
2527
   *  (the NULL pointer).
2528
   *  @returns @c true if the wrapper has no target, @c false otherwise
2529
   *
2530
   *  This function will not throw an %exception.
2531
   */
2532
  template
2533
    inline bool
2534
    operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
2535
    { return !static_cast(__f); }
2536
 
2537
  /// @overload
2538
  template
2539
    inline bool
2540
    operator==(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
2541
    { return !static_cast(__f); }
2542
 
2543
  /**
2544
   *  @brief Compares a polymorphic function object wrapper against 0
2545
   *  (the NULL pointer).
2546
   *  @returns @c false if the wrapper has no target, @c true otherwise
2547
   *
2548
   *  This function will not throw an %exception.
2549
   */
2550
  template
2551
    inline bool
2552
    operator!=(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
2553
    { return static_cast(__f); }
2554
 
2555
  /// @overload
2556
  template
2557
    inline bool
2558
    operator!=(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
2559
    { return static_cast(__f); }
2560
 
2561
  // [20.7.15.2.7] specialized algorithms
2562
 
2563
  /**
2564
   *  @brief Swap the targets of two polymorphic function object wrappers.
2565
   *
2566
   *  This function will not throw an %exception.
2567
   */
2568
  template
2569
    inline void
2570
    swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y)
2571
    { __x.swap(__y); }
2572
 
2573
_GLIBCXX_END_NAMESPACE_VERSION
2574
} // namespace std
2575
 
2576
#endif // C++11
2577
 
2578
#endif // _GLIBCXX_FUNCTIONAL

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.