You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-5Lines changed: 36 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -500,7 +500,8 @@ _output_
500
500
14 10
501
501
14 10 <== invoked with returned object
502
502
74
503
-
```Example with pointer to member function with additional parameters:
503
+
```
504
+
Example with pointer to member function with additional parameters:
504
505
```c++
505
506
structfoo
506
507
{
@@ -555,7 +556,7 @@ You can also use `std::bind` to bind the this pointer and any parameter placehol
555
556
If you wish to pass a `reference` parameter, you must wrap it in `std::ref`.
556
557
557
558
If you wish to provide a `constexpr` array, you will need to use a simple function prototype, since `std::function` is not constexpr (see unit tests for examples).
558
-
> [!TIP]
559
+
> [!IMPORTANT]
559
560
> Your `std::array` of `std::tuple` should be sorted by enum.
560
561
> The `dispatch` method performs a binary search on the array. Complexity for a sorted array is at most $2log_2(N)+O(1)$ comparisons.
561
562
> If the array is _not_ sorted, complexity is linear.
@@ -1034,7 +1035,7 @@ template<typename C, typename Fn, typename... Args> // specialisation for member
1034
1035
requires std::invocable<Fn&&, C, T, Args...>
1035
1036
[[maybe_unused]] constexpr auto for_each_n(int n, Fn&& func, C *obj, Args&&... args);
1036
1037
```
1037
-
Call supplied invocable for _each bit that is on_. Similar to `std::for_each` except first parameter of your invocable must accept an enum value (passed by `for_each`).
1038
+
Call supplied invocable for _every bit that is on_. Similar to `std::for_each` except first parameter of your invocable must accept an enum value (passed by `for_each`).
1038
1039
Optionally provide any additional parameters. Works with lambdas, member functions, functions etc. You can limit the number of calls to your
1039
1040
invocable by using the `for_each_n` version with the first parameter being the maximum number to call. The second version of `for_each` and `for_each_n` is intended to be used
1040
1041
when using a member function - the _second_ parameter passed by your call must be the `this` pointer of the object.
@@ -1043,7 +1044,7 @@ If you wish to pass a `reference` parameter, you must wrap it in `std::ref`.
1043
1044
Returns `std::bind(std::forward<Fn>(func), std::placeholders::_1, std::forward<Args>(args)...)` or
1044
1045
`std::bind(std::forward<Fn>(func), obj, std::placeholders::_1, std::forward<Args>(args)...)` which can be stored or immediately invoked.
1045
1046
1046
-
To iterate over each bit regardless of whether it is on or not, use `conjure_enum<T>::for_each`.
1047
+
To iterate over every bit regardless of whether it is on or not, use `conjure_enum<T>::for_each`.
1047
1048
1048
1049
Example using member function:
1049
1050
```c++
@@ -1076,6 +1077,36 @@ numbers::two
1076
1077
numbers::five
1077
1078
```
1078
1079
1080
+
### iv. Using `conjure_enum::dispatch` with `enum_bitset`
1081
+
Using an `enum_bitset` wth `conjure_enum::dispatch` can be a convenient way of iterating through a set of bits to call specific functions using `for_each`. The following demonstrates this:
0 commit comments