-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[335] - Did you know that you can simplify
boost.mp11
API with DSL?
- Loading branch information
1 parent
5ee533b
commit 1f910a8
Showing
3 changed files
with
75 additions
and
12 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
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
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,61 @@ | ||
<details open><summary>Info</summary><p> | ||
|
||
* Did you know that you can simplify `boost.mp11` API with DSL*? | ||
|
||
* https://github.com/boostorg/mp11 | ||
* DSL - Domain Specific Language | ||
|
||
</p></details><details open><summary>Example</summary><p> | ||
|
||
```cpp | ||
template <class T1, class T2> | ||
[[nodiscard]] constexpr auto operator==(const T1&, const T2&) { return std::is_same_v<T1, T2>; } | ||
|
||
template <class... Ts> | ||
constexpr auto list = mp11::mp_list<Ts...>{}; | ||
|
||
static_assert(list<> == list<>); | ||
static_assert(list<int> == list<int>); | ||
static_assert(list<int, double> == list<int, double>); | ||
``` | ||
> https://godbolt.org/z/fTMsK8Moh | ||
</p></details><details open><summary>Puzzle</summary><p> | ||
* Can you implement DSL for boost.mp11 | ||
```cpp | ||
struct event {}; | ||
class foo1 : event {}; | ||
class foo2 : event { int i; }; | ||
class bar1 {}; | ||
class bar2 { int i; }; | ||
template<class... Ts> | ||
constexpr auto unique_event_ptrs = | ||
list<Ts...> | ||
| unique | ||
| filter<is_base_of<event>> | ||
| transform<add_pointer> | ||
; | ||
static_assert(unique_event_ptrs<> == list<>); | ||
static_assert(unique_event_ptrs<foo1> == list<foo1*>); | ||
static_assert(unique_event_ptrs<foo1, foo1> == list<foo1*>); | ||
static_assert(unique_event_ptrs<bar1> == list<>); | ||
static_assert(unique_event_ptrs<bar1, bar1> == list<>); | ||
static_assert(unique_event_ptrs<bar2, bar1> == list<>); | ||
static_assert(unique_event_ptrs<foo2, foo1> == list<foo2*, foo1*>); | ||
static_assert(unique_event_ptrs<foo1, foo2> == list<foo1*, foo2*>); | ||
static_assert(unique_event_ptrs<foo1, foo2, foo2> == list<foo1*, foo2*>); | ||
static_assert(unique_event_ptrs<foo1, foo1, foo2, foo2> == list<foo1*, foo2*>); | ||
static_assert(unique_event_ptrs<foo1, foo2, foo1, foo2> == list<foo1*, foo2*>); | ||
static_assert(unique_event_ptrs<foo1, bar1, foo1, foo2> == list<foo1*, foo2*>); | ||
static_assert(unique_event_ptrs<foo1, bar1, foo1, foo2> == list<foo1*, foo2*>); | ||
static_assert(unique_event_ptrs<foo1, bar1, foo1, foo1, bar1, bar2> == list<foo1*>); | ||
``` | ||
|
||
> https://godbolt.org/z/rjh6hhK6j | ||
</p></details> |