|
Boost : |
Subject: Re: [boost] yomm2 - open methods
From: Jean-Louis Leroy (jl_at_[hidden])
Date: 2018-01-21 20:22:21
Thanks for the comments.
I am still hesitating about some of the names and APIs. The library is
pre-version 1.0.0, and it's the time to get things right.
I am still hesitating about the syntax for defining a method
(overridern). I could easily support:
// no return type here
// ---------V
YOMM2_BEGIN(kick, (Dog& dog)) {
return "bark";
} YOMM2_END;
It breaks the symmetry with YOMM2_DECLARE though.
Now onto your points...
> - I feel like it should be possible to get rid of YOMM2_END
> by moving the function body out-of-line or using a lambda
> or something.
Of course I would like to get rid of YOMM2_END, but I haven't yet found a way
of doing that that also ensures that the body of the method can be inlined
inside the wrapper that casts the virtual arguments. I trie with lambdas to
back in 2014. Then maybe I've overlooked something, if you have an idea...
> - The documentation isn't clear on how the one-definition-rule
> applies (unless I missed it). My default assumption would
> be that YOMM2_DEFINE for a given overload should appear in
> exactly one translation unit, and that YOMM2_DECLARE and
> YOMM2_CLASS may appear in multiple translation units so
> long as the declarations are identical, but I notice that
> they're /all/ using unnamed namespaces. All of your examples
> only use a single source file, so I can't really guess your
> intentions from usage either.
Indeed I should be more explicit about this. As you guessed, YOMM2_DECLARE
should go is header file worthy - it just defines an inline function and
delcares a hidden function that is just used to guide the overload resolution.
YOMM2_DEFINE is for *defintions* and as such only one is allowed per process;
they're for .cpp files.
YOMM2_CLASS is borderline. Normally it should be called once, whereever that
happens - but it tolerates being called any number of times. That's for coping
with situations where the same class may have several associated type_info
objects - what I have in mind here is dynamically loaded Windows DLLs.
I will improve the documentation...
> - I'm curious why I would ever want to use the "cute" names
> when they're actually longer than the YOMM2 names.
I would use them ;-) They're more readable, and no uppercase loud. YOMM2 is an
obscure acronym (Yorel's Open Multi Methods) that I picked to avoid name
clashes. Lowercase names look more like keyworks.
But indeed maybe I should write the entire doc and examples in terms of YOMM2*
macros and de-emphasize the "cute" macros.
J-L
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk