From e5f60816cb6a786aa828aa2845522bb81c02cbe6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 22 Dec 2016 16:43:47 -0800 Subject: Introduce ImmutableSortedVector --- toolsrc/include/ImmutableSortedVector.h | 48 +++++++++++++++++++++++++++++++++ toolsrc/include/vcpkg.h | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 toolsrc/include/ImmutableSortedVector.h (limited to 'toolsrc/include') 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 +#include + +// Add more forwarding functions to the delegate std::vector as needed. +namespace vcpkg +{ + template + class ImmutableSortedVector + { + public: + static ImmutableSortedVector create(std::vector 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::const_iterator begin() const + { + return this->delegate.cbegin(); + } + + typename std::vector::const_iterator end() const + { + return this->delegate.cend(); + } + + typename std::vector::const_iterator cbegin() const + { + return this->delegate.cbegin(); + } + + typename std::vector::const_iterator cend() const + { + return this->delegate.cend(); + } + + private: + std::vector 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 files; + ImmutableSortedVector files; }; std::vector get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db); -- cgit v1.2.3