Skip to content

Commit d8b79fa

Browse files
committed
feat: initial commit
0 parents  commit d8b79fa

17 files changed

Lines changed: 1152 additions & 0 deletions

.clang-format

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
Language: Cpp
3+
InsertNewlineAtEOF: true
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveMacros: false
7+
AlignConsecutiveAssignments:
8+
Enabled: true
9+
AcrossComments: false
10+
AcrossEmptyLines: false
11+
AlignConsecutiveDeclarations: false
12+
AlignEscapedNewlines: Right
13+
AlignOperands: true
14+
AlignTrailingComments: true
15+
AllowAllArgumentsOnNextLine: true
16+
AllowAllConstructorInitializersOnNextLine: true
17+
AllowAllParametersOfDeclarationOnNextLine: true
18+
AllowShortBlocksOnASingleLine: Never
19+
AllowShortCaseLabelsOnASingleLine: false
20+
AllowShortFunctionsOnASingleLine: Empty
21+
AllowShortLambdasOnASingleLine: Inline
22+
AllowShortIfStatementsOnASingleLine: Never
23+
AllowShortLoopsOnASingleLine: false
24+
AlwaysBreakAfterDefinitionReturnType: None
25+
AlwaysBreakAfterReturnType: None
26+
AlwaysBreakBeforeMultilineStrings: false
27+
AlwaysBreakTemplateDeclarations: Yes
28+
BinPackArguments: true
29+
BinPackParameters: true
30+
BraceWrapping:
31+
BeforeLambdaBody: true
32+
AfterCaseLabel: false
33+
AfterClass: true
34+
AfterControlStatement: true
35+
AfterEnum: true
36+
AfterFunction: true
37+
AfterNamespace: true
38+
AfterObjCDeclaration: true
39+
AfterStruct: true
40+
AfterUnion: false
41+
AfterExternBlock: true
42+
BeforeCatch: true
43+
BeforeElse: true
44+
IndentBraces: false
45+
SplitEmptyFunction: true
46+
SplitEmptyRecord: true
47+
SplitEmptyNamespace: true
48+
BreakBeforeBinaryOperators: None
49+
BreakBeforeBraces: Custom
50+
BreakBeforeInheritanceComma: false
51+
BreakInheritanceList: BeforeColon
52+
BreakBeforeTernaryOperators: true
53+
BreakConstructorInitializersBeforeComma: false
54+
BreakConstructorInitializers: BeforeColon
55+
BreakAfterJavaFieldAnnotations: false
56+
BreakStringLiterals: true
57+
ColumnLimit: 120
58+
CompactNamespaces: false
59+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
60+
ConstructorInitializerIndentWidth: 4
61+
ContinuationIndentWidth: 4
62+
Cpp11BracedListStyle: true
63+
DeriveLineEnding: true
64+
DerivePointerAlignment: false
65+
FixNamespaceComments: true
66+
IndentCaseLabels: false
67+
IndentGotoLabels: true
68+
IndentPPDirectives: None
69+
IndentWidth: 4
70+
IndentWrappedFunctionNames: false
71+
KeepEmptyLinesAtTheStartOfBlocks: true
72+
NamespaceIndentation: All
73+
PointerAlignment: Right
74+
ReflowComments: true
75+
SortIncludes: false
76+
SortUsingDeclarations: true
77+
SpaceAfterCStyleCast: false
78+
SpaceAfterLogicalNot: false
79+
SpaceAfterTemplateKeyword: true
80+
SpaceBeforeAssignmentOperators: true
81+
SpaceBeforeCpp11BracedList: false
82+
SpaceBeforeCtorInitializerColon: true
83+
SpaceBeforeInheritanceColon: true
84+
SpaceBeforeParens: ControlStatements
85+
SpaceBeforeRangeBasedForLoopColon: true
86+
SpaceInEmptyBlock: false
87+
SpaceInEmptyParentheses: false
88+
SpacesBeforeTrailingComments: 1
89+
SpacesInAngles: false
90+
SpacesInConditionalStatement: false
91+
SpacesInContainerLiterals: true
92+
SpacesInCStyleCastParentheses: false
93+
SpacesInParentheses: false
94+
SpacesInSquareBrackets: false
95+
SpaceBeforeSquareBrackets: false
96+
Standard: Latest
97+
TabWidth: 4
98+
UseCRLF: false
99+
UseTab: Never

.clang-tidy

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
Checks: "*,
3+
-abseil-*,
4+
-altera-*,
5+
-android-*,
6+
-fuchsia-*,
7+
-google-*,
8+
-llvm*,
9+
-modernize-use-trailing-return-type,
10+
-zircon-*,
11+
-readability-else-after-return,
12+
-readability-static-accessed-through-instance,
13+
-readability-avoid-const-params-in-decls,
14+
-cppcoreguidelines-non-private-member-variables-in-classes,
15+
-misc-non-private-member-variables-in-classes,
16+
-readability-redundant-access-specifiers,
17+
-cppcoreguidelines-special-member-functions,
18+
-hicpp-special-member-functions,
19+
-readability-implicit-bool-conversion,
20+
-hicpp-explicit-conversions,
21+
-*-magic-numbers,
22+
-readability-named-parameter,
23+
-hicpp-named-parameter,
24+
-readability-identifier-length,
25+
-cppcoreguidelines-owning-memory,
26+
-cppcoreguidelines-pro-type-reinterpret-cast,
27+
-cppcoreguidelines-avoid-non-const-global-variables,
28+
-hicpp-signed-bitwise,
29+
-*-uppercase-literal-suffix,
30+
-*-cognitive-complexity,
31+
-*-multiway-paths-covered,
32+
-*-switch-missing-default-case,
33+
-*-avoid-endl,
34+
-cppcoreguidelines-pro-type-static-cast-downcast,
35+
-misc-header-include-cycle,
36+
-cppcoreguidelines-pro-type-vararg,
37+
-*-member-init,
38+
-bugprone-easily-swappable-parameters,
39+
-hicpp-vararg,
40+
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
41+
-*-dcl21-cpp,
42+
-cert-err58-cpp,
43+
-performance-no-int-to-ptr,
44+
-cppcoreguidelines-interfaces-global-init,
45+
-*-avoid-c-arrays,
46+
-hicpp-no-array-decay
47+
-*-array-to-pointer-decay
48+
"
49+
WarningsAsErrors: ''
50+
HeaderFilterRegex: ''
51+
FormatStyle: none

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(rebind LANGUAGES CXX VERSION 1.0.0)
3+
4+
# --------------------------------------------------------------------------------------------------------
5+
# Library options
6+
# --------------------------------------------------------------------------------------------------------
7+
8+
option(rebind_tests "Run tests" OFF)
9+
10+
# --------------------------------------------------------------------------------------------------------
11+
# Create library
12+
# --------------------------------------------------------------------------------------------------------
13+
14+
add_library(${PROJECT_NAME} INTERFACE)
15+
add_library(cr::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
16+
17+
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20)
18+
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON)
19+
20+
# --------------------------------------------------------------------------------------------------------
21+
# Include "include" folder
22+
# --------------------------------------------------------------------------------------------------------
23+
24+
target_include_directories(${PROJECT_NAME} INTERFACE "include")
25+
26+
# --------------------------------------------------------------------------------------------------------
27+
# Setup Dependencies
28+
# --------------------------------------------------------------------------------------------------------
29+
30+
include("cmake/cpm.cmake")
31+
32+
CPMFindPackage(
33+
NAME boost_preprocessor
34+
GIT_TAG boost-1.85.0
35+
GIT_REPOSITORY "https://github.com/boostorg/preprocessor"
36+
)
37+
38+
target_link_libraries(${PROJECT_NAME} INTERFACE boost_preprocessor)
39+
40+
# --------------------------------------------------------------------------------------------------------
41+
# Run tests
42+
# --------------------------------------------------------------------------------------------------------
43+
44+
if (rebind_tests)
45+
message(STATUS "[rebind] Building tests")
46+
add_subdirectory(tests)
47+
endif()
48+
49+
# --------------------------------------------------------------------------------------------------------
50+
# Install Targets
51+
# --------------------------------------------------------------------------------------------------------
52+
53+
install(DIRECTORY "include/" TYPE INCLUDE)
54+
install(TARGETS ${PROJECT_NAME} INCLUDES DESTINATION include)

LICENSE

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

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<p align="center">
2+
<img src="assets/logo.svg" width="600">
3+
</p>
4+
5+
## 📃 Description
6+
7+
_Rebind_ is a simple header-only C++20 reflection library for aggregates and enums.
8+
9+
## 📦 Installation
10+
11+
* Using [CPM](https://github.com/cpm-cmake/CPM.cmake)
12+
```cmake
13+
CPMFindPackage(
14+
NAME rebind
15+
VERSION 1.0.0
16+
GIT_REPOSITORY "https://github.com/Curve/rebind"
17+
)
18+
```
19+
20+
* Using FetchContent
21+
```cmake
22+
include(FetchContent)
23+
24+
FetchContent_Declare(rebind GIT_REPOSITORY "https://github.com/Curve/rebind" GIT_TAG v1.0.0)
25+
FetchContent_MakeAvailable(rebind)
26+
27+
target_link_libraries(<target> cr::rebind)
28+
```
29+
30+
## 📖 Examples
31+
32+
https://github.com/Curve/rebind/blob/7de073bd4736900193f6af5c543a3cf62e6f1a73/tests/name.test.cpp#L9-L11
33+
https://github.com/Curve/rebind/blob/9ee66d3cc9e8976d5d8a40856d7ee5a09d32c415/tests/enum.test.cpp#L22-L33
34+
https://github.com/Curve/rebind/blob/9ee66d3cc9e8976d5d8a40856d7ee5a09d32c415/tests/member.test.cpp#L37-L45
35+
36+
> 🧪 For more examples see [tests](tests/)
37+
38+
## 📋 Documentation
39+
40+
```cpp
41+
template <typename T>
42+
static constexpr auto type_name = /*...*/;
43+
```
44+
45+
> **Returns**: Human readable name of type `T`
46+
47+
```cpp
48+
template <auto T>
49+
static constexpr auto nttp_name = /*...*/;
50+
```
51+
52+
> **Returns**: Human readable name of the given nttp `T`
53+
54+
---
55+
56+
```cpp
57+
template <auto T>
58+
static constexpr auto arity = /*...*/;
59+
```
60+
61+
> **Returns**: Count of members of `T`
62+
63+
```cpp
64+
template <typename T>
65+
requires std::is_aggregate_v<T>
66+
constexpr auto to_tuple(T &value);
67+
```
68+
69+
> **Returns**: A tuple of references to all members of the given `value`
70+
71+
```cpp
72+
template <std::size_t I, typename T>
73+
requires std::is_aggregate_v<T>
74+
constexpr decltype(auto) get(T &value);
75+
```
76+
77+
> **Returns**: A reference to the nth member of `value`
78+
79+
---
80+
81+
```cpp
82+
template <typename T, std::size_t I>
83+
static constexpr auto inspect = /*...*/;
84+
```
85+
86+
> **Returns**: Metadata on the nth member of `T`
87+
> **Contains**: The members `name`, `type`
88+
89+
```cpp
90+
template <typename T>
91+
static constexpr auto member_names = /*...*/;
92+
```
93+
94+
> **Returns**: An array containing the names of all members of `T`
95+
96+
```cpp
97+
template <typename T, typename Fn>
98+
requires std::is_aggregate_v<T>
99+
constexpr auto visit(T &value, Fn &&callback)
100+
```
101+
102+
> **Brief**: Calls `callback` with all members of `value`
103+
> **Note**: The passed `callback` receives two arguments, the first being a reference to the member and the second being the metadata on the member _(as returned by `rebind::inspect`)_
104+
105+
---
106+
107+
```cpp
108+
template <auto T>
109+
static constexpr auto enum_name = /*...*/;
110+
```
111+
112+
> **Returns**: The name of the given enum value
113+
> **Note**: To get the name of an enum-type use `rebind::type_name` instead
114+
115+
```cpp
116+
template <typename T>
117+
static constexpr auto enum_values = impl::enum_values<T>();
118+
```
119+
120+
> **Returns**: All possible values of the given enum `T`
121+
> **Contains**: The enum `value` and `name`
122+
123+
```cpp
124+
template <typename T>
125+
requires std::is_enum_v<T>
126+
constexpr std::optional<impl::enum_field<T>> enum_value(T value);
127+
```
128+
129+
> **Returns**: Metadata on the corresponding enum `value`
130+
> **Contains**: The enum `value` and `name`

0 commit comments

Comments
 (0)