52template <
typename Callable>
53constexpr auto repeat(std::size_t N, Callable func)
noexcept(
noexcept(func()))
55 for (std::size_t I = 0; I != N; ++I) {
67template <
typename Container,
typename Elem>
68constexpr auto erase(Container& c,
const Elem& val)
noexcept(
69 noexcept(c.erase(std::remove(c.begin(), c.end(), val), c.end()))) ->
void {
70 c.erase(std::remove(c.begin(), c.end(), val), c.end());
80template <
typename Container,
typename UnaryPredicate>
81constexpr auto erase_if(Container& c, UnaryPredicate p)
noexcept(
82 noexcept(c.erase(std::remove_if(c.begin(), c.end(), std::ref(p)), c.end())))
84 c.erase(std::remove_if(c.begin(), c.end(), std::ref(p)), c.end());
93template <
typename Obj>
95 const Obj& b)
noexcept(
noexcept(
a < b))
97 return not (
a < b) and not (b <
a);
105template <
typename Obj,
typename Compare>
107 Compare comp)
noexcept(
noexcept(comp(
a,
110 return not comp(
a, b) and not comp(b,
a);
122template <
typename Compare =
void,
typename Obj =
void>
126 noexcept(
noexcept(
equals(
a, b, comp))) ->
bool {
131template <
typename Obj>
134 noexcept(
noexcept(
equals(
a, b))) ->
bool {
139template <
typename Compare>
141 template <
typename Obj>
144 noexcept(
noexcept(
equals(
a, b, comp))) ->
bool {
151 template <
typename Obj>
153 noexcept(
noexcept(
equals(
a, b))) ->
bool {
161template <
typename InputIt,
typename T>
164 for (; first != last; ++first) {
165 init = std::move(init) + *first;
173template <
class InputIt,
class T,
class BinaryOperation>
175 BinaryOperation op) -> T {
176 for (; first != last; ++first) {
177 init = op(std::move(init), *first);
193template <
typename InputIt>
199 auto init = *first++;
215template <
typename InputIt,
typename BinaryOperation>
222 auto init = *first++;
236template <
typename Range>
240 auto first = begin(r);
245 auto init = *first++;
249template <
typename InputIt,
typename EndIt,
typename OutputIt,
typename T,
250 typename BinaryAccumulation,
typename UnaryTransform>
252 OutputIt d_first, T init,
253 BinaryAccumulation accum,
254 UnaryTransform proj) -> OutputIt {
255 while (first != last) {
263template <
typename InputIt,
typename BinaryAccumulation,
264 typename BinaryTransform>
266adjacent_reduce(InputIt begin, InputIt begin1, InputIt end,
267 BinaryAccumulation acc, BinaryTransform op) {}
269template <
typename InputIt,
typename BinaryTransform>
270KBLIB_NODISCARD constexpr auto adjacent_transform(InputIt begin, InputIt begin1,
272 BinaryTransform op) {}
274template <
typename InputIt,
typename BinaryAccumulation,
275 typename BinaryTransform>
277adjacent_inclusive_scan(InputIt begin, InputIt begin1, InputIt end,
278 BinaryAccumulation acc, BinaryTransform op) {}
289template <
typename ForwardIt,
typename EndIt,
typename Elem>
291 ForwardIt begin, EndIt end,
292 const Elem& value)
noexcept(
noexcept(*begin == value)) -> ForwardIt {
293 while (begin != end and *begin != value) {
308template <
typename ForwardIt,
typename EndIt,
typename Elem,
typename Comp>
310 ForwardIt begin, EndIt end,
const Elem& value,
311 Comp&& comp)
noexcept(
noexcept(comp(*begin, value))) -> ForwardIt {
312 while (begin != end and not
equals(*begin, value, comp)) {
326template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
328 ForwardIt begin, EndIt end,
329 UnaryPredicate&& pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
345template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
347 ForwardIt begin, EndIt end,
348 UnaryPredicate&& pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
365template <
typename ForwardIt,
typename EndIt,
typename Elem>
367 ForwardIt begin, EndIt end,
368 const Elem& value)
noexcept(
noexcept(*begin == value)) -> ForwardIt {
375 if (new_result == end) {
395template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
397 ForwardIt begin, EndIt end,
398 UnaryPredicate pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
406 if (new_result == end) {
426template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
428 ForwardIt begin, EndIt end,
429 UnaryPredicate pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
437 if (new_result == end) {
457template <
typename ForwardIt,
typename EndIt,
typename Elem>
459 ForwardIt begin, EndIt end,
460 const Elem& value)
noexcept(
noexcept(*begin == value)) ->
size_t {
473template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
475 ForwardIt begin, EndIt end,
476 UnaryPredicate pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
489template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
491 ForwardIt begin, EndIt end,
492 UnaryPredicate pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
509template <
typename ForwardIt,
typename EndIt,
typename Elem>
511 ForwardIt begin, EndIt end,
512 const Elem& value)
noexcept(
noexcept(*begin == value)) ->
size_t {
524template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
526 ForwardIt begin, EndIt end,
527 UnaryPredicate pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
540template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
542 ForwardIt begin, EndIt end,
543 UnaryPredicate pred)
noexcept(
noexcept(
kblib::invoke(pred, *begin)))
557template <
typename Container,
typename T>
559find_in(
const Container& c,
const T& value)
noexcept(
560 noexcept(*std::declval<iterator_type_for_t<const Container>&>() == value))
567template<
typename ExecutionPolicy,
typename Container,
typename T>
569 const Container& c,
const T& v) ->
size_t {
584template <
typename Container,
typename UnaryPredicate>
590 const Container>&>())))
606template <
typename Container,
typename UnaryPredicate>
612 const Container>&>())))
619template<
typename ExecutionPolicy,
typename Container,
typename UnaryPredicate>
622 UnaryPredicate p) ->
size_t {
623 return std::find_if(policy, std::begin(c), std::end(c), p) - std::begin(c);
625template<
typename ExecutionPolicy,
typename Container,
typename UnaryPredicate>
628 UnaryPredicate p) ->
size_t {
643template <
typename Container,
typename T>
646 noexcept(*std::declval<iterator_type_for_t<const Container>&>() == value))
663template <
typename Container,
typename UnaryPredicate>
669 const Container>&>())))
685template <
typename Container,
typename UnaryPredicate>
691 const Container>&>())))
699template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
700 typename BinaryPredicate = std::equal_to<>>
702 InputIt2 begin2, BinaryPredicate cmp)
706 decltype(*begin2)>::value,
707 std::pair<InputIt1, InputIt2>> {
708 while (begin1 != end1) {
710 return std::make_pair(begin1, begin2);
713 return std::make_pair(begin1, begin2);
715template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
716 typename EndIt2,
typename BinaryPredicate = std::equal_to<>>
718 InputIt2 begin2, EndIt2 end2,
723 decltype(*begin2)>::value,
724 std::pair<InputIt1, InputIt2>> {
725 while (begin1 != end1 and begin2 != end2) {
727 return std::make_pair(begin1, begin2);
730 return std::make_pair(begin1, begin2);
736template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
737 typename EndIt2,
typename BinaryPred>
739 InputIt2 begin2, EndIt2 end2,
742 (is_input_iterator_v<InputIt1> and is_input_iterator_v<InputIt2>)
744 InputIt1> and is_random_access_iterator_v<InputIt2>),
746 while (begin1 != end1 and begin2 != end2) {
751 return begin2 == end2;
757template <
typename RandomAccessIt1,
typename RandomAccessIt2,
758 typename BinaryPred = std::equal_to<>>
760 RandomAccessIt1 end1,
761 RandomAccessIt2 begin2,
762 RandomAccessIt2 end2,
763 BinaryPred pred = {})
766 RandomAccessIt1> and is_random_access_iterator_v<RandomAccessIt2>,
768 if (end2 - begin2 > end1 - begin1) {
771 auto N = end2 - begin2;
779template <
typename BidirIt1,
typename BidirIt2,
780 typename BinaryPred = std::equal_to<>>
782 BidirIt2 begin2, BidirIt2 end2,
783 BinaryPred pred = {})
785 (is_bidirectional_iterator_v<BidirIt1>
786 and is_bidirectional_iterator_v<BidirIt2>)
788 BidirIt1> and is_random_access_iterator_v<BidirIt2>),
790 while (begin1 != end1 and begin2 != end2) {
795 return begin2 == end2;
801template <
typename RandomAccessIt1,
typename RandomAccessIt2,
802 typename BinaryPred = std::equal_to<>>
804 RandomAccessIt1 end1,
805 RandomAccessIt2 begin2,
806 RandomAccessIt2 end2,
807 BinaryPred pred = {})
810 RandomAccessIt1> and is_random_access_iterator_v<RandomAccessIt2>,
812 if (end2 - begin2 > end1 - begin1) {
815 auto N = end2 - begin2;
820template <
typename InputIt,
typename EndIt,
typename T,
typename UnaryTransform>
825 for (; begin != end; ++begin) {
826 auto cur = op(*begin);
833template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
typename T,
834 typename BinaryTransform>
836 InputIt2 begin2, T def,
841 for (; begin1 != end1; ++begin1, ++begin2) {
842 auto cur = op(*begin1, *begin2);
849template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
850 typename EndIt2,
typename T,
typename BinaryTransform>
852 InputIt2 begin2, EndIt2 end2, T def,
857 for (; begin1 != end1 and begin2 != end2; ++begin1, ++begin2) {
858 auto cur = op(*begin1, *begin2);
866template <
typename InputIt,
typename EndIt,
typename T,
typename UnaryTransform,
867 typename UnaryPredicate>
872 for (; begin != end; ++begin) {
879template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
typename T,
880 typename BinaryTransform,
typename BinaryPredicate>
882 InputIt2 begin2, T def,
887 decltype(op(*begin1, *begin2))> {
888 for (; begin1 != end1; ++begin1, ++begin2) {
889 if (ch(*begin1, *begin2)) {
890 return op(*begin1, *begin2);
895template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
896 typename EndIt2,
typename T,
typename BinaryTransform,
897 typename BinaryPredicate>
899 InputIt2 begin2, EndIt2 end2,
900 T def, BinaryTransform op,
904 decltype(op(*begin1, *begin2))> {
905 for (; begin1 != end1 and begin2 != end2; ++begin1, ++begin2) {
906 if (ch(*begin1, *begin2)) {
907 return op(*begin1, *begin2);
919template <
typename InputIt,
typename EndIt,
typename T,
typename UnaryTransform>
924 for (; begin != end; ++begin) {
925 auto cur = op(*begin);
932template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
typename T,
933 typename BinaryTransform>
935 InputIt2 begin2, T def,
940 for (; begin1 != end1; ++begin1, ++begin2) {
941 auto cur = op(*begin1, *begin2);
948template <
typename InputIt1,
typename EndIt1,
typename InputIt2,
949 typename EndIt2,
typename T,
typename BinaryTransform>
951 InputIt2 begin2, EndIt2 end2,
952 T def, BinaryTransform op)
956 for (; begin1 != end1 and begin2 != end2; ++begin1, ++begin2) {
957 auto cur = op(*begin1, *begin2);
969template <
typename InputIt,
typename UnaryPredicate>
973 for (; begin != end; ++begin) {
983template <
typename Range,
typename UnaryPredicate>
986 for (
auto&& el : std::forward<Range>(rng)) {
987 if (not
kblib::invoke(pred,
static_cast<decltype(el)
>(el))) {
996template <
typename InputIt,
typename UnaryPredicate>
1000 for (; begin != end; ++begin) {
1010template <
typename Range,
typename UnaryPredicate>
1013 for (
auto&& el : std::forward<Range>(rng)) {
1023template <
typename InputIt,
typename UnaryPredicate>
1025 UnaryPredicate pred)
1027 for (; begin != end; ++begin) {
1037template <
typename Range,
typename UnaryPredicate>
1040 for (
auto&& el : std::forward<Range>(rng)) {
1051template <
typename InputIt,
typename Value>
1053 InputIt begin, InputIt end,
1054 const Value& val)
noexcept(
noexcept(*begin == val))
1056 return kblib::any_of(begin, end, [&](
const auto&
e) {
return e == val; });
1062template <
typename Set,
typename Value>
1066 val)
noexcept(
noexcept(*std::declval<iterator_type_for_t<const Set>&>()
1072 [&](
const auto&
e) {
return e == val; });
1075template <
typename InputIt1,
typename InputIt2>
1077 InputIt2 n_begin, InputIt2 n_end)
1086template <
typename InputIt,
typename Range2>
1097template <
typename Range1,
typename Range2>
1104 begin(haystack), end(haystack),
1108template <
typename ForwardIt,
typename EndIt,
typename Compare = std::less<>>
1109constexpr auto max_element(ForwardIt first, EndIt last, Compare comp = {})
1111 if (first == last) {
1115 ForwardIt largest = first;
1117 for (; first != last; ++first) {
1118 if (comp(*largest, *first)) {
1144template <
typename SequenceContainer,
typename Comp = std::less<>,
typename It,
1145 enable_if_t<is_linear_container_v<SequenceContainer>,
int> = 0>
1147 std::size_t count, Comp cmp = {})
1148 -> SequenceContainer {
1151 assert(first + count <= last);
1152 SequenceContainer c{first, first + count};
1154 auto& min_v = *std::min_element(begin(c), end(c), cmp);
1178template <
typename SetlikeContainer,
typename Comp = std::less<>,
typename It,
1179 enable_if_t<is_setlike_v<SetlikeContainer>,
int> = 0>
1181 std::size_t count, Comp cmp = {})
1182 -> SetlikeContainer {
1183 auto temp = get_max_n_old<std::vector<key_type_setlike_t<SetlikeContainer>>>(
1184 first, last, count, cmp);
1185 return SetlikeContainer{std::make_move_iterator(temp.begin()),
1186 std::make_move_iterator(temp.end())};
1201template <
typename SequenceContainer,
typename Comp = std::less<>,
typename It,
1202 enable_if_t<is_linear_container_v<SequenceContainer>,
int> = 0>
1204 Comp cmp = {}) -> SequenceContainer {
1207 SequenceContainer c(count);
1208 std::partial_sort_copy(first, last, begin(c), end(c),
1209 [&](
auto&&
a,
auto&& b) ->
decltype(
auto) {
1211 std::forward<
decltype(b)>(b),
1212 std::forward<
decltype(
a)>(
a));
1228template <
typename SetlikeContainer,
typename Comp = std::less<>,
typename It,
1229 enable_if_t<is_setlike_v<SetlikeContainer>,
int> = 0>
1231 Comp cmp = {}) -> SetlikeContainer {
1232 auto temp = get_max_n<std::vector<key_type_setlike_t<SetlikeContainer>>>(
1233 first, last, count, cmp);
1234 return SetlikeContainer{std::make_move_iterator(temp.begin()),
1235 std::make_move_iterator(temp.end())};
1255template <
typename Comp = std::less<>,
typename InputIt,
typename OutputIt,
1256 typename Elem =
typename std::iterator_traits<InputIt>::value_type>
1257constexpr auto get_max_n(InputIt first, InputIt last, OutputIt d_begin,
1258 std::size_t count, Comp cmp = {})
1261 auto temp = get_max_n<std::vector<Elem>>(first, last, count, cmp);
1262 return std::move(temp.begin(), temp.end(), d_begin);
1278template <
typename ForwardIt,
typename EndIt,
typename ForwardIt2,
1279 typename BinaryFunction>
1280constexpr auto for_each(ForwardIt first, EndIt last, ForwardIt2 second,
1281 BinaryFunction f) -> BinaryFunction {
1282 for (; first != last; (void)++first, (
void)++second) {
1285 return std::move(f);
1299template <
typename ForwardIt,
typename ForwardIt2,
typename Size,
1300 typename BinaryFunction>
1301constexpr auto for_each_n(ForwardIt first, Size n, ForwardIt2 second,
1303 -> std::pair<ForwardIt, ForwardIt2> {
1304 for (Size i = 0; i < n; (void)++first, (
void)++second, (void)++i) {
1307 return {first, second};
1321template <
typename InputIt,
typename EndIt,
typename OutputIt>
1322constexpr auto copy(InputIt first, EndIt last, OutputIt out) -> OutputIt {
1323 while (first != last) {
1341template <
typename InputIt,
typename EndIt,
typename OutputIt,
1342 typename UnaryPredicate>
1343constexpr auto copy_if(InputIt first, EndIt last, OutputIt out,
1344 UnaryPredicate pred) -> OutputIt {
1345 while (first != last) {
1364template <
typename InputIt,
typename Size,
typename OutputIt>
1365constexpr auto copy_n(InputIt first, Size count, OutputIt out) -> OutputIt {
1366 for (Size i = 0; i < count; ++i) {
1384template <
typename InputIt,
typename Size,
typename OutputIt,
1385 typename UnaryPredicate>
1386constexpr auto copy_n_if(InputIt first, Size count, OutputIt out,
1387 UnaryPredicate pred) -> OutputIt {
1388 for (Size i = 0; i < count; ++i) {
1411template <
typename InputIt,
typename EndIt,
typename OutputIt,
1412 typename UnaryPredicate,
typename T>
1414 UnaryPredicate pred,
const T& new_value)
1416 while (first != last) {
1442template <
typename InputIt,
typename Size,
typename OutputIt,
1443 typename UnaryPredicate,
typename T>
1445 UnaryPredicate pred,
const T& new_value)
1447 for (Size i = 0; i < count; ++i) {
1460template <
typename ForwardIt1,
typename ForwardIt2,
typename ForwardIt3,
1461 typename OutputIt,
typename BinaryPredicate = std::equal_to<>>
1463 ForwardIt2 n_begin, ForwardIt2 n_end,
1464 ForwardIt3 r_begin, ForwardIt3 r_end,
1466 BinaryPredicate Compare = {}) -> OutputIt {
1467 if (n_begin == n_end) {
1468 return copy(h_begin, h_end, d_begin);
1470 const auto needle_length = std::distance(n_begin, n_end);
1471 while (h_begin != h_end) {
1473 = std::search(h_begin, h_end, n_begin, n_end, Compare);
1476 if (h_begin != h_end) {
1477 d_begin =
copy(r_begin, r_end, d_begin);
1478 std::advance(h_begin, needle_length);
1485template <
typename Haystack,
typename Needle,
typename Replacement,
1486 typename OutputIt,
typename BinaryPredicate = std::equal_to<>>
1488 Replacement&& replacement, OutputIt d_begin,
1489 BinaryPredicate compare = {}) {
1493 begin(needle), end(needle),
1494 begin(replacement), end(replacement),
1508template <
class ForwardIt>
1509constexpr auto rotate(ForwardIt first, ForwardIt n_first,
1510 ForwardIt last)
noexcept(
noexcept(
swap(*first, *first)))
1512 if (first == n_first)
1514 if (n_first == last)
1517 ForwardIt read = n_first;
1518 ForwardIt write = first;
1519 ForwardIt next_read = first;
1521 while (read != last) {
1522 if (write == next_read)
1526 swap(*(write++), *(read++));
1544template <
typename OutputIt,
typename EndIt,
typename Generator>
1546 Generator g)
noexcept(
noexcept(*++first = g()))
1548 while (first != last) {
1564template <
typename OutputIt,
typename Size,
typename Generator>
1566 Generator g)
noexcept(
noexcept(*first++ = g()))
1568 for (Size i = 0; i < count; i++) {
1574template <
typename ForwardIt,
typename T>
1575constexpr auto iota(ForwardIt first, ForwardIt last, T value)
noexcept(
1576 noexcept(*first++ = value) and
noexcept(++value)) ->
void {
1577 while (first != last) {
1586template <
typename ForwardIt,
typename T,
typename UnaryOperation>
1588 ForwardIt first, ForwardIt last, T value,
1589 UnaryOperation unary_op
1590 )
noexcept(
noexcept(*first++ = value)
1595 while (first != last) {
1602template <
typename InputIt,
typename EndIt,
typename... Params>
1604 InputIt first, EndIt last, Params&&... params
1606 std::forward<Params>(params)...)))
1609 while (first != last) {
1630template <
typename InputIt,
typename EndIt,
typename OutputIt,
1631 typename UnaryOperation>
1632constexpr auto transform(InputIt first, EndIt last, OutputIt d_first,
1633 UnaryOperation unary_op) -> OutputIt {
1634 while (first != last) {
1657template <
typename InputIt,
typename EndIt,
typename InputIt2,
1658 typename OutputIt,
typename BinaryOperation>
1659constexpr auto transform(InputIt first, EndIt last, InputIt first2,
1660 OutputIt d_first, BinaryOperation binary_op)
1662 while (first != last) {
1688template <
typename InputIt,
typename EndIt,
typename OutputIt,
1689 typename UnaryPredicate,
typename UnaryOperation>
1691 UnaryPredicate pred, UnaryOperation unary_op)
1693 while (first != last) {
1702namespace detail_algorithm {
1713 template <
class ForwardIt>
1715 ForwardIt first, ForwardIt n_first,
1716 ForwardIt last)
noexcept(
noexcept(*first = std::move(*first))) ->
void {
1717 if (first == n_first or n_first == last)
1720 ForwardIt read = n_first;
1721 ForwardIt write = first;
1723 while (read != last) {
1724 *(write++) = std::move(*(read++));
This file provides some iterators, ranges, iterator/range adapters, and operations that can be perfor...
constexpr auto shift_backward(ForwardIt first, ForwardIt n_first, ForwardIt last) noexcept(noexcept(*first=std::move(*first))) -> void
Implementation function for insertion_sort_copy. Like std::move(begin, end, d_begin) but using the in...
constexpr auto call_each(InputIt first, EndIt last, Params &&... params) noexcept(noexcept(kblib::invoke(*first++, std::forward< Params >(params)...))) -> InputIt
constexpr auto contains(const Set &set, const Value &val) noexcept(noexcept(*std::declval< iterator_type_for_t< const Set > & >()==val)) -> enable_if_t< is_iterable< Set >::value, bool >
Determine if a range contains a value.
constexpr auto find_last_in(const Container &c, const T &value) noexcept(noexcept(*std::declval< iterator_type_for_t< const Container > & >()==value)) -> size_t
Find the last element in c equal to v and return the position.
constexpr auto contains(InputIt begin, InputIt end, const Value &val) noexcept(noexcept(*begin==val)) -> enable_if_t< is_input_iterator< InputIt >::value, bool >
Determine if a range contains a value.
constexpr auto get_max_n(InputIt first, InputIt last, OutputIt d_begin, std::size_t count, Comp cmp={}) -> return_assert_t< is_output_iterator_for< OutputIt, Elem >::value, OutputIt >
Copies the count greatest elements according to cmp of the range [first, last) to the range beginning...
constexpr auto transform_if(InputIt first, EndIt last, OutputIt d_first, UnaryPredicate pred, UnaryOperation unary_op) -> OutputIt
transform applies the given function to a range and stores the result in another range,...
constexpr auto exchange(T &obj, U &&new_value) -> T
constexpr auto accumulate(InputIt first, InputIt last, T init, BinaryOperation op) -> T
A constexpr version of std::accumulate.
constexpr auto any_of(Range &&rng, UnaryPredicate pred) -> enable_if_t< is_iterable< Range >::value, bool >
Determine if pred is true for every element of the range.
constexpr auto find_last_if_not(ForwardIt begin, EndIt end, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> ForwardIt
Searches a range for the last element on which a predicate returns false. It also allows for a sentin...
constexpr auto equals(const Obj &a, const Obj &b, Compare comp) noexcept(noexcept(comp(a, b))) -> bool
Synthesize an equivalence relation from comp.
constexpr auto a(const std::initializer_list< T > &a) -> auto
Index an array literal without naming its type.
constexpr auto first_result(InputIt1 begin1, EndIt1 end1, InputIt2 begin2, EndIt2 end2, T def, BinaryTransform op) -> enable_if_t< is_input_iterator< InputIt1 >::value and is_input_iterator< InputIt2 >::value, std::decay_t< decltype(op(*begin1, *begin2))> >
constexpr auto any_of(InputIt begin, InputIt end, UnaryPredicate pred) -> enable_if_t< is_input_iterator< InputIt >::value, bool >
Determine if pred is true for at least one element of the range.
constexpr auto generate(OutputIt first, EndIt last, Generator g) noexcept(noexcept(*++first=g())) -> OutputIt
Like std::generate except that it returns the output iterator at the end. It also allows for a sentin...
typename std::enable_if< B, T >::type enable_if_t
constexpr auto all_of(Range &&rng, UnaryPredicate pred) -> enable_if_t< is_iterable< Range >::value, bool >
Determine if pred is true for every element of the range.
constexpr auto replace_copy_if(InputIt first, EndIt last, OutputIt out, UnaryPredicate pred, const T &new_value) -> OutputIt
Copies an input range, but every element for which pred is true is replaced by new_value....
constexpr auto first_result_if(InputIt1 begin1, EndIt1 end1, InputIt2 begin2, EndIt2 end2, T def, BinaryTransform op, BinaryPredicate ch) -> enable_if_t< is_input_iterator< InputIt1 >::value and is_input_iterator< InputIt2 >::value, decltype(op(*begin1, *begin2))>
constexpr auto copy_n(InputIt first, Size count, OutputIt out) -> OutputIt
Copies all elements of [first, std::advance(first, n)) to out.
constexpr auto generate_n(OutputIt first, Size count, Generator g) noexcept(noexcept(*first++=g())) -> OutputIt
Like std::generate_n except that it is constexpr.
constexpr auto find_if(ForwardIt begin, EndIt end, UnaryPredicate &&pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> ForwardIt
Finds the first value in range [begin, end) for which pred returns true. If not found,...
constexpr auto find_in(const Container &c, const T &value) noexcept(noexcept(*std::declval< iterator_type_for_t< const Container > & >()==value)) -> size_t
Find the first element in c equal to v and return the position.
typename iterator_type_for< Range >::type iterator_type_for_t
constexpr auto for_each(ForwardIt first, EndIt last, ForwardIt2 second, BinaryFunction f) -> BinaryFunction
Applies a binary operation to each pair of corresponding elements in two input ranges....
constexpr auto find_last_in_if(const Container &c, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *std::declval< iterator_type_for_t< const Container > & >()))) -> size_t
Find the last element in c for which p returns true and return the position.
constexpr auto copy_if(InputIt first, EndIt last, OutputIt out, UnaryPredicate pred) -> OutputIt
Copies those elements of [first, last) which satisfy pred to out. It also allows for a sentinel end i...
constexpr auto for_each_n(ForwardIt first, Size n, ForwardIt2 second, BinaryFunction f) -> std::pair< ForwardIt, ForwardIt2 >
Applies a binary operation to each pair of corresponding elements in two input ranges.
constexpr auto ends_with(RandomAccessIt1 begin1, RandomAccessIt1 end1, RandomAccessIt2 begin2, RandomAccessIt2 end2, BinaryPred pred={}) -> enable_if_t< is_random_access_iterator_v< RandomAccessIt1 > and is_random_access_iterator_v< RandomAccessIt2 >, bool >
Checks if a given range ends with a particular subrange.
constexpr auto first_result_opt(InputIt1 begin1, EndIt1 end1, InputIt2 begin2, EndIt2 end2, T def, BinaryTransform op) -> enable_if_t< is_input_iterator< InputIt1 >::value and is_input_iterator< InputIt2 >::value, std::decay_t< decltype(op(*begin1, *begin2))> >
constexpr auto get_max_n_old(It first, It last, std::size_t count, Comp cmp={}) -> SequenceContainer
Returns a container of the greatest count elements according to cmp of the range [first,...
constexpr auto find(ForwardIt begin, EndIt end, const Elem &value, Comp &&comp) noexcept(noexcept(comp(*begin, value))) -> ForwardIt
Finds a value in range [begin, end). If not found, returns end. It also allows for a sentinel end ite...
constexpr auto find_last_in_if_not(const Container &c, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *std::declval< iterator_type_for_t< const Container > & >()))) -> size_t
Find the last element in c for which p returns true and return the position.
constexpr auto max_element(ForwardIt first, EndIt last, Compare comp={}) -> ForwardIt
constexpr auto find_last(ForwardIt begin, EndIt end, const Elem &value) noexcept(noexcept(*begin==value)) -> ForwardIt
Searches a range for the last occurence of a match, and returns an iterator to it....
constexpr auto invoke(F &&f, Args &&... args) noexcept(noexcept(detail::do_invoke(std::forward< F >(f), std::forward< Args >(args)...))) -> decltype(auto)
typename std::decay< T >::type decay_t
KBLIB_CONSTANT_V is_random_access_iterator_v
constexpr auto erase_if(Container &c, UnaryPredicate p) noexcept(noexcept(c.erase(std::remove_if(c.begin(), c.end(), std::ref(p)), c.end()))) -> void
Abbreviation of the erase-remove idiom as a free function.
constexpr auto transform_exclusive_scan(InputIt first, EndIt last, OutputIt d_first, T init, BinaryAccumulation accum, UnaryTransform proj) -> OutputIt
constexpr auto erase(Container &c, const Elem &val) noexcept(noexcept(c.erase(std::remove(c.begin(), c.end(), val), c.end()))) -> void
Abbreviation of the erase-remove idiom as a free function.
constexpr auto replace_copy_n_if(InputIt first, Size count, OutputIt out, UnaryPredicate pred, const T &new_value) -> OutputIt
Copies an input range, but every element for which pred is true is replaced by new_value.
constexpr auto iota(ForwardIt first, ForwardIt last, T value, UnaryOperation unary_op) noexcept(noexcept(*first++=value) and noexcept(kblib::invoke(unary_op, std::move(value)))) -> void
constexpr auto copy_n_if(InputIt first, Size count, OutputIt out, UnaryPredicate pred) -> OutputIt
Copies those elements of [first, std::advance(first, n)) which satisfy pred to out.
constexpr auto contains_any(Range1 &&haystack, Range2 &&needle) -> enable_if_t< is_iterable< Range1 >::value and is_iterable< Range2 >::value, bool >
constexpr auto find_in_if(const Container &c, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *std::declval< iterator_type_for_t< const Container > & >()))) -> size_t
Find the first element in c for which p returns true and return the position.
constexpr auto find(ForwardIt begin, EndIt end, const Elem &value) noexcept(noexcept(*begin==value)) -> ForwardIt
Finds a value in range [begin, end). If not found, returns end. It also allows for a sentinel end ite...
constexpr auto rotate(ForwardIt first, ForwardIt n_first, ForwardIt last) noexcept(noexcept(swap(*first, *first))) -> ForwardIt
Rotates the input range. This is just a constexpr-in-C++14 version of std::rotate.
constexpr auto accumulate(InputIt first, InputIt last, T init) -> T
A constexpr version of std::accumulate.
constexpr auto search_replace_copy(Haystack &&haystack, Needle &&needle, Replacement &&replacement, OutputIt d_begin, BinaryPredicate compare={})
constexpr auto find_if_not(ForwardIt begin, EndIt end, UnaryPredicate &&pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> ForwardIt
Finds the first value in range [begin, end) for which pred returns false. If not found,...
constexpr auto sum(Range &&r) -> auto
Sum a range.
constexpr auto copy(InputIt first, EndIt last, OutputIt out) -> OutputIt
Copies all elements of [first, last) to out. It also allows for a sentinel end iterator.
typename return_assert< V, T >::type return_assert_t
constexpr auto find_in_if_not(const Container &c, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *std::declval< iterator_type_for_t< const Container > & >()))) -> size_t
Find the first element in c for which p returns false and return the position.
constexpr auto none_of(Range &&rng, UnaryPredicate pred) -> enable_if_t< is_iterable< Range >::value, bool >
Determine if pred is true for every element of the range.
constexpr auto find_match(InputIt1 begin1, EndIt1 end1, InputIt2 begin2, EndIt2 end2, BinaryPredicate cmp) -> enable_if_t< is_input_iterator< InputIt1 >::value and is_input_iterator< InputIt2 >::value and is_invocable< BinaryPredicate, decltype(*begin1), decltype(*begin2)>::value, std::pair< InputIt1, InputIt2 > >
constexpr auto transform(InputIt first, EndIt last, InputIt first2, OutputIt d_first, BinaryOperation binary_op) -> OutputIt
transform applies the given function to a range and stores the result in another range,...
constexpr auto starts_with(RandomAccessIt1 begin1, RandomAccessIt1 end1, RandomAccessIt2 begin2, RandomAccessIt2 end2, BinaryPred pred={}) -> enable_if_t< is_random_access_iterator_v< RandomAccessIt1 > and is_random_access_iterator_v< RandomAccessIt2 >, bool >
Checks if a given range starts with a particular subrange.
constexpr auto to_unsigned(I x) -> std::make_unsigned_t< I >
Cast integral argument to corresponding unsigned type.
constexpr auto equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) -> bool
constexpr auto repeat(std::size_t N, Callable func) noexcept(noexcept(func())) -> return_assert_t< is_invocable< Callable >::value, void >
Invoke a function N times.
constexpr auto find_last_if(ForwardIt begin, EndIt end, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> ForwardIt
Searches a range for the last element on which a predicate returns true. It also allows for a sentine...
constexpr auto operator()(const Obj &a, const Obj &b, Compare comp) const noexcept(noexcept(equals(a, b, comp))) -> bool
constexpr auto operator()(const Obj &a, const Obj &b) const noexcept(noexcept(equals(a, b))) -> bool
constexpr auto operator()(const Obj &a, const Obj &b) const noexcept(noexcept(equals(a, b))) -> bool
A function object implementing the equivalence relationship over a comparison predicate.
constexpr auto operator()(const Obj &a, const Obj &b, Compare comp) const noexcept(noexcept(equals(a, b, comp))) -> bool
Provides macros and basic templates used by the rest of kblib.
#define KBLIB_NODISCARD
This internal macro is used to provide a fallback for [[nodiscard]] in C++14.
Contains some type traits not in the standard library that are useful in the implementation of kblib.