@@ -76,7 +76,7 @@ with `YOMM2_CLASS`. This means all classes that are marked with `virtual_`, and
7676all their subclasses. Each class registration must list the base classes that
7777may be involved in method calls.
7878
79- ` register_class ` is an alias for ` YOMM2_CLASS ` created by header
79+ ` register_class ` is an alias for ` YOMM2_CLASS ` provided by header
8080` yorel/yomm2/cute.hpp ` .
8181
8282#### Examples:
@@ -135,20 +135,20 @@ a virtual Animal argument in a method declaration.
135135```
136136YOMM2_DECLARE(return_type, method, (type...));
137137
138- return_type rv = method(unmarked_type ... arg);
138+ return_type rv = method(unspecified_type ... arg);
139139
140140```
141141
142142Declare a method.
143143
144144Create an inline function ` method ` that returns a ` return type ` and takes an
145- argument list of ` unmarked_type ...` , which consist of ` type... ` without the
145+ argument list of ` unspecified_type ...` , which consist of ` type... ` without the
146146` virtual_ ` marker. At least one ` type ` (but not necessarily all) must be marked
147147with ` virtual_ ` .
148148
149149When ` method ` is called, the dynamic types of the arguments marked with
150150` virtual_ ` are examined, and the most specific definition compatible with
151- ` unmarked_type ...` is called. If no compatible definition exists, or if
151+ ` unspecified_type ...` is called. If no compatible definition exists, or if
152152several compatible definitions exist but none of them is more specific than
153153all the others, the call is illegal and an error handler is executed. By
154154default it writes a diagnostic on ` std::cerr ` and terminates the program via
@@ -161,7 +161,7 @@ NOTE:
161161* The parameters in ` type... ` consist of _ just_ a type, e.g. ` int ` is correct
162162 but ` int i ` is not.
163163
164- ` declare_method ` is an alias for ` YOMM2_DECLARE ` created by header
164+ ` declare_method ` is an alias for ` YOMM2_DECLARE ` provided by header
165165` yorel/yomm2/cute.hpp ` .
166166
167167## Examples:
@@ -175,22 +175,31 @@ YOMM2_DECLARE(bool, approve, (virtual_<Role&>, virtual_<Expense&>), double);
175175
176176#### Synopsis:
177177```
178- YOMM2_DEFINE(return_type, name, (unmarked_type... argument)) {
178+ YOMM2_DEFINE(return_type, name, (unspecified_type... argument)) {
179+ ....
180+ }
181+
182+ YOMM2_DEFINE(container, return_type, name, (unspecified_type... argument)) {
179183 ....
180184}
181185```
182186
183187Add an implementation to a method.
184188
185- Locate a method that can be called with the specified ` unmarked_type ...` list
189+ Locate a method that can be called with the specified ` unspecified_type ...` list
186190and add the definition to the method's list of definitions. The method must
187191exist and must be unique. ` return_type ` must be covariant with the method's
188192return type. ` return_type ` may be ` auto ` .
189193
190194NOTE that the types of the arguments are _ not_ marked with ` virtual_ ` .
191195
192- ` define_method ` is an aliases for ` YOMM2_DEFINE ` and ` YOMM2_END `
193- created by header ` yorel/yomm2/cute.hpp ` .
196+ If ` container ` is specified, the method definition is placed inside the said
197+ container, which must have been declared with ` YOMM2_DECLARE_METHOD_CONTAINER `
198+ or ` method_container ` . See the documentation of
199+ ` YOMM2_DECLARE_METHOD_CONTAINER ` for more information on method containers.
200+
201+ ` define_method ` is an alias for ` YOMM2_DEFINE ` , provided by header
202+ ` yorel/yomm2/cute.hpp ` .
194203
195204## Examples:
196205```
@@ -222,11 +231,108 @@ YOMM2_DEFINE(std::string, meet, (Cat& cat, Dog& dog)) {
222231}
223232```
224233
234+ ## macros YOMM2_METHOD_INLINE, define_method_inline
235+
236+ #### Synopsis:
237+ ```
238+ YOMM2_DEFINE_INLINE(container, return_type, name, (unspecified_type... argument)) {
239+ ....
240+ }
241+ ```
242+
243+ Add an implementation to a method, inside a container, and make it inline.
244+
245+ Like the ` YOMM2_DEFINE(container, ...) ` macro, define a method inside the
246+ specified container, which must have been declared with
247+ ` YOMM2_DECLARE_METHOD_CONTAINER ` or ` method_container ` . The definition has the
248+ ` inline ` storage class, and thus can be placed in a header file and is a
249+ potential candidate for inlining.
250+
251+ See the documentation of ` YOMM2_DECLARE_METHOD_CONTAINER ` for more information
252+ on method containers.
253+
254+ ` define_method_inline ` is an alias for ` YOMM2_DEFINE_INLINE ` , provided by
255+ header ` yorel/yomm2/cute.hpp ` .
256+
257+ ## macros YOMM2_DECLARE_METHOD_CONTAINER, method_container
258+
259+ #### Synopsis:
260+
261+ ```
262+ YOMM2_DECLARE_METHOD_CONTAINER(container)
263+ YOMM2_DECLARE_METHOD_CONTAINER(container, return_type, name, (unspecified_type... argument))
264+ ```
265+
266+ Declare a method container, and optionally a method definition inside that
267+ container.
268+
269+ Method containers are collections of method definitions that can be addressed
270+ by their name, return type and signature. This makes it possible for a class to
271+ grant friendship to all the methods inside a container, or to a single method
272+ with a specific name, return type and signature - see ` YOMM2_FRIEND ` . It also
273+ makes it possible to retrieve a specific method, in order to call it or create
274+ a pointer to it - see ` YOMM2_DEFINITION ` . See [ containers] ( examples/containers )
275+ for an example.
276+
277+ This macro only creates declarations, and thus can be placed in a header
278+ file. The four argument form makes it possible to access a method definition
279+ across translation units.
280+
281+ Method containers are implemented as templates, and method definitions scoped
282+ inside containers are implemented as template specializations. Thus methods can
283+ only be added to a container defined in the same namespace, or a namespace
284+ nested inside the namespace where the container has been declared.
285+
286+ ` method_container ` is an alias for ` YOMM2_DECLARE_METHOD_CONTAINER ` , provided
287+ by header ` yorel/yomm2/cute.hpp ` .
288+
289+ ## macros YOMM2_FRIEND, friend_method
290+
291+ #### Synopsis:
292+
293+ ```
294+ YOMM2_FRIEND(container)
295+ YOMM2_FRIEND(container, return_type, (unspecified_type... argument))
296+ ```
297+
298+ Grant friendship to all the methods inside a container friend of a class, or to
299+ a specific method. See [ containers] ( examples/containers ) for an example.
300+
301+ ` friend_method_container ` is an alias for ` YOMM2_FRIEND ` , provided by header
302+ ` yorel/yomm2/cute.hpp ` .
303+
304+ ## macros YOMM2_DEFINITION, method_definition
305+
306+ #### Synopsis:
307+
308+ ```
309+ YOMM2_DEFINITION(container, return_type, (unspecified_type... argument))
310+ ```
311+
312+ Retrieve a method definition with a given return type and signature from a
313+ container.
314+
315+ The resulting method can be used as a normal function reference. It can be
316+ called, or its address can be taken. In particular, this makes it possible for
317+ a method definition to call a base method as part of its implementation, in the
318+ same manner as an ordinary virtual function can call a specific base function
319+ by prefixing its name with a base class name.
320+
321+ Note that the preferred way of calling the overriden method is via ` next ` . In
322+ normal circumstances, a method definition cannot assume which "super" or "base"
323+ function is the best choice, since the set of methods pertaining to the same
324+ declaration is open.
325+
326+ See [ containers] ( examples/containers ) for an example.
327+
328+ ` method_definition ` is an alias for ` YOMM2_DEFINITION ` , provided by header
329+ ` yorel/yomm2/cute.hpp ` .
330+
225331## function next
226332
227333#### Synopsis:
228334```
229- YOMM2_DEFINE(return_type, name, (type ... arg)) {
335+ YOMM2_DEFINE(return_type, name, (unspecified_type ... arg)) {
230336 ....
231337 next(arg...);
232338 ...
0 commit comments