← API Reference Namespace

asge::functools

Namespaces

Classes & Structs

Functions

#template<typename T, typename Callable> auto MakeCallback(Callable &&inFunc, std::shared_ptr< T > inPtr)

Creates a callback wrapper that holds a weak reference to an object and safely invokes a member function on that object if it is still alive.

This function accepts a member function pointer and a shared pointer to an object and returns a callable lambda that, when invoked, attempts to lock the weak pointer to the object. If successful, it calls the member function otherwise do nothing.

Template Parameters
T

The class type of the object owning the member function

_Callable

Type of the member function pointer

Parameters
func

The member function pointer to invoke on the object

ptr

Shared pointer to the object instance

#template<typename T, typename Callable> auto MakeCallback(Callable &&inFunc, T *inPtr)

The same MakeCallback with smart pointers, but using raw pointers, which means that the lifetime of the object pointed to must be managed carefully, otherwise segmentation fault would occur.

#template<typename Tuple, typename BinOp> auto ReduceTuple(Tuple const &t, BinOp &&b)

Right-associative fold over a tuple's elements, no separate seed.

The last element seeds the accumulator; b(accumulator, element) is then applied moving leftward one element at a time. For a 3-tuple (c0, c1, c2) this computes b(b(c2, c1), c0).

Every value passed to b — the accumulator and each element alike — is typed as Tuple's fold type: the shared element type if every element has the same type, or a std::variant of the element types otherwise. b must return that same type.

Template Parameters
Tuple

A std::tuple<Ts...> with at least 2 elements.

BinOp

Callable invoked as b(accumulator, element), both typed as Tuple's fold type.

Parameters
t

Tuple to fold; must have tuple_size >= 2.

b

Combines the running accumulator with the next element.

Returns

The final accumulator, typed as Tuple's fold type.

#template<typename Tuple, typename Callable> auto MapTuple(Tuple &&t, Callable &&c)

Applies a callable to every element of a tuple, collecting the results.

Each element is passed to c independently via std::invoke, so c may be generic or overloaded when Tuple is heterogeneous. The result tuple's element types are whatever c returns for each input, decayed the same way std::make_tuple decays its arguments.

Template Parameters
Tuple

A tuple-like forwarding reference.

Callable

Invoked once per element as c(element).

Parameters
t

Tuple whose elements are transformed.

c

Callable applied to each element.

Returns

A new tuple holding std::invoke(c, element) for every element of t.

#template<typename Tuple1, typename Tuple2> auto ConcatTuples(Tuple1 &&t1, Tuple2 &&t2)

Concatenates two tuples into one, preserving element order.

Template Parameters
Tuple1

First tuple-like forwarding reference.

Tuple2

Second tuple-like forwarding reference.

Parameters
t1

Tuple contributing the leading elements.

t2

Tuple contributing the trailing elements.

Returns

A new tuple holding t1's elements followed by t2's elements.

#template<typename T, typename Tuple> auto PrependToTuple(T &&value, Tuple &&t)

Returns a new tuple with value inserted at the front of t.

Template Parameters
T

Type of the value to prepend; decayed as std::make_tuple decays it.

Tuple

Tuple-like forwarding reference to prepend onto.

Parameters
value

Value to place before t's elements.

t

Tuple whose elements follow value.

Returns

A new tuple: (value, t...).

#template<typename Tuple, typename Callable> void ForEachTupleType(Callable &&inFn)

Calls inFn.template operator()<T>() for each element type T of Tuple, in order.

Tuple is only a type list; no tuple object is created.