mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 19:43:33 +01:00
Add more functions to ImmutableSortedVector
This commit is contained in:
parent
f1d4a4457e
commit
ee75fe6330
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user