diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-29 17:32:22 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-31 16:15:05 -0700 |
| commit | ee75fe6330d14401b06d74648b29afc161943d54 (patch) | |
| tree | 339134dc1833efcc7d70f8494b3ddb9e2468e8b9 | |
| parent | f1d4a4457ece7067bff16479b6e86d06770d3095 (diff) | |
| download | vcpkg-ee75fe6330d14401b06d74648b29afc161943d54.tar.gz vcpkg-ee75fe6330d14401b06d74648b29afc161943d54.zip | |
Add more functions to ImmutableSortedVector
| -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; }; |
