Skip to content

Add Function and MutatingFunction type-erased callable wrappers#79

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-type-erased-types-std-function
Draft

Add Function and MutatingFunction type-erased callable wrappers#79
Copilot wants to merge 2 commits intomainfrom
copilot/add-type-erased-types-std-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

DRAFT.md describes how protocol/protocol_view can implement the standard library's callable wrappers. This PR adds the concrete interface headers and tests that demonstrate this.

New interfaces

  • interface_function.hstruct Function { int operator()(int) const; } — models std::copyable_function<int(int) const>
  • interface_mutating_function.hstruct MutatingFunction { int operator()(int); } — models std::copyable_function<int(int)>
Standard library type Protocol equivalent
std::copyable_function<int(int) const> protocol<Function>
std::function_ref<int(int) const> protocol_view<const Function>
std::copyable_function<int(int)> protocol<MutatingFunction>
std::function_ref<int(int)> protocol_view<MutatingFunction>
// Any const-callable fits protocol<Function> — lambdas, structs, etc.
xyz::protocol<xyz::Function> f(std::in_place_type<DoubleIt>);
f(3);  // → 6

// protocol_view<const Function> is a non-owning reference — like std::function_ref
DoubleIt d;
xyz::protocol_view<const xyz::Function> view(d);

// protocol<MutatingFunction> captures mutable state with deep-copy semantics
xyz::protocol<xyz::MutatingFunction> counter(std::in_place_type<Counter>);
counter(10);  // accumulated state; copy starts independent

Template bug fix

protocol.j2 and protocol_manual_vtable.j2 generated requires(const T& t) {} when an interface has no const methods — an empty requires-expression that GCC 13 rejects. The const concept now emits true in that case.

Copilot AI changed the title [WIP] Implement type-erased types similar to std::function Add Function and MutatingFunction type-erased callable wrappers Apr 20, 2026
Copilot AI requested a review from jbcoe April 20, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

See if we can implement other type-erased types (like std::function)

2 participants