Skip to content

Commit

Permalink
Array unique and sort with comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsmirnov committed Dec 19, 2016
1 parent be0e1ca commit 15d45e7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions array.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GenericArray : public ReprProxy<GenericArray<T>>, public std::vector<T> {
using Base::end;
using Base::insert;
using Base::clear;
using Base::erase;

template<typename F, typename ...Args>
static GenericArray<T> randomf(size_t size, F func, const Args& ... args);
Expand All @@ -57,6 +58,15 @@ class GenericArray : public ReprProxy<GenericArray<T>>, public std::vector<T> {
GenericArray<T>& sort();
GenericArray<T> sorted() const;

template<typename Comp>
GenericArray<T>& sort(Comp&& comp) const;
template<typename Comp>
GenericArray<T> sorted(Comp&& comp);

GenericArray<T>& unique();
GenericArray<T> uniqued() const;


GenericArray<T> inverse() const;

template<typename Integer>
Expand Down Expand Up @@ -210,6 +220,34 @@ GenericArray<T> GenericArray<T>::sorted() const {
return res;
}

template<typename T>
template<typename Comp>
GenericArray<T>& GenericArray<T>::sort(Comp&& comp) const {
std::sort(begin(), end(), comp);
return *this;
}

template<typename T>
template<typename Comp>
GenericArray<T> GenericArray<T>::sorted(Comp&& comp) {
auto res = *this;
res.sort(comp);
return res;
}

template<typename T>
GenericArray<T>& GenericArray<T>::unique() {
erase(std::unique(begin(), end()), end());
return *this;
}

template<typename T>
GenericArray<T> GenericArray<T>::uniqued() const {
auto res = *this;
res.unique();
return res;
}

template<typename T>
GenericArray<T> GenericArray<T>::inverse() const {
static_assert(
Expand Down

0 comments on commit 15d45e7

Please sign in to comment.