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 | |
| parent | 64e1bf8de73d18c85776c4cce2f40281f3ebb253 (diff) | |
| download | vcpkg-e5f60816cb6a786aa828aa2845522bb81c02cbe6.tar.gz vcpkg-e5f60816cb6a786aa828aa2845522bb81c02cbe6.zip | |
Introduce ImmutableSortedVector
| -rw-r--r-- | toolsrc/include/ImmutableSortedVector.h | 48 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg.h | 3 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/vcpkgcommon/vcpkgcommon.vcxproj | 1 | ||||
| -rw-r--r-- | toolsrc/vcpkgcommon/vcpkgcommon.vcxproj.filters | 3 |
5 files changed, 55 insertions, 2 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); diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 4748aeb54..eb2184ccb 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -204,7 +204,7 @@ std::vector<StatusParagraph_and_associated_files> vcpkg::get_installed_files(con } ), installed_files_of_current_pgh.end()); - StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; + StatusParagraph_and_associated_files pgh_and_files = {*pgh, ImmutableSortedVector<std::string>::create(std::move(installed_files_of_current_pgh))}; installed_files.push_back(std::move(pgh_and_files)); } diff --git a/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj b/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj index 218a826ad..c0d108602 100644 --- a/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj +++ b/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj @@ -128,6 +128,7 @@ </ItemGroup> <ItemGroup> <ClInclude Include="..\include\expected.h" /> + <ClInclude Include="..\include\ImmutableSortedVector.h" /> <ClInclude Include="..\include\opt_bool.h" /> <ClInclude Include="..\include\Stopwatch.h" /> <ClInclude Include="..\include\vcpkg_Checks.h" /> diff --git a/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj.filters b/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj.filters index 4d40bfbe2..bba605c54 100644 --- a/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj.filters +++ b/toolsrc/vcpkgcommon/vcpkgcommon.vcxproj.filters @@ -62,5 +62,8 @@ <ClInclude Include="..\include\Stopwatch.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\include\ImmutableSortedVector.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file |
