46#if __cplusplus >= 201703L
65template <
typename Container,
typename InputIt,
typename UnaryFunction>
67 typename Container::allocator_type allocator
68 =
typename Container::allocator_type{})
70 Container out(allocator);
72 return static_cast<void>(out.resize(out.size())), out;
90template <
typename Container,
typename InputIt,
typename InputIt2,
91 typename BinaryFunction>
94 typename Container::allocator_type allocator
95 =
typename Container::allocator_type{})
97 Container out(allocator);
119template <
typename Array,
typename InputIt,
typename UnaryFunction,
120 enable_if_t<not is_resizable_v<Array>,
int> = 0>
145template <
typename Array,
typename InputIt,
typename InputIt2,
146 typename BinaryFunction,
147 enable_if_t<not is_resizable_v<Array>,
int> = 0>
149 BinaryFunction f) -> Array {
167template <
typename Container,
typename Functor>
169 typename Container::allocator_type allocator
170 =
typename Container::allocator_type{})
172 Container out(allocator);
193template <
typename Array,
typename Functor,
194 enable_if_t<not is_resizable_v<Array>,
int> = 0>
196 size_t size = std::tuple_size<Array>::value)
217template <
typename Container,
typename InputIt,
typename UnaryFunction>
240template <
typename Container,
typename InputIt,
typename InputIt2,
241 typename BinaryFunction>
243 BinaryFunction f) -> Container {
259template <
typename Container,
typename Functor>
274template <
typename Container,
typename Range,
typename UnaryFunction,
275 enable_if_t<is_resizable_v<Container>,
int> = 0>
288template <
typename Container,
typename ExecutionPolicy,
typename InputIt,
289 typename UnaryFunction>
291build(ExecutionPolicy&& policy, InputIt first, InputIt last, UnaryFunction f,
293 typename Container::allocator_type =
typename Container::allocator_type{})
297 return static_cast<void>(out.resize(out.size())), out;
299template <
typename Container,
typename ExecutionPolicy,
typename InputIt,
300 typename InputIt2,
typename BinaryFunction>
302build(ExecutionPolicy&& policy, InputIt first, InputIt last, InputIt2 first2,
305 typename Container::allocator_type =
typename Container::allocator_type{})
308 std::transform(policy, first, last, first2, std::back_inserter(out), f);
311template <
typename Array,
typename ExecutionPolicy,
typename InputIt,
312 typename UnaryFunction,
313 typename std::enable_if<
314 std::is_convertible<typename std::tuple_size<Array>::value_type,
318 InputIt last, UnaryFunction f) -> Array {
323template <
typename Array,
typename ExecutionPolicy,
typename InputIt,
324 typename InputIt2,
typename BinaryFunction,
325 typename std::enable_if<
326 std::is_convertible<typename std::tuple_size<Array>::value_type,
330 InputIt last, InputIt2 first2, BinaryFunction f)
336template <
typename Container,
typename ExecutionPolicy,
typename Functor>
338build(ExecutionPolicy&& policy, Functor f,
size_t size,
340 typename Container::allocator_type =
typename Container::allocator_type{})
346template <
typename Array,
typename ExecutionPolicy,
typename Functor,
347 typename std::enable_if<
348 std::is_convertible<typename std::tuple_size<Array>::value_type,
352 size_t size = std::tuple_size<Array>::value)
362 template <
typename Container>
364 template <
typename T>
365 constexpr static auto impl(std::size_t count, T
value) -> Container {
368 while (count-- > 0) {
369 out.push_back(
value);
374 template <
typename T,
typename I>
375 constexpr static auto impl(std::size_t count, T
value, I incr)
379 while (count-- > 0) {
380 out.push_back(
value);
387 template <
typename Array>
389 template <
typename T>
392 for (
auto& v : out) {
398 template <
typename T,
typename I>
401 for (
auto& v : out) {
424template <
typename Container,
typename... Args>
427 std::forward<Args>(args)...);
438template <
typename Container,
typename InputIt>
440 typename Container::allocator_type allocator
441 =
typename Container::allocator_type{})
443 Container out(allocator);
444 std::copy(first, last, std::back_inserter(out));
455template <
typename Container,
typename Range,
456 enable_if_t<is_resizable_v<Container>,
int> = 0>
472template <
typename Container,
typename Range>
474 typename Container::allocator_type allocator
475 =
typename Container::allocator_type{})
477 Container out(allocator);
478 std::copy(std::begin(r), std::end(r), std::back_inserter(out));
489template <
typename Container,
typename InputIt,
490 enable_if_t<not is_resizable_v<Container>,
int> = 0>
494 auto pos = std::begin(out);
495 auto end = std::end(out);
496 for (; first != last and pos != end; ++first, ++pos) {
508template <
typename Container,
typename Range,
509 enable_if_t<not is_resizable_v<Container>,
int> = 0>
512 auto first = std::begin(r);
513 auto last = std::end(r);
514 auto pos = std::begin(out);
515 auto end = std::end(out);
516 for (; first != last and pos != end; ++first, ++pos) {
530template <
typename Container,
typename InputIt,
531 enable_if_t<not is_resizable_v<Container>,
int> = 0>
535 auto pos = std::begin(out);
536 auto end = std::end(out);
537 for (std::size_t count = 0; count !=
size and first != last and pos != end;
538 ++first, ++pos, ++count) {
551template <
typename Container,
typename Range,
552 enable_if_t<not is_resizable_v<Container>,
int> = 0>
555 auto first = std::begin(r);
556 auto last = std::end(r);
557 auto pos = std::begin(out);
558 auto end = std::end(out);
559 for (std::size_t count = 0; count !=
size and first != last and pos != end;
560 ++first, ++pos, ++count) {
575template <
typename Container,
typename InputIt,
typename Predicate>
577 typename Container::allocator_type allocator
578 =
typename Container::allocator_type{})
580 Container out(allocator);
593template <
typename Container,
typename InputIt,
typename Size>
595 typename Container::allocator_type allocator
596 =
typename Container::allocator_type{})
598 Container out(allocator);
599 std::copy_n(first, count, std::back_inserter(out));
612template <
typename Container,
typename InputIt,
typename Size,
615 InputIt first, Size count, Predicate f,
616 typename Container::allocator_type allocator
617 =
typename Container::allocator_type{}) -> Container {
618 Container out(allocator);
Provides general-purpose algorithms, similar to the <algorithms> header.
This header provides some features of C++17 <type_traits> and other headers for C++14,...
This file provides some iterators, ranges, iterator/range adapters, and operations that can be perfor...
constexpr auto size(const C &c) -> decltype(c.size())
constexpr auto size(const C &c) -> decltype(c.size())
auto build_copy_n(InputIt first, Size count, typename Container::allocator_type allocator=typename Container::allocator_type{}) -> Container
constexpr auto buildiota(Args &&... args) -> auto
Builds a container of increasing values.
auto build_copy_n_if(InputIt first, Size count, Predicate f, typename Container::allocator_type allocator=typename Container::allocator_type{}) -> Container
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 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...
auto try_reserve(C &c, std::size_t s) noexcept(noexcept(c.reserve(s))) -> void
Attempt to reserve capacity in a container. No-op if unsupported.
auto build_copy_if(InputIt first, InputIt last, Predicate f, typename Container::allocator_type allocator=typename Container::allocator_type{}) -> Container
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 copy(InputIt first, EndIt last, OutputIt out) -> OutputIt
Copies all elements of [first, last) to out. It also allows for a sentinel end iterator.
auto build_copy(Range &&r, std::size_t size) -> Container
auto build_dy(Range &&r, UnaryFunction f) -> Container
auto build(Functor f, size_t size=std::tuple_size< Array >::value) -> Array
Constructs an array-like container with elements initialized by repeatedly calling a generating funct...
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,...
static constexpr auto impl(T value, I incr) -> Array
static constexpr auto impl(T value) -> Array
static constexpr auto impl(std::size_t count, T value) -> Container
static constexpr auto impl(std::size_t count, T value, I incr) -> Container
Provides macros and basic templates used by the rest of kblib.
#define KBLIB_UNUSED
This internal macro is used to provide a fallback for [[maybe_unused]] in C++14.
#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.