Boost logo

Boost :

From: Ivan Matek (libbooze_at_[hidden])
Date: 2025-05-25 21:34:55


On Sun, May 25, 2025 at 11:10 PM Jean-Louis Leroy via Boost <
boost_at_[hidden]> wrote:

> > As I often use GMock I would prefer same pattern here,
> > return type, name, args
> > this is example from GMock docs(ignore override):
> > MOCK_METHOD(void, Forward, (int distance), (override));
>
> Same as YOMM2:
>
> declare_method(void, poke, (virtual_<Animal&>, std::ostream&));
>
> define_method(void, poke, (Dog& dog, std::ostream& os)) {
> os << "bark";
> }
>
> So why did I change it to this?
>
> BOOST_OPENMETHOD(poke, (virtual_ptr<Animal>, std::ostream&), void);
>
> BOOST_OPENMETHOD_OVERRIDE(
> poke, (virtual_ptr<Dog> dog, std::ostream& os), void) {
> os << "bark";
> }
>
> That's because the YOMM2 syntax does not work well with return types that
> contain commas, like `std::tuple<int, float>`, forcing you to use tricks
> like
> typedefs or `BOOST_IDENTITY_TYPE`. The new syntax requires that the method
> name
> be an identifier, so we know for sure that the first macro argument is the
> entire thing, not a bit of it (e.g., not `std::tuple<int`). The second is
> wrapped in parentheses.
>

This is actually strong argument, comma thing is quite obnoxious with
GMock, not to mention that last time I hit it compiler error message was
useless.
So you have convinced me. :)

> It is a valid function type, as in `std::function<int(char, float)>`
>

I meant when you declare function in C++ you can do:
auto my_sum(int, int) -> int
int my_sum(int, int)
but you can not do:
my_sum int(int, int)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk