Skip to content

Commit 65b314c

Browse files
Initial commit
0 parents  commit 65b314c

31 files changed

+1473
-0
lines changed

.clang-format

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
BasedOnStyle: LLVM
2+
---
3+
Language: Cpp
4+
5+
AlwaysBreakTemplateDeclarations: Yes
6+
7+
IncludeBlocks: Regroup
8+
9+
IncludeCategories:
10+
- Regex: '^"'
11+
Priority: 1
12+
- Regex: "^<simply/"
13+
Priority: 2
14+
- Regex: "^<[^./]*[./]"
15+
Priority: 3
16+
- Regex: "^<[^./]*>$"
17+
Priority: 4
18+
19+
QualifierAlignment: Custom
20+
21+
QualifierOrder: [ "inline", "static", "friend", "constexpr", "const", "volatile", "type" ]

.clang-tidy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Checks: >
2+
bugprone-*,
3+
clang-analyzer-*,
4+
cppcoreguidelines-*,
5+
modernize-*,
6+
performance-*,
7+
portability-*,
8+
readability-*,
9+
-cppcoreguidelines-owning-memory,
10+
-readability-identifier-length,
11+
WarningsAsErrors: "*"

.clangd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CompileFlags:
2+
Remove: [ -fconcepts-diagnostics-depth=*, -fdeps-format=*, -fmodule-mapper=*, -fmodules-ts ]
3+
Diagnostics:
4+
UnusedIncludes: None

.envrc.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
layout python
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CMake on multiple platforms
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
fail-fast: false
15+
16+
matrix:
17+
os: [ ubuntu-latest, windows-latest ]
18+
build_type: [ Debug, Release ]
19+
c_compiler: [ gcc, clang, cl ]
20+
include:
21+
- os: windows-latest
22+
c_compiler: cl
23+
cpp_compiler: cl
24+
- os: ubuntu-latest
25+
c_compiler: gcc
26+
cpp_compiler: g++
27+
- os: ubuntu-latest
28+
c_compiler: clang
29+
cpp_compiler: clang++
30+
exclude:
31+
- os: windows-latest
32+
c_compiler: gcc
33+
- os: windows-latest
34+
c_compiler: clang
35+
- os: ubuntu-latest
36+
c_compiler: cl
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Set reusable strings
42+
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
43+
id: strings
44+
shell: bash
45+
run: |
46+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
47+
48+
- name: Configure CMake
49+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
50+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
51+
run: >
52+
cmake -B ${{ steps.strings.outputs.build-output-dir }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }}
53+
54+
- name: Build
55+
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
56+
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
57+
58+
- name: Test
59+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
60+
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
61+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
62+
run: ctest --build-config ${{ matrix.build_type }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.cache/
2+
/.direnv/
3+
/.venv/
4+
/build/
5+
/.envrc

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/Takishima/cmake-pre-commit-hooks
3+
rev: v1.9.6
4+
hooks:
5+
- id: clang-format
6+
- id: clang-tidy

CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.30)
2+
3+
project(
4+
Simply
5+
VERSION 1.0.0
6+
LANGUAGES CXX)
7+
8+
set(CMAKE_CXX_EXTENSIONS OFF)
9+
10+
option(SIMPLY_INSTALL_PRE_COMMIT_HOOKS
11+
"Install pre-commit hooks during configuration" ON)
12+
13+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
14+
15+
if(SIMPLY_INSTALL_PRE_COMMIT_HOOKS)
16+
include(pre-commit)
17+
endif()
18+
19+
include(simply)
20+
21+
add_library(simply INTERFACE)
22+
add_library(simply::simply ALIAS simply)
23+
target_compile_features(simply INTERFACE cxx_std_26)
24+
# target_compile_options(simply INTERFACE -Wall -Wextra -Werror -Wpedantic)
25+
26+
target_include_directories(simply INTERFACE include)
27+
28+
add_subdirectory(tests)

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 Patrick Roberts
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

Comments
 (0)