|
| 1 | +# Simply |
| 2 | + |
| 3 | +## A playground for external polymorphism in C++. |
| 4 | + |
| 5 | +- No macros |
| 6 | +- Concise syntax for defining and using affordances |
| 7 | +- Supports allocators |
| 8 | +- `constexpr` in C++26 |
| 9 | + |
| 10 | +```cpp |
| 11 | +#include <simply/destructible.hpp> |
| 12 | +#include <simply/dyn.hpp> |
| 13 | + |
| 14 | +#include <iostream> |
| 15 | +#include <numbers> |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +struct insertable : simply::member_affordance_base { |
| 19 | + static auto fn(const auto &value, std::ostream &out) -> std::ostream & { |
| 20 | + return out << value; |
| 21 | + } |
| 22 | +}; |
| 23 | + |
| 24 | +template <typename Self> |
| 25 | +struct simply::iface<insertable, Self> { |
| 26 | + friend auto operator<<(std::ostream &out, const Self &self) -> std::ostream & { |
| 27 | + return simply::impl<insertable, Self>::fn(self, out); |
| 28 | + } |
| 29 | +}; |
| 30 | + |
| 31 | +int main() { |
| 32 | + using namespace std::string_literals; |
| 33 | + |
| 34 | + struct affordances : simply::conjunction<insertable, simply::destructible> {}; |
| 35 | + |
| 36 | + std::vector<simply::dyn<affordances>> values; |
| 37 | + values.emplace_back(std::quoted("Hello, world!"s)); |
| 38 | + values.emplace_back(4); |
| 39 | + values.emplace_back(std::numbers::pi); |
| 40 | + |
| 41 | + for (const auto &value : values) { |
| 42 | + std::cout << value << '\n'; |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | +
|
| 47 | +### Supported Compilers |
| 48 | +
|
| 49 | +- Clang 20 |
| 50 | +- GCC 14, 15 |
| 51 | +
|
| 52 | +### Features |
| 53 | +
|
| 54 | +- `dyn` for type erasure of affordances |
| 55 | +- Concepts: |
| 56 | + - `affordance<Affordance>` |
| 57 | + - `affords<T, Affordance>` |
| 58 | +- Predefined affordances for common use-cases: |
| 59 | + - `destructible` |
| 60 | + - `move_constructible` |
| 61 | + - `copy_constructible` |
| 62 | + - `extractable<In>` |
| 63 | + - `insertable<Out>` |
| 64 | + - `allocator_storage<Allocator>` |
| 65 | + - `indirect_dispatch` |
| 66 | + - `inplace_dispatch` |
| 67 | +- `iface<Affordance, Self>` to specialize interfaces of `dyn` |
| 68 | +- `impl<Affordance, T>` to specialize implementations of an affordance |
| 69 | +
|
| 70 | +### Planned Features |
| 71 | +
|
| 72 | +- `disjunction` to compose affordances as unions |
| 73 | +- `inplace_storage` |
| 74 | +- `shared_storage` |
| 75 | +- `copy_on_write_storage` |
| 76 | +- `invocable` affordance template |
| 77 | +- `assignment_affordance` support for type erasing sinks |
| 78 | +- `slot_dispatch` for vtable lookup using a static slot map key |
| 79 | +- Affordances for iterators |
| 80 | +- Specializations of `impl` to delegate member affordances through: |
| 81 | + - `std::reference_wrapper` |
| 82 | + - `std::unique_ptr` |
| 83 | + - `std::shared_ptr` |
| 84 | + - `std::weak_ptr` |
| 85 | + - `std::indirect` |
| 86 | + - `std::polymorphic` |
| 87 | + - `std::variant` (if every alternative affords the member) |
| 88 | + - `std::optional` (if both `T` and `std::nullopt_t` afford the member) |
| 89 | + - `std::expected` (if both `T` and `E` afford the member) |
| 90 | + - `std::pair` (if either first or second exclusively affords the member) |
| 91 | + - `std::tuple` (if one element exclusively affords the member) |
| 92 | +- Specializations of `dyn` that behave equivalently to: |
| 93 | + - `std::function` |
| 94 | + - `std::copyable_function` |
| 95 | + - `std::move_only_function` |
| 96 | + - `std::function_ref` |
| 97 | + - `std::ranges::any_view` |
0 commit comments