diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2016-12-22 16:43:47 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-01-05 14:30:52 -0800 |
| commit | e5f60816cb6a786aa828aa2845522bb81c02cbe6 (patch) | |
| tree | 5db56ac7d0557b6ee195c32b149308eae886d273 /toolsrc/include/ImmutableSortedVector.h | |
| parent | 64e1bf8de73d18c85776c4cce2f40281f3ebb253 (diff) | |
| download | vcpkg-e5f60816cb6a786aa828aa2845522bb81c02cbe6.tar.gz vcpkg-e5f60816cb6a786aa828aa2845522bb81c02cbe6.zip | |
Introduce ImmutableSortedVector
Diffstat (limited to 'toolsrc/include/ImmutableSortedVector.h')
| -rw-r--r-- | toolsrc/include/ImmutableSortedVector.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/toolsrc/include/ImmutableSortedVector.h b/toolsrc/include/ImmutableSortedVector.h new file mode 100644 index 000000000..681f9fd4d --- /dev/null +++ b/toolsrc/include/ImmutableSortedVector.h @@ -0,0 +1,48 @@ +#pragma once + +#include <vector> +#include <algorithm> + +// Add more forwarding functions to the delegate std::vector as needed. +namespace vcpkg +{ + template <class T> + class ImmutableSortedVector + { + public: + static ImmutableSortedVector<T> create(std::vector<T> vector) + { + ImmutableSortedVector out; + out.delegate = std::move(vector); + if (!std::is_sorted(out.delegate.cbegin(), out.delegate.cend())) + { + std::sort(out.delegate.begin(), out.delegate.end()); + } + + return out; + } + + typename std::vector<T>::const_iterator begin() const + { + return this->delegate.cbegin(); + } + + typename std::vector<T>::const_iterator end() const + { + return this->delegate.cend(); + } + + typename std::vector<T>::const_iterator cbegin() const + { + return this->delegate.cbegin(); + } + + typename std::vector<T>::const_iterator cend() const + { + return this->delegate.cend(); + } + + private: + std::vector<T> delegate; + }; +} |
