正确实现运行时多态
目前,该库是实验性的,它纯粹是一种好奇心。不保证接口的稳定性或实现的质量。请自行承担风险使用。
Dyno 是对以下内容的纯库实现: [Rust 特性对象][], [Go 接口][], [Haskell 类型类][], 和 [虚拟概念][]。在底层,它使用了称为 [类型消除][] 的 C++ 技术,这是 [std::any][], [std::function] 和许多其他有用类型背后的思想。
cmake --build build --target examples # 编译并运行示例 cmake --build build --target tests # 编译并运行单元测试 cmake --build build --target check # 运行示例和测试 cmake --build build --target benchmarks # 编译并运行基准测试
## Introduction
In programming, the need for manipulating objects with a common interface but
with a different dynamic type arises very frequently. C++ solves this with
inheritance:
c++ struct Drawable { virtual void draw(std::ostream& out) const = 0; }; struct Square : Drawable { virtual void draw(std::ostream& out) const override final { ... } }; struct Circle : Drawable { virtual void draw(std::ostream& out) const override final { ... } }; void f(Drawable const* drawable) { drawable->draw(std::cout); }
…c++ #include 使用命名空间 dyno::literals;
struct Drawable: decltype(dyno::requires_( "draw"_s = dyno::method )) { };
这个定义
![Travis status][badge.Travis]暂无开放 Issues,或尚未同步最近议题。