Add more functions to ImmutableSortedVector
MODIFY
include/ImmutableSortedVector.h
include/ImmutableSortedVector.h
@@ -9,6 +9,8 @@ namespace vcpkg
template <class T>
class ImmutableSortedVector
{
+ typedef typename std::vector<T>::size_type size_type;
+
public:
static ImmutableSortedVector<T> create(std::vector<T> vector)
{
@@ -22,6 +24,19 @@ namespace vcpkg
return out;
}
+ template <class Compare>
+ static ImmutableSortedVector<T> create(std::vector<T> vector, Compare comp)
+ {
+ ImmutableSortedVector<T> out;
+ out.delegate = std::move(vector);
+ if (!std::is_sorted(out.delegate.cbegin(), out.delegate.cend(), comp))
+ {
+ std::sort(out.delegate.begin(), out.delegate.end(), comp);
+ }
+
+ return out;
+ }
+
typename std::vector<T>::const_iterator begin() const
{
return this->delegate.cbegin();
@@ -42,6 +57,16 @@ namespace vcpkg
return this->delegate.cend();
}
+ bool empty() const
+ {
+ return this->delegate.empty();
+ }
+
+ size_type size() const
+ {
+ return this->delegate.size();
+ }
+
private:
std::vector<T> delegate;
};

Add more functions to ImmutableSortedVector