aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/ImmutableSortedVector.h
diff options
context:
space:
mode:
authorPatrick Bader <mail@patrickbader.eu>2017-01-06 19:09:17 +0100
committerPatrick Bader <mail@patrickbader.eu>2017-01-06 19:09:17 +0100
commit04f8da985c9acdd090055ad06bcf75eb20af1987 (patch)
tree76ae8c42d498f0c2d607c891eac50f41f06d1269 /toolsrc/include/ImmutableSortedVector.h
parent44c86f56db351da15e5a2b2fcca62656ab8cccbf (diff)
parentff10939203b7694f21d8e8e0464f092dff1b4eb0 (diff)
downloadvcpkg-04f8da985c9acdd090055ad06bcf75eb20af1987.tar.gz
vcpkg-04f8da985c9acdd090055ad06bcf75eb20af1987.zip
Merge branch 'master' of https://github.com/Microsoft/vcpkg
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;
+ };
+}