aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/ImmutableSortedVector.h
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-02-08 15:12:28 -0800
committerGitHub <noreply@github.com>2017-02-08 15:12:28 -0800
commit7ddae17e2f520e83d25f78c078bf8b8a58fff447 (patch)
tree87e2fc5c57a685367ec051b1efbdeb5d3ab43f4d /toolsrc/include/ImmutableSortedVector.h
parent5e588ddb5be9e6e27cebcc3be2e1a27f3ca83a50 (diff)
parenta9f7fc6e90feaad50c1221ef9bd56e2620302215 (diff)
downloadvcpkg-7ddae17e2f520e83d25f78c078bf8b8a58fff447.tar.gz
vcpkg-7ddae17e2f520e83d25f78c078bf8b8a58fff447.zip
Merge branch 'master' into master
Diffstat (limited to 'toolsrc/include/ImmutableSortedVector.h')
-rw-r--r--toolsrc/include/ImmutableSortedVector.h48
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;
+ };
+}