Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add experimental refraction module #10

Merged
merged 9 commits into from Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -21,6 +21,7 @@ Bolts is a utility library for the D programming language which contains a numbe
* **iz**: super non-eponymous template that provides a lot of the functionality that's in the traits module with a different sytax that allows their usage in meta functions as well.
* **experimental**: contains experimental features
*signatures: working implementation of type signatures
*refraction: generate mixin strings to replicate a function, with some changes

Most functions here operate on any compile time entity. For example `isUnaryOver` works in both these situatons:

Expand Down Expand Up @@ -82,3 +83,26 @@ source/bolts/experimental/signatures.d(310,5): Error: static assert: "Type MyRa
source/bolts/experimental/signatures.d(464): <-- Signature InputRange!(int) defined here.
source/bolts/experimental/signatures.d(471): <-- Checked here."
```

## Refraction (experimental):

It is sometimes necessary to create a function which is an exact copy of
another function. Or sometimes it is necessary to introduce a few variations,
while carrying all the other aspects. Because of function attributes, parameter
storage classes and user-defined attributes, this requires building a string
mixin. In addition, the mixed-in code must refer only to local names, if it is
to work across module boundaires. This module facilitates the creation of such
mixins.

For example, this creates a function that has a different name and return type,
but retains the 'pure' attribute from the original function:

```d
pure int answer() { return 42; }
mixin(
refract!(answer, "answer").withName("realAnswer")
.withReturnType("real")
.mixture);
static assert(is(typeof(realAnswer()) == real));
static assert(functionAttributes!realAnswer & FunctionAttribute.pure_);
```
11 changes: 10 additions & 1 deletion dub.json
Expand Up @@ -9,5 +9,14 @@
"targetPath": "bin",
"toolChainRequirements": {
"frontend": ">=2.086"
}
},
"configurations": [
{
"dflags": [
"-mixin=mixins.txt"
],
"name": "unittest",
"targetType": "library"
}
],
}