Changeset db05684 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:21Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2353857
Parents:
289c954a
git-author:
Dzejrou <dzejrou@…> (2018-04-11 21:07:02)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
Message:

cpp: added assign, front/back emplace and fixed bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/deque.hpp

    r289c954a rdb05684  
    425425                    fini_();
    426426
    427                 prepare_for_size_(other.size_);
    428                 init_();
    429427                copy_from_range_(other.begin(), other.end());
    430428
     
    444442                    fini_();
    445443
    446                 prepare_for_size_(init.size());
    447                 init_();
    448444                copy_from_range_(init.begin(), init.end());
    449445
     
    454450            void assign(InputIterator first, InputIterator last)
    455451            {
    456                 // TODO: implement
     452                copy_from_range_(first, last);
    457453            }
    458454
    459455            void assign(size_type n, const T& value)
    460456            {
    461                 // TODO: implement
     457                prepare_for_size_(n);
     458                init_();
     459                size_ = n;
     460
     461                auto it = begin();
     462                for (size_type i = size_type{}; i < n; ++i)
     463                    *it++ = value;
    462464            }
    463465
    464466            void assign(initializer_list<T> init)
    465467            {
    466                 // TODO: implement
     468                copy_from_range_(init.begin(), init.end());
    467469            }
    468470
     
    543545            size_type max_size() const noexcept
    544546            {
    545                 return allocator_traits<Allocator>::max_size(allocator_);
     547                return allocator_traits<allocator_type>::max_size(allocator_);
    546548            }
    547549
     
    643645            void emplace_front(Args&&... args)
    644646            {
    645                 // TODO: implement
     647                if (front_bucket_idx_ == 0)
     648                    add_new_bucket_front_();
     649
     650                allocator_traits<allocator_type>::construct(
     651                    allocator_,
     652                    &data_[front_bucket_][--front_bucket_idx_],
     653                    forward<Args>(args)...
     654                );
     655
     656                ++size_;
    646657            }
    647658
     
    649660            void emplace_back(Args&&... args)
    650661            {
    651                 // TODO: implement
     662                allocator_traits<allocator_type>::construct(
     663                    allocator_,
     664                    &data_[back_bucket_][back_bucket_idx_++],
     665                    forward<Args>(args)...
     666                );
     667
     668                ++size_;
     669
     670                if (back_bucket_idx_ >= bucket_size_)
     671                    add_new_bucket_back_();
    652672            }
    653673
     
    838858                    bucket_count_ = bucket_capacity_ = 2;
    839859                else if (size % bucket_size_ == 0)
    840                     bucket_count_ = bucket_capacity_ = size / bucket_size_ + 1;
     860                    bucket_count_ = bucket_capacity_ = size / bucket_size_ + 2;
    841861                else
    842862                    bucket_count_ = bucket_capacity_ = size / bucket_size_ + 2;
     
    844864                front_bucket_ = 0;
    845865                back_bucket_ = bucket_capacity_ - 1;
     866
     867                front_bucket_idx_ = bucket_size_;
     868                back_bucket_idx_ = size % bucket_size_;
    846869            }
    847870
     
    856879                while (first != last)
    857880                    *it++ = *first++;
    858 
    859                 // Remainder is the amount of elements in the last bucket.
    860                 back_bucket_idx_ = size_ % bucket_size_;
    861881            }
    862882
Note: See TracChangeset for help on using the changeset viewer.