Skip to content

Commit b47bc38

Browse files
author
Víctor Navarro González
committed
Merge remote-tracking branch 'origin/master'
2 parents 85bab9f + e6997e0 commit b47bc38

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All of the three classes support function removal by using '-='
2323
action -= foo;
2424
action.Invoke();
2525

26-
Prints: Nothing.
26+
// Prints: Nothing.
2727
```
2828

2929
### Func
@@ -40,7 +40,7 @@ func.Invoke(5, 'A');
4040
```
4141
4242
### Delegate
43-
His purpose is to store functions whose return type is not void with 0 or more parameters.
43+
His purpose is to store functions whose return type could be whatever, with 0 or more parameters.
4444
4545
``` C++
4646
Delegate<int()> delegate;
@@ -56,6 +56,17 @@ for (const auto &item : delegate.Invoke()) std::cout << item;
5656
// Prints: 123
5757
```
5858

59+
As with _Funcs_, you can also pass parameters to the Invoke method.
60+
``` C++
61+
int square(int x) { return x * x; }
62+
63+
Delegate<int(int)> delegate;
64+
delegate += square;
65+
66+
std::cout << delegate.Invoke(2)[0];
67+
// Prints: 4
68+
```
69+
5970
## Frequent questions
6071
### Can I add member functions?
6172
Yes! Perhaps is not in the most beautiful way, but still does the trick. You just need to use lambdas like this.
@@ -74,3 +85,10 @@ action.Invoke();
7485
// Prints: 5A6B
7586
```
7687
88+
### Something else you didn't mention?
89+
Thanks for asking. The operator `+=` is overloaded to accept a vector.
90+
``` C++
91+
delegate += { foo, bar };
92+
```
93+
You can also reset or clear the delegate with `delegate.Clear()`
94+

0 commit comments

Comments
 (0)