diff --git a/docs/CookBook.md b/docs/CookBook.md index 0b59eee..af59507 100644 --- a/docs/CookBook.md +++ b/docs/CookBook.md @@ -940,8 +940,18 @@ void a_test() ### 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; + +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 diff --git a/docs/FAQ.md b/docs/FAQ.md index 23c0feb..00b089c 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -696,16 +696,7 @@ work poorly with templates. It sees the parameters to the macro above as `make`, `std::pair(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))); -}; -``` - -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; @@ -713,6 +704,7 @@ using pair_int_int = std::pair; struct M { MAKE_MOCK2(make, pair_int_int(int,int)); + MAKE_MOCK(make_trail, auto (int, int)->pair_int_int); }; ``` @@ -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`, 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: