Implement a type-erased function wrapper

Quick Overview

This question evaluates a candidate's understanding of C++ type erasure, callable wrappers, object lifetime and copy/move semantics, and exception-safety considerations when implementing a minimal std::function-like template.

Implement a type-erased function wrapper

Company: Qube Research & Technologies

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a minimal std::function-like callable wrapper in C++ using type erasure via inheritance and a virtual call. Define a template Function<R(Args...)> that can store and invoke any callable (function pointer, lambda with captures, or functor), supports copy/move construction and assignment, operator(), destruction, and a boolean conversion for an empty state. You may ignore small-buffer optimization and heap/memory constraints. Explain exception-safety choices and the time/space costs of invocation and copies compared to the standard library version.

Quick Answer: This question evaluates a candidate's understanding of C++ type erasure, callable wrappers, object lifetime and copy/move semantics, and exception-safety considerations when implementing a minimal std::function-like template.

|Home/Coding & Algorithms/Qube Research & Technologies
Qube Research & Technologies logo
Qube Research & Technologies
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
8
0

Implement a minimal std::function-like callable wrapper in C++ using type erasure via inheritance and a virtual call. Define a template Function<R(Args...)> that can store and invoke any callable (function pointer, lambda with captures, or functor), supports copy/move construction and assignment, operator(), destruction, and a boolean conversion for an empty state. You may ignore small-buffer optimization and heap/memory constraints. Explain exception-safety choices and the time/space costs of invocation and copies compared to the standard library version.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...