18#if HX_USE_MACROS_WITH_MODULE
19#error Header does not provide macros alone.
29template<
typename iterator_t_,
typename callable_t_>
31bool hxall_of(iterator_t_ begin_, iterator_t_ end_, callable_t_&& callable_) {
32 for(; begin_ != end_; ++begin_) {
43template<
typename iterator_t_,
typename callable_t_>
45bool hxany_of(iterator_t_ begin_, iterator_t_ end_, callable_t_&& callable_) {
46 for(; begin_ != end_; ++begin_) {
56template<
typename iterator_t_,
typename callable_t_>
60 for(; begin_ != end_; ++begin_) {
71template<
typename T_,
typename U_>
82template<
typename iterator_t_,
typename callable_t_>
84iterator_t_
hxfind_if(iterator_t_ begin_, iterator_t_ end_, callable_t_&& callable_) {
85 for(; begin_ != end_; ++begin_) {
96template<
typename iterator_t_,
typename callable_t_>
98callable_t_
hxfor_each(iterator_t_ begin_, iterator_t_ end_, callable_t_&& callable_) {
99 for(; begin_ != end_; ++begin_) {
113template<
typename iterator_t_,
typename output_iterator_t_,
typename less_t_>
115output_iterator_t_
hxmerge(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_,
116 output_iterator_t_&& output_,
const less_t_& less_)
noexcept {
120 while(src0_ != end0_ && src1_ != end1_) {
121 const bool take1_ = less_(*src1_, *src0_);
123 *output_r_ =
hxmove(*sel_);
125 src1_ = src1_ +
static_cast<ptrdiff_t
>(take1_);
126 src0_ = src0_ +
static_cast<ptrdiff_t
>(!take1_);
128 while(src0_ != end0_) {
129 *output_r_ =
hxmove(*src0_);
130 ++output_r_; ++src0_;
132 while(src1_ != end1_) {
133 *output_r_ =
hxmove(*src1_);
134 ++output_r_; ++src1_;
146template<
typename iterator_t_,
typename output_iterator_t_>
148output_iterator_t_
hxmerge(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_,
149 iterator_t_ end1_, output_iterator_t_&& output_)
noexcept {
156template<
typename iterator_t_>
169template<
typename iterator_t_,
typename less_t_>
172hxminmax(iterator_t_ begin_, iterator_t_ end_,
const less_t_& less_) {
174 if(begin_ == end_) {
return result_; }
175 for(++begin_; begin_ != end_; ++begin_) {
176 if(less_(*begin_, *result_.
min)) {
177 result_.
min = begin_;
179 else if(less_(*result_.
max, *begin_)) {
180 result_.
max = begin_;
188template<
typename iterator_t_>
204template<
typename iterator_t_,
typename output_iterator_t_,
typename less_t_>
206output_iterator_t_
hxset_difference(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_,
207 iterator_t_ end1_, output_iterator_t_&& output_,
const less_t_& less_)
noexcept {
211 while(src0_ != end0_ && src1_ != end1_) {
212 const bool lt_ = less_(*src0_, *src1_);
213 const bool gt_ = less_(*src1_, *src0_);
215 *output_r_ =
hxmove(*src0_);
218 src0_ = src0_ +
static_cast<ptrdiff_t
>(!gt_);
219 src1_ = src1_ +
static_cast<ptrdiff_t
>(!lt_);
221 while(src0_ != end0_) {
222 *output_r_ =
hxmove(*src0_);
223 ++output_r_; ++src0_;
235template<
typename iterator_t_,
typename output_iterator_t_>
237output_iterator_t_
hxset_difference(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_,
238 iterator_t_ end1_, output_iterator_t_&& output_)
noexcept {
252template<
typename iterator_t_,
typename output_iterator_t_,
typename less_t_>
255 iterator_t_ end1_, output_iterator_t_&& output_,
const less_t_& less_)
noexcept {
259 while(src0_ != end0_ && src1_ != end1_) {
260 const bool lt_ = less_(*src0_, *src1_);
261 const bool gt_ = less_(*src1_, *src0_);
263 *output_r_ =
hxmove(*src0_);
266 src0_ = src0_ +
static_cast<ptrdiff_t
>(!gt_);
267 src1_ = src1_ +
static_cast<ptrdiff_t
>(!lt_);
279template<
typename iterator_t_,
typename output_iterator_t_>
282 iterator_t_ end1_, output_iterator_t_&& output_)
noexcept {
296template<
typename iterator_t_,
typename output_iterator_t_,
typename less_t_>
298output_iterator_t_
hxset_union(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_,
299 iterator_t_ end1_, output_iterator_t_&& output_,
const less_t_& less_)
noexcept {
303 while(src0_ != end0_ && src1_ != end1_) {
304 const bool take1_ = less_(*src1_, *src0_);
305 const bool less0_ = less_(*src0_, *src1_);
307 *output_r_ =
hxmove(*sel_);
309 src0_ = src0_ +
static_cast<ptrdiff_t
>(!take1_);
310 src1_ = src1_ +
static_cast<ptrdiff_t
>(!less0_);
312 while(src0_ != end0_) {
313 *output_r_ =
hxmove(*src0_);
314 ++output_r_; ++src0_;
316 while(src1_ != end1_) {
317 *output_r_ =
hxmove(*src1_);
318 ++output_r_; ++src1_;
331template<
typename iterator_t_,
typename output_iterator_t_>
333output_iterator_t_
hxset_union(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_,
334 iterator_t_ end1_, output_iterator_t_&& output_)
noexcept {
346template<
typename iterator_t_,
typename equal_t_>
348iterator_t_
hxunique(iterator_t_ begin_, iterator_t_ end_,
const equal_t_& equal_)
noexcept {
349 if(begin_ == end_) {
return end_; }
350 iterator_t_ dst_ = begin_;
351 for(++begin_; begin_ != end_; ++begin_, ++dst_) {
352 if(equal_(*dst_, *begin_)) {
break; }
354 if(begin_ == end_) {
return end_; }
355 for(++begin_; begin_ != end_; ++begin_) {
356 if(!equal_(*dst_, *begin_)) {
366template<
typename iterator_t_>
368iterator_t_
hxunique(iterator_t_ begin_, iterator_t_ end_)
noexcept {
hxkey_equal_t<T> - A constexpr callable that invokes hxkey_equal.
Definition hxkey.hpp:87
hxkey_less_t<T> - A constexpr callable that invokes hxkey_less.
Definition hxkey.hpp:131
hxminmax_result - Return type of hxminmax holding iterators to the minimum and maximum elements of a ...
Definition hxalgorithm.hpp:157
iterator_t_ max
Definition hxalgorithm.hpp:160
iterator_t_ min
Definition hxalgorithm.hpp:159
constexpr callable_t_ hxfor_each(iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
hxfor_each - Applies the callable to each element in [begin, end) in order.
Definition hxalgorithm.hpp:98
constexpr iterator_t_ hxfind_if(iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
hxfind_if - Returns an iterator to the first element in [begin, end) for which the predicate callable...
Definition hxalgorithm.hpp:84
constexpr iterator_t_ hxunique(iterator_t_ begin_, iterator_t_ end_, const equal_t_ &equal_) noexcept
hxunique - Removes consecutive duplicate elements from the range [begin, end) using equal to identify...
Definition hxalgorithm.hpp:348
HX_NS_BEGIN_ constexpr bool hxall_of(iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
hxall_of - Returns true if the predicate callable returns true for every element in [begin,...
Definition hxalgorithm.hpp:31
constexpr hxminmax_result< iterator_t_ > hxminmax(iterator_t_ begin_, iterator_t_ end_, const less_t_ &less_)
hxminmax - Returns an hxminmax_result with iterators to the smallest and largest elements in [begin,...
Definition hxalgorithm.hpp:172
constexpr output_iterator_t_ hxset_difference(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
hxset_difference - Forms the difference of two ordered ranges [begin0, end0) and [begin1,...
Definition hxalgorithm.hpp:206
constexpr hxsize_t hxcount_if(iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
hxcount_if - Returns the number of elements in [begin, end) for which the predicate callable returns ...
Definition hxalgorithm.hpp:58
constexpr output_iterator_t_ hxmerge(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
hxmerge - Performs a stable merge of two ordered ranges [begin0, end0) and [begin1,...
Definition hxalgorithm.hpp:115
constexpr output_iterator_t_ hxset_intersection(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
hxset_intersection - Forms the intersection of two ordered ranges [begin0, end0) and [begin1,...
Definition hxalgorithm.hpp:254
constexpr T hxexchange(T &obj_, U_ &&new_value_) noexcept
hxexchange - Replaces obj with new_value and returns the old value of obj.
Definition hxalgorithm.hpp:73
constexpr bool hxany_of(iterator_t_ begin_, iterator_t_ end_, callable_t_ &&callable_)
hxany_of - Returns true if the predicate callable returns true for at least one element in [begin,...
Definition hxalgorithm.hpp:45
constexpr output_iterator_t_ hxset_union(iterator_t_ begin0_, iterator_t_ end0_, iterator_t_ begin1_, iterator_t_ end1_, output_iterator_t_ &&output_, const less_t_ &less_) noexcept
hxset_union - Forms the union of two ordered ranges [begin0, end0) and [begin1, end1) into output.
Definition hxalgorithm.hpp:298
User-overloadable key-equal, key-less, and key-hash functions.
#define hxinline
hxinline - Force a function to be inlined into its callers.
Definition hxsettings.h:120
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:89
#define hxattr_flatten
hxattr_flatten - Inline every call inside a function's body into it, recursively, regardless of the c...
Definition hxsettings.h:82
#define hxconstexpr
hxconstexpr - Enables C++23 compatable constexpr usage for functions as that has support for destruct...
Definition hxsettings.h:263
typename hxrestrict_t_< T >::type hxrestrict_t
hxrestrict_t - Adds the __restrict keyword to C++ pointers.
Definition hxutility.h:237
constexpr T && hxforward(hxremove_reference_t< T > &&x_)
hxforward - Implements std::forward.
Definition hxutility.h:304
constexpr hxremove_reference_t< T > && hxmove(T &&t_)
hxmove - Implements std::move.
Definition hxutility.h:333
Provides core macros, memory management and feature detection.
ptrdiff_t hxsize_t
hxsize_t - A signed size type, same as ssize_t or ptrdiff_t.
Definition libhatchet.h:209