libycxx

class template

ycxx::inplace_function

Status
libycxx extension; include its header (not exported by import std;)
Scope
ycxx

Copyable owning function wrapper with configurable inline storage and no heap fallback.

Synopsis

template<
    class Signature,
    size_t Capacity = 4 * sizeof(void *),
    size_t Alignment = alignof(std::max_align_t)>
class inplace_function;

Specializations

Description

Include <ycxx/functional.hpp>; this is a libycxx extension, not a member of std and not exported by import std;. Only function signatures of the form R(Args...) are supported.

Targets must be copy constructible, nothrow move constructible, callable as T&, and fit Capacity bytes at Alignment alignment. Unsuitable targets are rejected by constraints. Capacity must be positive; Alignment must be a supported positive power-of-two alignment. Defaults are four pointer widths and alignof(std::max_align_t) (32 bytes and 16-byte alignment on typical 64-bit targets). Capacity excludes the wrapper's metadata and padding.

The wrapper never allocates target storage. A target's construction, copy, invocation or destruction can allocate internally. Copies own independent target copies; moves empty the source. Calling an empty wrapper throws std::bad_function_call, following libycxx's error handler policy when exceptions are disabled. The const call operator invokes a mutable target just as std::function does. References returned by the target preserve their lifetime requirements; dangling reference conversions are rejected.


#include <ycxx/functional.hpp>
#include <array>

int main() {
    std::array<int, 12> values{};
    ycxx::inplace_function<int(), 64> callback = [values] { return values[0]; };
    auto copy = callback; // independent target, still no wrapper allocation
}

Unlike std::function, this extension has no target()/target_type() interface, allocator parameter, or qualified/noexcept signatures. A different capacity specialization is treated like any other callable: the entire source wrapper must fit; no unwrapping is performed.

Template parameters

Signature
Function signature R(Args...).
Capacity
Maximum target size in bytes, excluding metadata and padding.
Alignment
Alignment of the target buffer, in bytes.