-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d8b79fa
Showing
17 changed files
with
1,152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
Language: Cpp | ||
InsertNewlineAtEOF: true | ||
AccessModifierOffset: -2 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveMacros: false | ||
AlignConsecutiveAssignments: | ||
Enabled: true | ||
AcrossComments: false | ||
AcrossEmptyLines: false | ||
AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: Right | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AllowAllArgumentsOnNextLine: true | ||
AllowAllConstructorInitializersOnNextLine: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: Never | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: Empty | ||
AllowShortLambdasOnASingleLine: Inline | ||
AllowShortIfStatementsOnASingleLine: Never | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: Yes | ||
BinPackArguments: true | ||
BinPackParameters: true | ||
BraceWrapping: | ||
BeforeLambdaBody: true | ||
AfterCaseLabel: false | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterObjCDeclaration: true | ||
AfterStruct: true | ||
AfterUnion: false | ||
AfterExternBlock: true | ||
BeforeCatch: true | ||
BeforeElse: true | ||
IndentBraces: false | ||
SplitEmptyFunction: true | ||
SplitEmptyRecord: true | ||
SplitEmptyNamespace: true | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Custom | ||
BreakBeforeInheritanceComma: false | ||
BreakInheritanceList: BeforeColon | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: false | ||
BreakConstructorInitializers: BeforeColon | ||
BreakAfterJavaFieldAnnotations: false | ||
BreakStringLiterals: true | ||
ColumnLimit: 120 | ||
CompactNamespaces: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
DeriveLineEnding: true | ||
DerivePointerAlignment: false | ||
FixNamespaceComments: true | ||
IndentCaseLabels: false | ||
IndentGotoLabels: true | ||
IndentPPDirectives: None | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
NamespaceIndentation: All | ||
PointerAlignment: Right | ||
ReflowComments: true | ||
SortIncludes: false | ||
SortUsingDeclarations: true | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterLogicalNot: false | ||
SpaceAfterTemplateKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeCpp11BracedList: false | ||
SpaceBeforeCtorInitializerColon: true | ||
SpaceBeforeInheritanceColon: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceBeforeRangeBasedForLoopColon: true | ||
SpaceInEmptyBlock: false | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInConditionalStatement: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
SpaceBeforeSquareBrackets: false | ||
Standard: Latest | ||
TabWidth: 4 | ||
UseCRLF: false | ||
UseTab: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
Checks: "*, | ||
-abseil-*, | ||
-altera-*, | ||
-android-*, | ||
-fuchsia-*, | ||
-google-*, | ||
-llvm*, | ||
-modernize-use-trailing-return-type, | ||
-zircon-*, | ||
-readability-else-after-return, | ||
-readability-static-accessed-through-instance, | ||
-readability-avoid-const-params-in-decls, | ||
-cppcoreguidelines-non-private-member-variables-in-classes, | ||
-misc-non-private-member-variables-in-classes, | ||
-readability-redundant-access-specifiers, | ||
-cppcoreguidelines-special-member-functions, | ||
-hicpp-special-member-functions, | ||
-readability-implicit-bool-conversion, | ||
-hicpp-explicit-conversions, | ||
-*-magic-numbers, | ||
-readability-named-parameter, | ||
-hicpp-named-parameter, | ||
-readability-identifier-length, | ||
-cppcoreguidelines-owning-memory, | ||
-cppcoreguidelines-pro-type-reinterpret-cast, | ||
-cppcoreguidelines-avoid-non-const-global-variables, | ||
-hicpp-signed-bitwise, | ||
-*-uppercase-literal-suffix, | ||
-*-cognitive-complexity, | ||
-*-multiway-paths-covered, | ||
-*-switch-missing-default-case, | ||
-*-avoid-endl, | ||
-cppcoreguidelines-pro-type-static-cast-downcast, | ||
-misc-header-include-cycle, | ||
-cppcoreguidelines-pro-type-vararg, | ||
-*-member-init, | ||
-bugprone-easily-swappable-parameters, | ||
-hicpp-vararg, | ||
-cppcoreguidelines-pro-bounds-pointer-arithmetic, | ||
-*-dcl21-cpp, | ||
-cert-err58-cpp, | ||
-performance-no-int-to-ptr, | ||
-cppcoreguidelines-interfaces-global-init, | ||
-*-avoid-c-arrays, | ||
-hicpp-no-array-decay | ||
-*-array-to-pointer-decay | ||
" | ||
WarningsAsErrors: '' | ||
HeaderFilterRegex: '' | ||
FormatStyle: none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(rebind LANGUAGES CXX VERSION 1.0.0) | ||
|
||
# -------------------------------------------------------------------------------------------------------- | ||
# Library options | ||
# -------------------------------------------------------------------------------------------------------- | ||
|
||
option(rebind_tests "Run tests" OFF) | ||
|
||
# -------------------------------------------------------------------------------------------------------- | ||
# Create library | ||
# -------------------------------------------------------------------------------------------------------- | ||
|
||
add_library(${PROJECT_NAME} INTERFACE) | ||
add_library(cr::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) | ||
|
||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON) | ||
|
||
# -------------------------------------------------------------------------------------------------------- | ||
# Include "include" folder | ||
# -------------------------------------------------------------------------------------------------------- | ||
|
||
target_include_directories(${PROJECT_NAME} INTERFACE "include") | ||
|
||
# -------------------------------------------------------------------------------------------------------- | ||
# Setup Dependencies | ||
# -------------------------------------------------------------------------------------------------------- | ||
|
||
include("cmake/cpm.cmake") | ||
|
||
CPMFindPackage( | ||
NAME boost_preprocessor | ||
GIT_TAG boost-1.85.0 | ||
GIT_REPOSITORY "https://github.com/boostorg/preprocessor" | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} INTERFACE boost_preprocessor) | ||
|
||
# -------------------------------------------------------------------------------------------------------- | ||
# Run tests | ||
# -------------------------------------------------------------------------------------------------------- | ||
|
||
if (rebind_tests) | ||
message(STATUS "[rebind] Building tests") | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
# -------------------------------------------------------------------------------------------------------- | ||
# Install Targets | ||
# -------------------------------------------------------------------------------------------------------- | ||
|
||
install(DIRECTORY "include/" TYPE INCLUDE) | ||
install(TARGETS ${PROJECT_NAME} INCLUDES DESTINATION include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Noah | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<p align="center"> | ||
<img src="assets/logo.svg" width="600"> | ||
</p> | ||
|
||
## 📃 Description | ||
|
||
_Rebind_ is a simple header-only C++20 reflection library for aggregates and enums. | ||
|
||
## 📦 Installation | ||
|
||
* Using [CPM](https://github.com/cpm-cmake/CPM.cmake) | ||
```cmake | ||
CPMFindPackage( | ||
NAME rebind | ||
VERSION 1.0.0 | ||
GIT_REPOSITORY "https://github.com/Curve/rebind" | ||
) | ||
``` | ||
|
||
* Using FetchContent | ||
```cmake | ||
include(FetchContent) | ||
FetchContent_Declare(rebind GIT_REPOSITORY "https://github.com/Curve/rebind" GIT_TAG v1.0.0) | ||
FetchContent_MakeAvailable(rebind) | ||
target_link_libraries(<target> cr::rebind) | ||
``` | ||
|
||
## 📖 Examples | ||
|
||
https://github.com/Curve/rebind/blob/7de073bd4736900193f6af5c543a3cf62e6f1a73/tests/name.test.cpp#L9-L11 | ||
https://github.com/Curve/rebind/blob/9ee66d3cc9e8976d5d8a40856d7ee5a09d32c415/tests/enum.test.cpp#L22-L33 | ||
https://github.com/Curve/rebind/blob/9ee66d3cc9e8976d5d8a40856d7ee5a09d32c415/tests/member.test.cpp#L37-L45 | ||
|
||
> 🧪 For more examples see [tests](tests/) | ||
## 📋 Documentation | ||
|
||
```cpp | ||
template <typename T> | ||
static constexpr auto type_name = /*...*/; | ||
``` | ||
|
||
> **Returns**: Human readable name of type `T` | ||
```cpp | ||
template <auto T> | ||
static constexpr auto nttp_name = /*...*/; | ||
``` | ||
|
||
> **Returns**: Human readable name of the given nttp `T` | ||
--- | ||
|
||
```cpp | ||
template <auto T> | ||
static constexpr auto arity = /*...*/; | ||
``` | ||
|
||
> **Returns**: Count of members of `T` | ||
```cpp | ||
template <typename T> | ||
requires std::is_aggregate_v<T> | ||
constexpr auto to_tuple(T &value); | ||
``` | ||
> **Returns**: A tuple of references to all members of the given `value` | ||
```cpp | ||
template <std::size_t I, typename T> | ||
requires std::is_aggregate_v<T> | ||
constexpr decltype(auto) get(T &value); | ||
``` | ||
|
||
> **Returns**: A reference to the nth member of `value` | ||
--- | ||
|
||
```cpp | ||
template <typename T, std::size_t I> | ||
static constexpr auto inspect = /*...*/; | ||
``` | ||
|
||
> **Returns**: Metadata on the nth member of `T` | ||
> **Contains**: The members `name`, `type` | ||
```cpp | ||
template <typename T> | ||
static constexpr auto member_names = /*...*/; | ||
``` | ||
|
||
> **Returns**: An array containing the names of all members of `T` | ||
```cpp | ||
template <typename T, typename Fn> | ||
requires std::is_aggregate_v<T> | ||
constexpr auto visit(T &value, Fn &&callback) | ||
``` | ||
> **Brief**: Calls `callback` with all members of `value` | ||
> **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`)_ | ||
--- | ||
```cpp | ||
template <auto T> | ||
static constexpr auto enum_name = /*...*/; | ||
``` | ||
|
||
> **Returns**: The name of the given enum value | ||
> **Note**: To get the name of an enum-type use `rebind::type_name` instead | ||
```cpp | ||
template <typename T> | ||
static constexpr auto enum_values = impl::enum_values<T>(); | ||
``` | ||
|
||
> **Returns**: All possible values of the given enum `T` | ||
> **Contains**: The enum `value` and `name` | ||
```cpp | ||
template <typename T> | ||
requires std::is_enum_v<T> | ||
constexpr std::optional<impl::enum_field<T>> enum_value(T value); | ||
``` | ||
> **Returns**: Metadata on the corresponding enum `value` | ||
> **Contains**: The enum `value` and `name` |
Oops, something went wrong.