|
23 | 23 | * - For ARM C 5, C++11/14 features:
|
24 | 24 | * - std::align
|
25 | 25 | * - std::addressof
|
| 26 | + * - std::uninitialized_copy_n |
26 | 27 | * - std::unique_ptr, std::make_unique, std::default_delete
|
| 28 | + * - For all toolchains, C++17 backports: |
| 29 | + * - mstd::uninitialized_default_construct, mstd::uninitialized_value_construct |
| 30 | + * - mstd::uninitialized_move, mstd::uninitialized_move_n |
| 31 | + * - mstd::destroy_at, mstd::destroy, mstd::destroy_n |
27 | 32 | */
|
28 | 33 |
|
29 | 34 | #include <memory>
|
30 | 35 |
|
31 | 36 | #include <mstd_type_traits>
|
| 37 | +#include <mstd_utility> // std::pair |
| 38 | +#include <mstd_iterator> // std::iterator_traits |
32 | 39 |
|
33 | 40 | #ifdef __CC_ARM
|
34 | 41 |
|
@@ -60,6 +67,19 @@ T *addressof(T &arg) noexcept
|
60 | 67 | return reinterpret_cast<T *>(const_cast<char *>(&reinterpret_cast<const volatile char &>(arg)));
|
61 | 68 | }
|
62 | 69 |
|
| 70 | +// [uninitialized.copy] - ARMCC has pre-C++11 uninitialized_copy |
| 71 | +template <class InputIterator, class Size, class ForwardIterator> |
| 72 | +ForwardIterator uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result) { |
| 73 | + for ( ; n > 0; ++result, (void) ++first, --n) { |
| 74 | + ::new (static_cast<void*>(addressof(*result))) |
| 75 | + typename std::iterator_traits<ForwardIterator>::value_type(*first); |
| 76 | + } |
| 77 | + |
| 78 | + return result; |
| 79 | +} |
| 80 | + |
| 81 | +// [uninitialized.fill] - ARMCC has pre-C++11 uninitialized_fill and uninitialized_fill_n |
| 82 | + |
63 | 83 | // [unique.ptr]
|
64 | 84 | namespace impl
|
65 | 85 | {
|
@@ -496,12 +516,97 @@ bool operator>=(nullptr_t, const unique_ptr<T, D> &x) noexcept
|
496 | 516 | #endif // __CC_ARM
|
497 | 517 |
|
498 | 518 | namespace mstd {
|
| 519 | + using std::align; |
499 | 520 | using std::allocator;
|
| 521 | + using std::addressof; |
| 522 | + |
| 523 | + // [uninitialized.construct.default] (C++17) |
| 524 | + template <class ForwardIterator, class Size> |
| 525 | + void uninitialized_default_construct(ForwardIterator first, ForwardIterator last) { |
| 526 | + for (; first != last; ++first) { |
| 527 | + ::new (static_cast<void*>(addressof(*first))) |
| 528 | + typename std::iterator_traits<ForwardIterator>::value_type; |
| 529 | + } |
| 530 | + } |
| 531 | + |
| 532 | + template <class ForwardIterator, class Size> |
| 533 | + ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n) { |
| 534 | + for (; n; ++first, --n) { |
| 535 | + ::new (static_cast<void*>(addressof(*first))) |
| 536 | + typename std::iterator_traits<ForwardIterator>::value_type; |
| 537 | + } |
| 538 | + |
| 539 | + return first; |
| 540 | + } |
| 541 | + |
| 542 | + // [uninitialized.construct.value] (C++17) |
| 543 | + template <class ForwardIterator, class Size> |
| 544 | + void uninitialized_value_construct(ForwardIterator first, ForwardIterator last) { |
| 545 | + for (; first != last; ++first) { |
| 546 | + ::new (static_cast<void*>(addressof(*first))) |
| 547 | + typename std::iterator_traits<ForwardIterator>::value_type(); |
| 548 | + } |
| 549 | + } |
| 550 | + |
| 551 | + template <class ForwardIterator, class Size> |
| 552 | + ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n) { |
| 553 | + for (; n; ++first, --n) { |
| 554 | + ::new (static_cast<void*>(addressof(*first))) |
| 555 | + typename std::iterator_traits<ForwardIterator>::value_type(); |
| 556 | + } |
| 557 | + |
| 558 | + return first; |
| 559 | + } |
| 560 | + |
| 561 | + // [uninitialized.move] (C++17) |
| 562 | + template <class InputIterator, class ForwardIterator> |
| 563 | + ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result) { |
| 564 | + for (; first != last; ++result, (void) ++first) { |
| 565 | + ::new (static_cast<void*>(addressof(*result))) |
| 566 | + typename std::iterator_traits<ForwardIterator>::value_type(move(*first)); |
| 567 | + } |
| 568 | + |
| 569 | + return result; |
| 570 | + } |
| 571 | + |
| 572 | + template <class InputIterator, class Size, class ForwardIterator> |
| 573 | + std::pair<InputIterator, ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result) { |
| 574 | + for ( ; n > 0; ++result, (void) ++first, --n) { |
| 575 | + ::new (static_cast<void*>(addressof(*result))) |
| 576 | + typename std::iterator_traits<ForwardIterator>::value_type(std::move(*first)); |
| 577 | + } |
| 578 | + |
| 579 | + return { first, result }; |
| 580 | + } |
| 581 | + |
500 | 582 | using std::uninitialized_copy;
|
| 583 | + using std::uninitialized_copy_n; |
501 | 584 | using std::uninitialized_fill;
|
502 | 585 | using std::uninitialized_fill_n;
|
503 |
| - using std::addressof; |
504 |
| - using std::align; |
| 586 | + |
| 587 | + // [specialized.destroy] (C++17) |
| 588 | + template <class T> |
| 589 | + void destroy_at(T *location) |
| 590 | + { |
| 591 | + location->~T(); |
| 592 | + } |
| 593 | + |
| 594 | + template <class ForwardIterator> |
| 595 | + void destroy(ForwardIterator first, ForwardIterator last) |
| 596 | + { |
| 597 | + for (; first != last; ++first) { |
| 598 | + destroy_at(addressof(*first)); |
| 599 | + } |
| 600 | + } |
| 601 | + |
| 602 | + template <class ForwardIterator, class Size> |
| 603 | + ForwardIterator destroy_n(ForwardIterator first, Size n) |
| 604 | + { |
| 605 | + for (; n > 0; (void)++first, --n) { |
| 606 | + destroy_at(addressof(*first)); |
| 607 | + } |
| 608 | + return first; |
| 609 | + } |
505 | 610 |
|
506 | 611 | using std::default_delete;
|
507 | 612 | using std::unique_ptr;
|
|
0 commit comments