aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2016-12-22 16:43:47 -0800
committerAlexander Karatarakis <alkarata@microsoft.com>2017-01-05 14:30:52 -0800
commite5f60816cb6a786aa828aa2845522bb81c02cbe6 (patch)
tree5db56ac7d0557b6ee195c32b149308eae886d273 /toolsrc/include
parent64e1bf8de73d18c85776c4cce2f40281f3ebb253 (diff)
downloadvcpkg-e5f60816cb6a786aa828aa2845522bb81c02cbe6.tar.gz
vcpkg-e5f60816cb6a786aa828aa2845522bb81c02cbe6.zip
Introduce ImmutableSortedVector
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/ImmutableSortedVector.h48
-rw-r--r--toolsrc/include/vcpkg.h3
2 files changed, 50 insertions, 1 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;
+ };
+}
diff --git a/toolsrc/include/vcpkg.h b/toolsrc/include/vcpkg.h
index 75dc40b43..b1653d197 100644
--- a/toolsrc/include/vcpkg.h
+++ b/toolsrc/include/vcpkg.h
@@ -4,6 +4,7 @@
#include "BinaryParagraph.h"
#include "StatusParagraphs.h"
#include "vcpkg_paths.h"
+#include "ImmutableSortedVector.h"
namespace vcpkg
{
@@ -14,7 +15,7 @@ namespace vcpkg
struct StatusParagraph_and_associated_files
{
StatusParagraph pgh;
- std::vector<std::string> files;
+ ImmutableSortedVector<std::string> files;
};
std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db);