diff options
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/ImmutableSortedVector.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/toolsrc/include/ImmutableSortedVector.h b/toolsrc/include/ImmutableSortedVector.h index 681f9fd4d..0756068eb 100644 --- a/toolsrc/include/ImmutableSortedVector.h +++ b/toolsrc/include/ImmutableSortedVector.h @@ -9,6 +9,8 @@ namespace vcpkg template <class T> class ImmutableSortedVector { + typedef typename std::vector<T>::size_type size_type; + public: static ImmutableSortedVector<T> create(std::vector<T> vector) { @@ -22,6 +24,19 @@ namespace vcpkg return out; } + template <class Compare> + static ImmutableSortedVector<T> create(std::vector<T> vector, Compare comp) + { + ImmutableSortedVector<T> out; + out.delegate = std::move(vector); + if (!std::is_sorted(out.delegate.cbegin(), out.delegate.cend(), comp)) + { + std::sort(out.delegate.begin(), out.delegate.end(), comp); + } + + return out; + } + typename std::vector<T>::const_iterator begin() const { return this->delegate.cbegin(); @@ -42,6 +57,16 @@ namespace vcpkg return this->delegate.cend(); } + bool empty() const + { + return this->delegate.empty(); + } + + size_type size() const + { + return this->delegate.size(); + } + private: std::vector<T> delegate; }; |
