Add more functions to ImmutableSortedVector

This commit is contained in:
Alexander Karatarakis 2017-03-29 17:32:22 -07:00
parent f1d4a4457e
commit ee75fe6330

View File

@ -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;
};