rah
Functions
rah::action Namespace Reference

Functions

template<typename C , typename P = is_equal, typename = std ::enable_if_t<is_range<C>::value>>
auto && unique (C &&container, P &&pred={})
 Remove all but first successive values which are equals. More...
 
template<typename P = is_equal, typename = std ::enable_if_t<not is_range<P>::value>>
auto unique (P &&pred={})
 Remove all but first successuve values which are equals. More...
 
template<typename C , typename P >
auto && remove_if (C &&container, P &&pred)
 Keep only elements for which pred(elt) is false
. More...
 
template<typename P >
auto remove_if (P &&pred)
 Keep only elements for which pred(elt) is false
. More...
 
template<typename C , typename P = is_lesser, typename = std ::enable_if_t<is_range<C>::value>>
auto && sort (C &&container, P &&pred={})
 Sort a range in place, using the given predicate. More...
 
template<typename P = is_lesser, typename = std ::enable_if_t<not is_range<P>::value>>
auto sort (P &&pred={})
 Sort a range in place, using the given predicate. More...
 
template<typename C , typename URBG >
auto && shuffle (C &&container, URBG &&g)
 Reorders the elements in the given range such that each possible permutation of those elements has equal probability of appearance. More...
 
template<typename URBG >
auto shuffle (URBG &&g)
 Reorders the elements in the given range such that each possible permutation of those elements has equal probability of appearance. More...
 
template<typename R1 , typename V >
auto fill (R1 &&in, V &&value)
 Assigns the given value to the elements in the range [first, last) More...
 
template<typename V >
auto fill (V &&value)
 Assigns the given value to the elements in the range [first, last) More...
 
template<typename C , typename V >
auto && remove (C &&container, V &&value)
 Keep only elements not equal to value. More...
 
template<typename V >
auto remove (V &&value)
 Keep only elements not equal to value. More...
 

Function Documentation

◆ fill() [1/2]

template<typename R1 , typename V >
auto rah::action::fill ( R1 &&  in,
V &&  value 
)

Assigns the given value to the elements in the range [first, last)

std::vector<int> in{ 1, 2, 3 };
std::vector<int> out{ 0, 0, 0, 4, 5 };
// std::vector<int> out{ 0, 0 }; // Trigger an assert
assert(rah::make_iterator_range(rah::copy(in, out), end(out)) | rah::equal(std::initializer_list<int>({ 4, 5 })));
assert(out == (std::vector<int>{ 1, 2, 3, 4, 5 }));

◆ fill() [2/2]

template<typename V >
auto rah::action::fill ( V &&  value)

Assigns the given value to the elements in the range [first, last)

Remarks
pipeable syntax
std::vector<int> in{ 1, 2, 3 };
std::vector<int> out{ 0, 0, 0, 4, 5 };
auto iter = in | rah::copy(out);
assert((rah::make_iterator_range(iter, end(out)) | rah::equal(std::initializer_list<int>{ 4, 5 })));
assert(out == (std::vector<int>{ 1, 2, 3, 4, 5 }));

◆ remove() [1/2]

template<typename C , typename V >
auto&& rah::action::remove ( C &&  container,
V &&  value 
)

Keep only elements not equal to value.

Returns
reference to the container
std::vector<int> in{ 1, 2, 1, 3, 1 };
auto&& result = rah::action::remove(in, 1);
assert(&result == &in);
assert(in == std::vector<int>({ 2, 3 }));

◆ remove() [2/2]

template<typename V >
auto rah::action::remove ( V &&  value)

Keep only elements not equal to value.

Returns
reference to the container
Remarks
pipeable syntax
std::vector<int> in{ 1, 2, 1, 3, 1 };
auto&& result = in | rah::action::remove(1);
assert(&result == &in);
assert(in == std::vector<int>({ 2, 3 }));

◆ remove_if() [1/2]

template<typename C , typename P >
auto && rah::action::remove_if ( C &&  container,
P &&  pred 
)

Keep only elements for which pred(elt) is false
.

Returns
reference to the container
std::vector<int> in{ 1, 2, 3, 4, 5 };
auto&& result = rah::action::remove_if(in, [](auto a) {return a < 4; });
assert(&result == &in);
assert(in == std::vector<int>({ 4, 5 }));

◆ remove_if() [2/2]

template<typename P >
auto rah::action::remove_if ( P &&  pred)

Keep only elements for which pred(elt) is false
.

Returns
reference to the container
Remarks
pipeable syntax
std::vector<int> in{ 1, 2, 3, 4, 5 };
auto&& result = in | rah::action::remove_if([](int a) {return a < 4; });
assert(&result == &in);
assert(in == std::vector<int>({ 4, 5 }));

◆ shuffle() [1/2]

template<typename C , typename URBG >
auto && rah::action::shuffle ( C &&  container,
URBG &&  g 
)

Reorders the elements in the given range such that each possible permutation of those elements has equal probability of appearance.

Returns
reference to container
std::random_device rd;
std::mt19937 g(rd());
std::vector<int> in{ 1, 2, 3, 4, 5, 6 };
assert(&rah::action::shuffle(in, g) == &in);

◆ shuffle() [2/2]

template<typename URBG >
auto rah::action::shuffle ( URBG &&  g)

Reorders the elements in the given range such that each possible permutation of those elements has equal probability of appearance.

Returns
reference to container
Remarks
pipeable syntax
std::random_device rd;
std::mt19937 g(rd());
std::vector<int> in{ 1, 2, 3, 4, 5, 6 };
assert(&(in | rah::action::shuffle(g)) == &in);

◆ sort() [1/2]

template<typename C , typename P = is_lesser, typename = std ::enable_if_t<is_range<C>::value>>
auto && rah::action::sort ( C &&  container,
P &&  pred = {} 
)

Sort a range in place, using the given predicate.

Returns
reference to container
std::vector<int> in{ 2, 1, 5, 3, 4 };
auto&& result = rah::action::sort(in);
assert(&result == &in);
assert(in == std::vector<int>({ 1, 2, 3, 4, 5 }));
std::vector<int> in{ 2, 1, 5, 3, 4 };
auto&& result = rah::action::sort(in, [](auto a, auto b) {return a < b; });
assert(&result == &in);
assert(in == std::vector<int>({ 1, 2, 3, 4, 5 }));

◆ sort() [2/2]

template<typename P = is_lesser, typename = std ::enable_if_t<not is_range<P>::value>>
auto rah::action::sort ( P &&  pred = {})

Sort a range in place, using the given predicate.

Returns
reference to container
Remarks
pipeable syntax
std::vector<int> in{ 2, 1, 5, 3, 4 };
auto&& result = in | rah::action::sort();
assert(&result == &in);
assert(in == std::vector<int>({ 1, 2, 3, 4, 5 }));
std::vector<int> in{ 2, 1, 5, 3, 4 };
auto&& result = in | rah::action::sort([](auto a, auto b) {return a < b; });
assert(&result == &in);
assert(in == std::vector<int>({ 1, 2, 3, 4, 5 }));

◆ unique() [1/2]

template<typename C , typename P = is_equal, typename = std ::enable_if_t<is_range<C>::value>>
auto && rah::action::unique ( C &&  container,
P &&  pred = {} 
)

Remove all but first successive values which are equals.

Returns
Reference to container
std::vector<int> in{ 2, 1, 1, 1, 5, 3, 3, 4 };
auto&& result = rah::action::unique(in);
assert(&result == &in);
assert(in == std::vector<int>({ 2, 1, 5, 3, 4 }));
std::vector<int> in{ 2, 1, 1, 1, 5, 3, 3, 4 };
auto&& result = rah::action::unique(in, [](auto a, auto b) {return a == b; });
assert(&result == &in);
assert(in == std::vector<int>({ 2, 1, 5, 3, 4 }));

◆ unique() [2/2]

template<typename P = is_equal, typename = std ::enable_if_t<not is_range<P>::value>>
auto rah::action::unique ( P &&  pred = {})

Remove all but first successuve values which are equals.

Returns
Reference to container
Remarks
pipeable syntax
std::vector<int> in{ 2, 1, 1, 1, 5, 3, 3, 4 };
auto&& result = in | rah::action::unique();
assert(&result == &in);
assert(in == std::vector<int>({ 2, 1, 5, 3, 4 }));
std::vector<int> in{ 2, 1, 1, 1, 5, 3, 3, 4 };
auto&& result = in | rah::action::unique([](auto a, auto b) {return a == b; });
assert(&result == &in);
assert(in == std::vector<int>({ 2, 1, 5, 3, 4 }));