Boost logo

Boost :

From: Ivan Matek (libbooze_at_[hidden])
Date: 2025-05-25 13:05:49


On Sun, May 25, 2025 at 12:37 AM Jean-Louis Leroy via Boost <
boost_at_[hidden]> wrote:

> During the review, Joaquin suggested changing the syntax for declaring and
> overriding methods, from:
>
> BOOST_OPENMETHOD(poke, (virtual_ptr<Animal>, std::ostream&), void);
>
> BOOST_OPENMETHOD_OVERRIDE(
> poke, (virtual_ptr<Bulldog> dog, std::ostream& os), void) { ... }
>
> to:
>
> BOOST_OPENMETHOD(poke, void(virtual_ptr<Animal>, std::ostream&));
>
> BOOST_OPENMETHOD_OVERRIDE(
> poke, void(virtual_ptr<Bulldog> dog, std::ostream& os)) { ... }
>
> The difficulty with this is that the macros generate several constructs
> using
> the method name, formal parameter list and return type.
>
> Steven suggested a trick to implement a similar syntax, using trailing
> return
> types:
>
> BOOST_OPENMETHOD(poke, (virtual_ptr<Animal>, std::ostream&)->void);
>
> BOOST_OPENMETHOD_OVERRIDE(
> poke, (virtual_ptr<Bulldog> dog, std::ostream& os)->void) { ... }
>

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));

Benefit is that trailing return type is not commonly used in codebases
where I worked, and downside is that name of method is not first... so when
you have 20 methods one after another first column is return types, and
name of fn is second column, so it is a bit less
readable.

 I am not a fan of:
poke, void(virtual_ptr<Animal>:
since afaik there is no C++ syntax that nas name, return type, arguments
ordering.

But to be honest I would not consider either of the options you suggested
bad so no strong pro or against votes from me. :)


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