1#ifndef _BBM_NATIVE_CONTROL_H_
2#define _BBM_NATIVE_CONTROL_H_
8#include "backbone/type_traits.h"
9#include "backbone/horizontal.h"
26 template<
typename NEWTYPE,
typename OLDTYPE>
27 inline constexpr NEWTYPE
cast(OLDTYPE&& val)
29 return static_cast<NEWTYPE
>(val);
35 template<
typename T,
typename U>
requires requires(std::decay_t<T> a, std::decay_t<U> b) {{a+b};}
36 inline constexpr auto select(
bool mask,
const T& a,
const U& b)
38 using return_type =
decltype( std::declval<std::decay_t<U>>() + std::declval<std::decay_t<T>>() );
39 return (mask ? return_type(a) : return_type(b));
42 template<
typename T,
typename U,
size_t N>
requires requires(value_t<T> a, value_t<U> b) {{a+b};}
45 using return_type =
decltype( std::declval<value_t<U>>() + std::declval<
value_t<T>>() );
52 template<
typename T,
typename U>
requires (!is_complex_v<U>) &&
requires(value_t<T> a, value_t<U> b) {{a+b};}
58 template<
typename T,
typename U>
requires (!is_complex_v<U>) &&
requires(value_t<T> a, value_t<U> b) {{a+b};}
68 template<
typename RET,
typename C>
requires std::ranges::range<C> && std::convertible_to<bbm::iterable_value_t<C>, RET>
69 inline constexpr RET
lookup(C&& container,
size_t idx,
bool mask=
true)
72 if(!mask)
return RET();
76 return RET(*(std::next(
bbm::begin(container), idx)));
82 template<
typename VAL,
typename C>
requires std::ranges::range<C> && std::convertible_to<VAL, bbm::iterable_value_t<C>>
83 inline constexpr void set(C&& container,
size_t idx, VAL&& value,
bool mask=
true)
90 *(std::next(
bbm::begin(container), idx)) = std::forward<VAL>(value);
96 template<
typename C,
typename PRED>
requires std::ranges::range<C> && std::is_invocable_r_v<bool, PRED, bbm::iterable_value_t<C>>
97 inline constexpr size_t binary_search(C&& container, PRED&& predicate,
bool mask=
true)
105 auto pred_wrapper = [&](
const value_type& val,
const value_type& )
107 return predicate(val);
111 return std::distance(
bbm::begin(container), std::lower_bound(
bbm::begin(container),
bbm::end(container), value_type(), pred_wrapper) );
#define bbm_out_of_range
Definition: error.h:44
ranged for loop over multiple containers at once
Random number generator; built on top of Drjit.
Definition: backbone.h:53
constexpr void set(C &&container, const Index &idx, VAL &&value, const index_mask_t< Index > &mask=true)
Non-packet set.
Definition: control.h:77
typename backbone::detail::value< std::decay_t< T > >::type value_t
Value trait.
Definition: type_traits.h:35
constexpr RET lookup(C &&container, const Index &idx, const index_mask_t< Index > &mask=true)
Non-packet look up.
Definition: control.h:61
NEWTYPE cast(OLDTYPE &&val)
cast
Definition: control.h:27
constexpr index_t< bbm::iterable_value_t< C > > binary_search(C &&container, PRED &&predicate, const index_mask_t< bbm::iterable_value_t< C > > &mask=true)
binary search
Definition: control.h:92
auto select(MASK &&mask, A &&a, B &&b)
Extension of drjit::select to diff/non-diff masks.
Definition: control.h:47
void multirange_for(FUNC &&func, Ts &&... containers)
ranged for loop over multiple containers at once
Definition: multirange_for.h:43
auto end(T &&t)
Definition: iterator_util.h:43
size_t size(T &&t)
Definition: iterator_util.h:22
std::decay_t< decltype(*bbm::begin(std::declval< T >()))> iterable_value_t
Definition: iterator_util.h:61
auto begin(T &&t)
Definition: iterator_util.h:29
Complex numbers.
Definition: complex.h:22