~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to system/include/libcxx/vector

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
272
272
 
273
273
#include <__undef_min_max>
274
274
 
 
275
#ifdef _LIBCPP_DEBUG2
 
276
#   include <__debug>
 
277
#else
 
278
#   define _LIBCPP_ASSERT(x, m) ((void)0)
 
279
#endif
 
280
 
275
281
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
276
282
#pragma GCC system_header
277
283
#endif
309
315
#endif
310
316
}
311
317
 
312
 
#ifdef _MSC_VER
 
318
#ifdef _LIBCPP_MSVC
313
319
#pragma warning( push )
314
320
#pragma warning( disable: 4231 )
315
 
#endif // _MSC_VER
 
321
#endif // _LIBCPP_MSVC
316
322
_LIBCPP_EXTERN_TEMPLATE(class __vector_base_common<true>)
317
 
#ifdef _MSC_VER
 
323
#ifdef _LIBCPP_MSVC
318
324
#pragma warning( pop )
319
 
#endif // _MSC_VER
 
325
#endif // _LIBCPP_MSVC
320
326
 
321
327
template <class _Tp, class _Allocator>
322
328
class __vector_base
365
371
        {return static_cast<size_type>(__end_cap() - __begin_);}
366
372
 
367
373
    _LIBCPP_INLINE_VISIBILITY
368
 
    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
369
 
        {__destruct_at_end(__new_last, false_type());}
370
 
    _LIBCPP_INLINE_VISIBILITY
371
 
    void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
372
 
    _LIBCPP_INLINE_VISIBILITY
373
 
    void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
 
374
    void __destruct_at_end(pointer __new_last) _NOEXCEPT;
374
375
 
375
376
    _LIBCPP_INLINE_VISIBILITY
376
377
    void __copy_assign_alloc(const __vector_base& __c)
437
438
template <class _Tp, class _Allocator>
438
439
_LIBCPP_INLINE_VISIBILITY inline
439
440
void
440
 
__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
 
441
__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
441
442
{
442
443
    while (__new_last != __end_)
443
 
        __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
444
 
}
445
 
 
446
 
template <class _Tp, class _Allocator>
447
 
_LIBCPP_INLINE_VISIBILITY inline
448
 
void
449
 
__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
450
 
{
451
 
    __end_ = const_cast<pointer>(__new_last);
 
444
        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
452
445
}
453
446
 
454
447
template <class _Tp, class _Allocator>
455
448
_LIBCPP_INLINE_VISIBILITY inline
456
449
__vector_base<_Tp, _Allocator>::__vector_base()
457
450
        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
458
 
    : __begin_(0),
459
 
      __end_(0),
460
 
      __end_cap_(0)
 
451
    : __begin_(nullptr),
 
452
      __end_(nullptr),
 
453
      __end_cap_(nullptr)
461
454
{
462
455
}
463
456
 
464
457
template <class _Tp, class _Allocator>
465
458
_LIBCPP_INLINE_VISIBILITY inline
466
459
__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
467
 
    : __begin_(0),
468
 
      __end_(0),
469
 
      __end_cap_(0, __a)
 
460
    : __begin_(nullptr),
 
461
      __end_(nullptr),
 
462
      __end_cap_(nullptr, __a)
470
463
{
471
464
}
472
465
 
473
466
template <class _Tp, class _Allocator>
474
467
__vector_base<_Tp, _Allocator>::~__vector_base()
475
468
{
476
 
    if (__begin_ != 0)
 
469
    if (__begin_ != nullptr)
477
470
    {
478
471
        clear();
479
472
        __alloc_traits::deallocate(__alloc(), __begin_, capacity());
797
790
        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
798
791
    void __move_assign(vector& __c, false_type);
799
792
    _LIBCPP_INLINE_VISIBILITY
800
 
    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
 
793
    void __destruct_at_end(pointer __new_last) _NOEXCEPT
801
794
    {
802
795
#if _LIBCPP_DEBUG_LEVEL >= 2
803
796
        __c_node* __c = __get_db()->__find_c_and_lock(this);
878
871
void
879
872
vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
880
873
{
881
 
    if (this->__begin_ != 0)
 
874
    if (this->__begin_ != nullptr)
882
875
    {
883
876
        clear();
884
877
        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
885
 
        this->__begin_ = this->__end_ = this->__end_cap() = 0;
 
878
        this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
886
879
    }
887
880
}
888
881
 
1171
1164
    this->__begin_ = __x.__begin_;
1172
1165
    this->__end_ = __x.__end_;
1173
1166
    this->__end_cap() = __x.__end_cap();
1174
 
    __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
 
1167
    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1175
1168
}
1176
1169
 
1177
1170
template <class _Tp, class _Allocator>
1597
1590
#endif
1598
1591
    _LIBCPP_ASSERT(__position != end(),
1599
1592
        "vector::erase(iterator) called with a non-dereferenceable iterator");
1600
 
    pointer __p = const_cast<pointer>(&*__position);
 
1593
    difference_type __ps = __position - cbegin();
 
1594
    pointer __p = this->__begin_ + __ps;
1601
1595
    iterator __r = __make_iter(__p);
1602
1596
    this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1603
1597
    return __r;
1615
1609
    _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1616
1610
    pointer __p = this->__begin_ + (__first - begin());
1617
1611
    iterator __r = __make_iter(__p);
1618
 
    this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
 
1612
    if (__first != __last)
 
1613
        this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1619
1614
    return __r;
1620
1615
}
1621
1616
 
1942
1937
bool
1943
1938
vector<_Tp, _Allocator>::__invariants() const
1944
1939
{
1945
 
    if (this->__begin_ == 0)
 
1940
    if (this->__begin_ == nullptr)
1946
1941
    {
1947
 
        if (this->__end_ != 0 || this->__end_cap() != 0)
 
1942
        if (this->__end_ != nullptr || this->__end_cap() != nullptr)
1948
1943
            return false;
1949
1944
    }
1950
1945
    else
2306
2301
        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2307
2302
    _LIBCPP_INLINE_VISIBILITY
2308
2303
    iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2309
 
        {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
 
2304
        {return begin() + (__p - cbegin());}
2310
2305
#endif  // _LIBCPP_DEBUG
2311
2306
 
2312
2307
    _LIBCPP_INLINE_VISIBILITY
2413
2408
void
2414
2409
vector<bool, _Allocator>::deallocate() _NOEXCEPT
2415
2410
{
2416
 
    if (this->__begin_ != 0)
 
2411
    if (this->__begin_ != nullptr)
2417
2412
    {
2418
2413
        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2419
2414
        __invalidate_all_iterators();
2420
 
        this->__begin_ = 0;
 
2415
        this->__begin_ = nullptr;
2421
2416
        this->__size_ = this->__cap() = 0;
2422
2417
    }
2423
2418
}
2480
2475
_LIBCPP_INLINE_VISIBILITY inline
2481
2476
vector<bool, _Allocator>::vector()
2482
2477
        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2483
 
    : __begin_(0),
 
2478
    : __begin_(nullptr),
2484
2479
      __size_(0),
2485
2480
      __cap_alloc_(0)
2486
2481
{
2489
2484
template <class _Allocator>
2490
2485
_LIBCPP_INLINE_VISIBILITY inline
2491
2486
vector<bool, _Allocator>::vector(const allocator_type& __a)
2492
 
    : __begin_(0),
 
2487
    : __begin_(nullptr),
2493
2488
      __size_(0),
2494
2489
      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2495
2490
{
2497
2492
 
2498
2493
template <class _Allocator>
2499
2494
vector<bool, _Allocator>::vector(size_type __n)
2500
 
    : __begin_(0),
 
2495
    : __begin_(nullptr),
2501
2496
      __size_(0),
2502
2497
      __cap_alloc_(0)
2503
2498
{
2510
2505
 
2511
2506
template <class _Allocator>
2512
2507
vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2513
 
    : __begin_(0),
 
2508
    : __begin_(nullptr),
2514
2509
      __size_(0),
2515
2510
      __cap_alloc_(0)
2516
2511
{
2523
2518
 
2524
2519
template <class _Allocator>
2525
2520
vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2526
 
    : __begin_(0),
 
2521
    : __begin_(nullptr),
2527
2522
      __size_(0),
2528
2523
      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2529
2524
{
2539
2534
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2540
2535
       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2541
2536
                         !__is_forward_iterator<_InputIterator>::value>::type*)
2542
 
    : __begin_(0),
 
2537
    : __begin_(nullptr),
2543
2538
      __size_(0),
2544
2539
      __cap_alloc_(0)
2545
2540
{
2553
2548
    }
2554
2549
    catch (...)
2555
2550
    {
2556
 
        if (__begin_ != 0)
 
2551
        if (__begin_ != nullptr)
2557
2552
            __storage_traits::deallocate(__alloc(), __begin_, __cap());
2558
2553
        __invalidate_all_iterators();
2559
2554
        throw;
2566
2561
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2567
2562
       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2568
2563
                         !__is_forward_iterator<_InputIterator>::value>::type*)
2569
 
    : __begin_(0),
 
2564
    : __begin_(nullptr),
2570
2565
      __size_(0),
2571
2566
      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2572
2567
{
2580
2575
    }
2581
2576
    catch (...)
2582
2577
    {
2583
 
        if (__begin_ != 0)
 
2578
        if (__begin_ != nullptr)
2584
2579
            __storage_traits::deallocate(__alloc(), __begin_, __cap());
2585
2580
        __invalidate_all_iterators();
2586
2581
        throw;
2592
2587
template <class _ForwardIterator>
2593
2588
vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2594
2589
                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2595
 
    : __begin_(0),
 
2590
    : __begin_(nullptr),
2596
2591
      __size_(0),
2597
2592
      __cap_alloc_(0)
2598
2593
{
2608
2603
template <class _ForwardIterator>
2609
2604
vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2610
2605
                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2611
 
    : __begin_(0),
 
2606
    : __begin_(nullptr),
2612
2607
      __size_(0),
2613
2608
      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2614
2609
{
2624
2619
 
2625
2620
template <class _Allocator>
2626
2621
vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2627
 
    : __begin_(0),
 
2622
    : __begin_(nullptr),
2628
2623
      __size_(0),
2629
2624
      __cap_alloc_(0)
2630
2625
{
2638
2633
 
2639
2634
template <class _Allocator>
2640
2635
vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2641
 
    : __begin_(0),
 
2636
    : __begin_(nullptr),
2642
2637
      __size_(0),
2643
2638
      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2644
2639
{
2655
2650
template <class _Allocator>
2656
2651
vector<bool, _Allocator>::~vector()
2657
2652
{
2658
 
    if (__begin_ != 0)
 
2653
    if (__begin_ != nullptr)
2659
2654
        __storage_traits::deallocate(__alloc(), __begin_, __cap());
2660
2655
#ifdef _LIBCPP_DEBUG
2661
2656
    __invalidate_all_iterators();
2664
2659
 
2665
2660
template <class _Allocator>
2666
2661
vector<bool, _Allocator>::vector(const vector& __v)
2667
 
    : __begin_(0),
 
2662
    : __begin_(nullptr),
2668
2663
      __size_(0),
2669
2664
      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2670
2665
{
2677
2672
 
2678
2673
template <class _Allocator>
2679
2674
vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2680
 
    : __begin_(0),
 
2675
    : __begin_(nullptr),
2681
2676
      __size_(0),
2682
2677
      __cap_alloc_(0, __a)
2683
2678
{
2719
2714
      __size_(__v.__size_),
2720
2715
      __cap_alloc_(__v.__cap_alloc_)
2721
2716
{
2722
 
    __v.__begin_ = 0;
 
2717
    __v.__begin_ = nullptr;
2723
2718
    __v.__size_ = 0;
2724
2719
    __v.__cap() = 0;
2725
2720
}
2726
2721
 
2727
2722
template <class _Allocator>
2728
2723
vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2729
 
    : __begin_(0),
 
2724
    : __begin_(nullptr),
2730
2725
      __size_(0),
2731
2726
      __cap_alloc_(0, __a)
2732
2727
{
3122
3117
bool
3123
3118
vector<bool, _Allocator>::__invariants() const
3124
3119
{
3125
 
    if (this->__begin_ == 0)
 
3120
    if (this->__begin_ == nullptr)
3126
3121
    {
3127
3122
        if (this->__size_ != 0 || this->__cap() != 0)
3128
3123
            return false;