Skip to content

Commit

Permalink
Clarified docs on comma in trailing return type
Browse files Browse the repository at this point in the history
  • Loading branch information
rollbear committed Oct 7, 2024
1 parent 40835a9 commit fb4f732
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 12 additions & 2 deletions docs/CookBook.md
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,18 @@ void a_test()

### <A name="mocking_return_template"/> Mocking functions which return a template

To use template as return type you have to put the signature into parentheses
like this:
To use template as return type, you need to introduce an alias for the return type instead:

```Cpp
using pair_ints = std::pair<int,int>;

struct M
{
MAKE_MOCK(make, auto (int, int)->pair_ints);
};
```
If you use the [**`MAKE_MOCKn()`**](reference.md/#MAKE_MOCKn) macros, you can get away
with enclosing the return type in parentheses, like this:
```Cpp
struct M
Expand Down
14 changes: 3 additions & 11 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -696,23 +696,15 @@ work poorly with templates. It sees the parameters to the
macro above as `make`, `std::pair<int`, followed by `int>(int,int)`, which
of course is nonsense and causes compilation errors.
One easy way around this is to put the signature into parentheses:
```Cpp
struct M
{
MAKE_MOCK2(make, (std::pair<int,int>(int,int)));
};
```

Or if you prefer the legacy way, create an alias:
One easy way around this is to create an alias:
```Cpp
using pair_int_int = std::pair<int,int>;
struct M
{
MAKE_MOCK2(make, pair_int_int(int,int));
MAKE_MOCK(make_trail, auto (int, int)->pair_int_int);
};
```

Expand All @@ -738,7 +730,7 @@ struct M
work poorly with templates. The expansion of the
[**`MAKE_MOCK()`**](reference.md/#MAKE_MOCK) macro sees the parameters to the
function as `std::pair<int`, followed by `int>`, which of course is nonsense
and causes compilation errors.
and causes compilation errors. The same problem applies to the return type.
A way around this is to create an alias:
Expand Down

0 comments on commit fb4f732

Please sign in to comment.