計算機科學中,包裝函式(英語:Wrapper function)是一種電腦程式中的函式,它存在的主要目的就是用來呼叫另一個函式。在物件導向編程中,它又被稱為方法委任(method delegation)。它的存在有多種功能:可以被當成适配器模式來使用,可以當成錯誤檢查程序,也可以被當成多重繼承來使用。

程式範例

编辑
public class StackSet implements Stack, Set {

    private LinkedList stack;
    private HashSet set;
    public boolean push(Object o) {
        if (set.add(o)) return stack.push(o);
        else return false;
    }
    public Object pop() {
        Object o = stack.pop();
        set.remove(o);
        return o;
    }
    public boolean contains(Object o) {
        return set.contains(o);
    }

}

📚 Artikel Terkait di Wikipedia

C++ Technical Report 1

wrapper產生的實體(instance)獲得。wrapper reference近似於C++語言中的引用。 使用ref以獲得任何实例的wrapper reference(對常数引用const &使用cref)。 wrapper reference對模板函数(template function

函数对象

object。 std::function<R(Args...)> 对象,更准确叫 type-erased polymorphic function wrapper。通常也算functor。 C++20 CPO,Customization Point Object,即“定制点对象”。例如std::ranges::begin。CPO

互递归

。对Pascal语言要求先声明后使用,互递归要求前向声明。 如同直接递归函数,包装函数(wrapper function)对互递归函数是有用的作为包装函数的作用域内的嵌套函数(英语:nested function)(如果支持的话)。这对跨多个函数共享状态而不直接传递参数特别有用。 一个例子用于确定奇偶数。

元类

assert b.f is not b.f == b.f >>> inspect(B.f) function None [] >>> inspect(B.f.__get__) method-wrapper None None >>> assert b.f == B.f.__get__(b) >>>

Underscore.js

each來區分這些函數。 The function chain can be used to create a modified version of the wrapper produced by _函數. When invoked on such a chained wrapper, each method

C++23

std::unreachable:标记不可达代码的函数 使 std::tuple 与其他“类似元组”的对象兼容 为 std::reference_wrapper 提供 std::basic_common_reference 特化以生成引用类型 为 std::pair 的转发构造函数添加默认参数 对以下内容添加

钩子编程

VirtualFunction01_t )( ticket* thisptr ); VirtualFunction01_t g_org_VirtualFunction01; //our detour function void __fastcall hk_VirtualFunction01( ticket*

流式接口

200); app.setTitle("My OpenGL/GLUT App"); app.create(); } // Fluent wrapper class FluentGlutApp : private GlutApp { public: FluentGlutApp(int argc