52 template <
typename Callable>
53 constexpr
auto repeat(std::size_t N, Callable func) noexcept(noexcept(func()))
55 for (std::size_t I = 0; I != N; ++I) {
67 template <
typename Container,
typename Elem>
68 constexpr
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());
80 template <
typename Container,
typename UnaryPredicate>
81 constexpr
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());
93 template <
typename Obj>
95 const Obj& b) noexcept(noexcept(
a < b))
97 return not (
a < b) and not (b <
a);
105 template <
typename Obj,
typename Compare>
107 Compare comp) noexcept(noexcept(comp(
a,
110 return not comp(
a, b) and not comp(b,
a);
122 template <
typename Compare =
void,
typename Obj =
void>
126 noexcept(noexcept(
equals(
a, b, comp))) ->
bool {
131 template <
typename Obj>
134 noexcept(noexcept(
equals(
a, b))) ->
bool {
139 template <
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 {
161 template <
typename InputIt,
typename T>
164 for (; first != last; ++first) {
165 init = std::move(init) + *first;
173 template <
class InputIt,
class T,
class BinaryOperation>
175 BinaryOperation op) -> T {
176 for (; first != last; ++first) {
177 init = op(std::move(init), *first);
193 template <
typename InputIt>
199 auto init = *first++;
215 template <
typename InputIt,
typename BinaryOperation>
222 auto init = *first++;
236 template <
typename Range>
240 auto first = begin(r);
245 auto init = *first++;
249 template <
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) {
263 template <
typename InputIt,
typename BinaryAccumulation,
264 typename BinaryTransform>
266 adjacent_reduce(InputIt begin, InputIt begin1, InputIt end,
267 BinaryAccumulation acc, BinaryTransform op) {}
269 template <
typename InputIt,
typename BinaryTransform>
270 KBLIB_NODISCARD constexpr
auto adjacent_transform(InputIt begin, InputIt begin1,
272 BinaryTransform op) {}
274 template <
typename InputIt,
typename BinaryAccumulation,
275 typename BinaryTransform>
277 adjacent_inclusive_scan(InputIt begin, InputIt begin1, InputIt end,
278 BinaryAccumulation acc, BinaryTransform op) {}
289 template <
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) {
308 template <
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)) {
326 template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
328 ForwardIt begin, EndIt end,
329 UnaryPredicate&& pred) noexcept(noexcept(
kblib::invoke(pred, *begin)))
345 template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
347 ForwardIt begin, EndIt end,
348 UnaryPredicate&& pred) noexcept(noexcept(
kblib::invoke(pred, *begin)))
365 template <
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) {
395 template <
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) {
426 template <
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) {
457 template <
typename ForwardIt,
typename EndIt,
typename Elem>
459 ForwardIt begin, EndIt end,
460 const Elem& value) noexcept(noexcept(*begin == value)) ->
size_t {
473 template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
475 ForwardIt begin, EndIt end,
476 UnaryPredicate pred) noexcept(noexcept(
kblib::invoke(pred, *begin)))
489 template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
491 ForwardIt begin, EndIt end,
492 UnaryPredicate pred) noexcept(noexcept(
kblib::invoke(pred, *begin)))
509 template <
typename ForwardIt,
typename EndIt,
typename Elem>
511 ForwardIt begin, EndIt end,
512 const Elem& value) noexcept(noexcept(*begin == value)) ->
size_t {
524 template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
526 ForwardIt begin, EndIt end,
527 UnaryPredicate pred) noexcept(noexcept(
kblib::invoke(pred, *begin)))
540 template <
typename ForwardIt,
typename EndIt,
typename UnaryPredicate>
542 ForwardIt begin, EndIt end,
543 UnaryPredicate pred) noexcept(noexcept(
kblib::invoke(pred, *begin)))
557 template <
typename Container,
typename T>
559 find_in(
const Container& c,
const T& value) noexcept(
567 template<
typename ExecutionPolicy,
typename Container,
typename T>
569 const Container& c,
const T& v) ->
size_t {
584 template <
typename Container,
typename UnaryPredicate>
590 const Container>&>())))
606 template <
typename Container,
typename UnaryPredicate>
612 const Container>&>())))
619 template<
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);
625 template<
typename ExecutionPolicy,
typename Container,
typename UnaryPredicate>
628 UnaryPredicate p) ->
size_t {
643 template <
typename Container,
typename T>
663 template <
typename Container,
typename UnaryPredicate>
669 const Container>&>())))
685 template <
typename Container,
typename UnaryPredicate>
691 const Container>&>())))
699 template <
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);
715 template <
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);
736 template <
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;
757 template <
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;
779 template <
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;
801 template <
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;
820 template <
typename InputIt,
typename EndIt,
typename T,
typename UnaryTransform>
825 for (; begin != end; ++begin) {
826 auto cur = op(*begin);
833 template <
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);
849 template <
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);
866 template <
typename InputIt,
typename EndIt,
typename T,
typename UnaryTransform,
867 typename UnaryPredicate>
872 for (; begin != end; ++begin) {
879 template <
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);
895 template <
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);
914 template <
typename T>
916 template <
typename U>
919 template <
typename InputIt,
typename EndIt,
typename T,
typename UnaryTransform>
924 for (; begin != end; ++begin) {
925 auto cur = op(*begin);
932 template <
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);
948 template <
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);
969 template <
typename InputIt,
typename UnaryPredicate>
973 for (; begin != end; ++begin) {
983 template <
typename Range,
typename UnaryPredicate>
986 for (
auto&& el : std::forward<Range>(rng)) {
987 if (not
kblib::invoke(pred,
static_cast<decltype(el)
>(el))) {
996 template <
typename InputIt,
typename UnaryPredicate>
1000 for (; begin != end; ++begin) {
1010 template <
typename Range,
typename UnaryPredicate>
1013 for (
auto&& el : std::forward<Range>(rng)) {
1023 template <
typename InputIt,
typename UnaryPredicate>
1025 UnaryPredicate pred)
1027 for (; begin != end; ++begin) {
1037 template <
typename Range,
typename UnaryPredicate>
1040 for (
auto&& el : std::forward<Range>(rng)) {
1051 template <
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; });
1062 template <
typename Set,
typename Value>
1072 [&](
const auto&
e) {
return e == val; });
1075 template <
typename InputIt1,
typename InputIt2>
1077 InputIt2 n_begin, InputIt2 n_end)
1086 template <
typename InputIt,
typename Range2>
1097 template <
typename Range1,
typename Range2>
1104 begin(haystack), end(haystack),
1108 template <
typename ForwardIt,
typename EndIt,
typename Compare = std::less<>>
1109 constexpr
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)) {
1144 template <
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);
1178 template <
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())};
1201 template <
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));
1228 template <
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())};
1255 template <
typename Comp = std::less<>,
typename InputIt,
typename OutputIt,
1256 typename Elem =
typename std::iterator_traits<InputIt>::value_type>
1257 constexpr
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);
1278 template <
typename ForwardIt,
typename EndIt,
typename ForwardIt2,
1279 typename BinaryFunction>
1280 constexpr
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);
1299 template <
typename ForwardIt,
typename ForwardIt2,
typename Size,
1300 typename BinaryFunction>
1301 constexpr
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};
1321 template <
typename InputIt,
typename EndIt,
typename OutputIt>
1322 constexpr
auto copy(InputIt first, EndIt last, OutputIt out) -> OutputIt {
1323 while (first != last) {
1341 template <
typename InputIt,
typename EndIt,
typename OutputIt,
1342 typename UnaryPredicate>
1343 constexpr
auto copy_if(InputIt first, EndIt last, OutputIt out,
1344 UnaryPredicate pred) -> OutputIt {
1345 while (first != last) {
1364 template <
typename InputIt,
typename Size,
typename OutputIt>
1365 constexpr
auto copy_n(InputIt first, Size count, OutputIt out) -> OutputIt {
1366 for (Size i = 0; i < count; ++i) {
1384 template <
typename InputIt,
typename Size,
typename OutputIt,
1385 typename UnaryPredicate>
1386 constexpr
auto copy_n_if(InputIt first, Size count, OutputIt out,
1387 UnaryPredicate pred) -> OutputIt {
1388 for (Size i = 0; i < count; ++i) {
1411 template <
typename InputIt,
typename EndIt,
typename OutputIt,
1412 typename UnaryPredicate,
typename T>
1414 UnaryPredicate pred,
const T& new_value)
1416 while (first != last) {
1442 template <
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) {
1460 template <
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);
1485 template <
typename Haystack,
typename Needle,
typename Replacement,
1486 typename OutputIt,
typename BinaryPredicate = std::equal_to<>>
1488 Replacement&& replacement, OutputIt d_begin,
1489 BinaryPredicate compare = {}) {
1490 using std::begin, std::end;
1492 begin(needle), end(needle),
1493 begin(replacement), end(replacement),
1507 template <
class ForwardIt>
1508 constexpr
auto rotate(ForwardIt first, ForwardIt n_first,
1509 ForwardIt last) noexcept(noexcept(
swap(*first, *first)))
1511 if (first == n_first)
1513 if (n_first == last)
1516 ForwardIt read = n_first;
1517 ForwardIt write = first;
1518 ForwardIt next_read = first;
1520 while (read != last) {
1521 if (write == next_read)
1525 swap(*(write++), *(read++));
1543 template <
typename OutputIt,
typename EndIt,
typename Generator>
1545 Generator g) noexcept(noexcept(*++first = g()))
1547 while (first != last) {
1563 template <
typename OutputIt,
typename Size,
typename Generator>
1565 Generator g) noexcept(noexcept(*first++ = g()))
1567 for (Size i = 0; i < count; i++) {
1573 template <
typename ForwardIt,
typename T>
1574 constexpr
auto iota(ForwardIt first, ForwardIt last, T value) noexcept(
1575 noexcept(*first++ = value) and noexcept(++value)) ->
void {
1576 while (first != last) {
1585 template <
typename ForwardIt,
typename T,
typename UnaryOperation>
1587 ForwardIt first, ForwardIt last, T value,
1588 UnaryOperation unary_op
1589 ) noexcept(noexcept(*first++ = value)
1594 while (first != last) {
1601 template <
typename InputIt,
typename EndIt,
typename... Params>
1603 InputIt first, EndIt last, Params&&... params
1605 std::forward<Params>(params)...)))
1608 while (first != last) {
1629 template <
typename InputIt,
typename EndIt,
typename OutputIt,
1630 typename UnaryOperation>
1631 constexpr
auto transform(InputIt first, EndIt last, OutputIt d_first,
1632 UnaryOperation unary_op) -> OutputIt {
1633 while (first != last) {
1656 template <
typename InputIt,
typename EndIt,
typename InputIt2,
1657 typename OutputIt,
typename BinaryOperation>
1658 constexpr
auto transform(InputIt first, EndIt last, InputIt first2,
1659 OutputIt d_first, BinaryOperation binary_op)
1661 while (first != last) {
1687 template <
typename InputIt,
typename EndIt,
typename OutputIt,
1688 typename UnaryPredicate,
typename UnaryOperation>
1690 UnaryPredicate pred, UnaryOperation unary_op)
1692 while (first != last) {
1701 namespace detail_algorithm {
1712 template <
class ForwardIt>
1714 ForwardIt first, ForwardIt n_first,
1715 ForwardIt last) noexcept(noexcept(*first = std::move(*first))) ->
void {
1716 if (first == n_first or n_first == last)
1719 ForwardIt read = n_first;
1720 ForwardIt write = first;
1722 while (read != last) {
1723 *(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...
The main namespace in which all entities from kblib are defined.
constexpr auto call_each(InputIt first, EndIt last, Params &&... params) noexcept(noexcept(kblib::invoke(*first++, std::forward< Params >(params)...))) -> InputIt
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 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 find_in_if_not(ForwardIt begin, EndIt end, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> size_t
Find the offset of the first element for which p returns false. It also allows for a sentinel end ite...
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 a(const std::initializer_list< T > &a) -> auto
Index an array literal without naming its type.
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 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 iota(ForwardIt first, ForwardIt last, T value) noexcept(noexcept(*first++=value) and noexcept(++value)) -> void
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_last_in_if(ForwardIt begin, EndIt end, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> size_t
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,...
typename iterator_type_for< Range >::type iterator_type_for_t
constexpr auto first_result_if(InputIt begin, EndIt end, T def, UnaryTransform op, UnaryPredicate ch) -> enable_if_t< is_input_iterator< InputIt >::value, decltype(op(*begin))>
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 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 equals(const Obj &a, const Obj &b) noexcept(noexcept(a< b)) -> bool
Synthesize an equivalence relation from <.
constexpr auto find_in(ForwardIt begin, EndIt end, const Elem &value) noexcept(noexcept(*begin==value)) -> size_t
Find the offset of the first ocurrence of v in a range from the beginning. It also allows for a senti...
constexpr auto get_max_n(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 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 max_element(ForwardIt first, EndIt last, Compare comp={}) -> ForwardIt
constexpr auto ends_with(BidirIt1 begin1, BidirIt1 end1, BidirIt2 begin2, BidirIt2 end2, BinaryPred pred={}) -> enable_if_t<(is_bidirectional_iterator_v< BidirIt1 > and is_bidirectional_iterator_v< BidirIt2 >) and not(is_random_access_iterator_v< BidirIt1 > and is_random_access_iterator_v< BidirIt2 >), bool >
Checks if a given range ends with a particular subrange.
constexpr auto starts_with(InputIt1 begin1, EndIt1 end1, InputIt2 begin2, EndIt2 end2, BinaryPred pred) -> enable_if_t<(is_input_iterator_v< InputIt1 > and is_input_iterator_v< InputIt2 >) and not(is_random_access_iterator_v< InputIt1 > and is_random_access_iterator_v< InputIt2 >), bool >
Checks if a given range starts with a particular subrange.
constexpr auto contains_any(InputIt1 begin, InputIt1 end, InputIt2 n_begin, InputIt2 n_end) -> enable_if_t< is_input_iterator< InputIt1 >::value and is_input_iterator< InputIt2 >::value, bool >
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)
constexpr auto find_last_in_if_not(ForwardIt begin, EndIt end, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> size_t
Find the offset of the last element for which p returns false. It also allows for a sentinel end iter...
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 none_of(InputIt begin, InputIt end, UnaryPredicate pred) -> enable_if_t< is_input_iterator< InputIt >::value, bool >
Determine if pred is false for every element of the range.
constexpr auto sum(InputIt first, InputIt last) -> std::decay_t< decltype(*first)>
Sum a range.
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 all_of(InputIt begin, InputIt end, UnaryPredicate pred) -> enable_if_t< is_input_iterator< InputIt >::value, bool >
Determine if pred is true for every element of the range.
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(ForwardIt1 h_begin, ForwardIt1 h_end, ForwardIt2 n_begin, ForwardIt2 n_end, ForwardIt3 r_begin, ForwardIt3 r_end, OutputIt d_begin, BinaryPredicate Compare={}) -> OutputIt
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 copy(InputIt first, EndIt last, OutputIt out) -> OutputIt
Copies all elements of [first, last) to out. It also allows for a sentinel end iterator.
constexpr auto find_match(InputIt1 begin1, EndIt1 end1, InputIt2 begin2, 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 >>
typename return_assert< V, T >::type return_assert_t
constexpr auto first_result(InputIt begin, EndIt end, T def, UnaryTransform op) -> enable_if_t< is_input_iterator< InputIt >::value, std::decay_t< decltype(op(*begin))>>
constexpr auto first_result_opt(InputIt begin, EndIt end, T def, UnaryTransform op) -> enable_if_t< is_input_iterator< InputIt >::value, std::decay_t< decltype(op(*begin))>>
constexpr auto find_last_in(ForwardIt begin, EndIt end, const Elem &value) noexcept(noexcept(*begin==value)) -> size_t
Find the offset of the last ocurrence of v in a range from the beginning. It also allows for a sentin...
constexpr auto find_in_if(ForwardIt begin, EndIt end, UnaryPredicate pred) noexcept(noexcept(kblib::invoke(pred, *begin))) -> size_t
Find the offset of the first element for which p returns true. It also allows for a sentinel end iter...
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 transform(InputIt first, EndIt last, OutputIt d_first, UnaryOperation unary_op) -> OutputIt
transform applies the given function to a range and stores the result in another range,...
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.