Changeset c06328da in mainline


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

cpp: added move assignment and comparison operator for vector

File:
1 edited

Legend:

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

    rbfa86e5 rc06328da  
    11/*
    2  * Copyright (c) 2017 Jaroslav Jindrak
     2 * Copyright (c) 2018 Jaroslav Jindrak
    33 * All rights reserved.
    44 *
     
    153153                         allocator_traits<Allocator>::is_always_equal::value)
    154154            {
    155                 // TODO: implement
     155                if (data_)
     156                    allocator_.deallocate(data_, capacity_);
     157
     158                // TODO: test this
     159                data_ = other.data_;
     160                size_ = other.size_;
     161                capacity_ = other.capacity_;
     162                allocator_ = move(other.allocator_);
     163
     164                other.data_ = nullptr;
     165                other.size_ = size_type{};
     166                other.capacity_ = size_type{};
     167                other.allocator_ = allocator_type{};
    156168                return *this;
    157169            }
     
    370382            }
    371383
    372             // TODO: assert CopyInstertable etc with enable_if!
    373384            void push_back(const T& x)
    374385            {
     
    584595    bool operator==(const vector<T, Alloc>& lhs, const vector<T, Alloc>& rhs)
    585596    {
    586         // TODO: implement
    587         return false;
     597        if (lhs.size() != rhs.size())
     598            return false;
     599
     600        for (decltype(lhs.size()) i = 0; i < lhs.size(); ++i)
     601        {
     602            if (lhs[i] != rhs[i])
     603                return false;
     604        }
     605
     606        return true;
    588607    }
    589608
     
    591610    bool operator<(const vector<T, Alloc>& lhs, const vector<T, Alloc>& rhs)
    592611    {
    593         // TODO: implement
    594         return false;
     612        auto min_size = min(lhs.size(), rhs.size());
     613        for (decltype(lhs.size()) i = 0; i < min_size; ++i)
     614        {
     615            if (lhs[i] >= rhs[i])
     616                return false;
     617        }
     618
     619        if (lhs.size() == rhs.size())
     620            return true;
     621        else
     622            return lhs.size() < rhs.size();
    595623    }
    596624
     
    604632    bool operator>(const vector<T, Alloc>& lhs, const vector<T, Alloc>& rhs)
    605633    {
    606         // TODO: implement
    607         return false;
     634        return rhs < lhs;
    608635    }
    609636
     
    611638    bool operator>=(const vector<T, Alloc>& lhs, const vector<T, Alloc>& rhs)
    612639    {
    613         // TODO: implement
    614         return false;
     640        return !(lhs < rhs);
    615641    }
    616642
     
    618644    bool operator<=(const vector<T, Alloc>& lhs, const vector<T, Alloc>& rhs)
    619645    {
    620         // TODO: implement
    621         return false;
     646        return !(rhs < lhs);
    622647    }
    623648
     
    631656        lhs.swap(rhs);
    632657    }
     658
     659    /**
     660     * 23.3.7, class vector<bool>:
     661     */
     662
     663    // TODO: implement
    633664}
    634665
Note: See TracChangeset for help on using the changeset viewer.