Introduce ImmutableSortedVector
ADD
include/ImmutableSortedVector.h
+#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;
+ };
+}

MODIFY
include/vcpkg.h
include/vcpkg.h
#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);

MODIFY
src/vcpkg.cpp
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));
}

MODIFY
vcpkgcommon/vcpkgcommon.vcxproj
vcpkgcommon/vcpkgcommon.vcxproj
</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" />

MODIFY
vcpkgcommon/vcpkgcommon.vcxproj.filters
vcpkgcommon/vcpkgcommon.vcxproj.filters
<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

Introduce ImmutableSortedVector