|
1 | | -// |
2 | | -// Copyright (c) 2025 Jean-Louis Leroy (jean-louis.leroy@gmail.com) |
3 | | -// |
4 | | -// Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 | | -// file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) |
6 | | -// |
7 | | -// Official repository: https://github.com/boostorg/openmethod |
8 | | -// |
| 1 | += Boost.OpenMethod |
9 | 2 |
|
| 3 | +Boost.OpenMethod is a C++17 library that implements open-methods. |
10 | 4 |
|
11 | | -# Introduction |
| 5 | +== Features |
12 | 6 |
|
13 | | -Open-methods are similar to virtual functions, but they are not required to be |
14 | | -members of a class. By being both free and virtual, tdoc/hello_world.adochey provide a solution to |
15 | | -the Expression Problem: |
| 7 | +* Headers-only. |
16 | 8 |
|
17 | | -> Given a set of types, and a set of operations on these types, is it possible |
18 | | -to add new operations on the existing types, and new types to the existing |
19 | | -operations, without modifying existing code? |
| 9 | +* Exception agnostic by default. |
20 | 10 |
|
21 | | -Open-methods also address the banana-gorilla-jungle problem: |
| 11 | +* Customization points for alternative RTTI systems, error handling, vptr |
| 12 | +placement. |
22 | 13 |
|
23 | | -> The problem with object-oriented languages is they’ve got all this implicit |
24 | | -environment that they carry around with them. You wanted a banana but what you |
25 | | -got was a gorilla holding the banana and the entire jungle. — Joe Armstrong, |
26 | | -creator of Erlang progamming language |
| 14 | +== Requirements |
27 | 15 |
|
28 | | -As a bonus, open-methods can take more than one argument into account when |
29 | | -selecting the appropriate function to call - aka multiple dispatch. For that |
30 | | -reason, open-methods are often called multi-methods, but that term is |
31 | | -misleading, as it suggests that the feature is useful only when multiple |
32 | | -dispatch is needed. In reality, |
33 | | -https://openaccess.wgtn.ac.nz/articles/thesis/Multiple_Dispatch_in_Practice/16959112/1[it |
34 | | -has been observed] that, in large systems written in languages that support |
35 | | -multi-methods, most methods use single-dispatch. The real benefit is in the |
36 | | -solution to the Expression Problem. |
| 16 | +The library requires a compiler supporting at least C++17. |
37 | 17 |
|
38 | | -Open-methods were introduced by the Common Lisp Object System, and they are |
39 | | -native to many languages: Clojure, Julia, Dylan, TADS, Cecil, Diesel, Nice, etc. |
40 | | -Bjarne Stroustrup wanted open-methods in C++ almost from the beginning. In D&E |
41 | | -he writes: |
| 18 | +== Tested Compilers |
42 | 19 |
|
43 | | -> I repeatedly considered a mechanism for a virtual function call based on more |
44 | | -than one object, often called multi-methods. I rejected multi-methods with |
45 | | -regret because I liked the idea, but couldn’t find an acceptable form under |
46 | | -which to accept it. [...] Multi-methods is one of the interesting what-ifs of |
47 | | -C++. Could I have designed and implemented them well enough at the time? Would |
48 | | -their applications have been important enough to warrant the effort? What other |
49 | | -work might have been left undone to provide the time to design and implement |
50 | | -multi-methods? Since about 1985, I have always felt some twinge of regret for |
51 | | -not providing multi-methods (Stroustrup, 1994, The Design and Evolution of |
52 | | -C{plus}{plus}, 13.8). |
| 20 | +Boost.OpenMethod has been tested with the following compilers: |
53 | 21 |
|
54 | | -Circa 2007, he and his PhD students Peter Pirkelbauer and Yuriy Solodkyy wrote a |
55 | | -series of papers and a prototype implementation based on the EDG compiler. |
56 | | -Unfortunately, open-methods never made it into the standard. Stroustrup bemoans, |
57 | | -in a more recent paper: |
| 22 | +* clang: 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 |
| 23 | +* gcc: 8, 9, 10, 11, 12, 13, 14, 15 |
| 24 | +* msvc: 14.3 |
58 | 25 |
|
59 | | -> In retrospect, I don’t think that the object-oriented notation (e.g., x.f(y)) |
60 | | -should ever have been introduced. The traditional mathematical notation f(x,y) |
61 | | -is sufficient. As a side benefit, the mathematical notation would naturally have |
62 | | -given us multi-methods, thereby saving us from the visitor pattern workaround |
63 | | -(Stroustrup, 2020, Thriving in a Crowded and ChangingWorld: C++ 2006–2020). |
| 26 | +== Quality Assurance |
64 | 27 |
|
65 | | -This library implements the features described in the |
66 | | -http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2216.pdf[N2216 paper], |
67 | | -with some extensions: |
| 28 | +The development infrastructure for the library includes these per-commit |
| 29 | +analyses: |
68 | 30 |
|
69 | | -* a mechanism for calling the next most specialized overrider |
| 31 | +* Coverage reports |
| 32 | +* Clang sanitizers |
| 33 | +* Compilation and tests on Drone.io and GitHub Actions |
70 | 34 |
|
71 | | -* support for smart pointers |
72 | | -
|
73 | | -* customization points for RTTI, error handling, tracing, smart pointers... |
74 | | -
|
75 | | -Multiple and virtual inheritance are supported, with the exception of repeated |
76 | | -inheritance. |
| 35 | +== Acknowledgments |
0 commit comments