Repository navigation
Replies: 3 comments 11 replies
|
Cool initiative. In case you're not aware, I researched it two years ago for this presentation: https://www.youtube.com/watch?v=UcxD_ORaMM0 I don't think is identical to your proposal but there are apparently more options. So I'm all in for using C++20 concepts! |
|
I noticed an event that may make this choice for us wrt to C++ version and release targeted: Boost.Graph 1.95 will be C++17 , boostorg/graph#613 We are one of the three Boost libraries besides graph_parallel and mpi that depends on graph, and we depend on an actual algorithm. Their corresponding reddit thread may be useful: https://www.reddit.com/r/cpp/comments/1wt531i/boostgraph_195_will_be_c17/ It e.g. points to the current MISRA standard being for C++17, which is industry-relevant and may include proprietary software users that we could not find by checking open repositories. I don't have any insight into how that standard develops, according to LLM-summary it might bump their C++ standard to 20 only in 2028/2029. If we want to keep the Boost.Graph dependency, we may want to at least bump the requirement C++17 for Boost 1.95 and in that case already get the deprecation warning in for Boost 1.93 which closes for major changes in 3 weeks. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I propose to start work towards moving the C++ baseline to C++20 (except modules because their implementation is still ongoing), specifically
Motivation
Major refactoring opportunities using features that standardize what we already do, such as concepts (replacing macros/BCCL), constraints (replacing a lot of SFINAE), constexpr if (replacing a lot of partially specialized on bools wrapper structs with apply methods. (click for details)
BG is a library that heavily utilizes template metaprogramming and many of the techniques and library facilities it has been using for a long time have received native language support by C++20. Relying on this standard allows refactoring several verbose and complicated constructs that are used heavily in the library into concise and modern-C++-idiomatic expressions that make their intent clear on first glance. Besides shorter and clearer code, this also drops Boost-internal dependences. The useful new features for refactoring since C++14 include mainly:
constexpr if(C++17): Already used behind a macro-guard to suppress warnings about compile-time constantifconditions but their main advantage is that they allow code in the non-selected branch that would be ill-formed otherwise, i.e. code that we would currently need to move out into members of partially speciliased template structs, even if the conditional code is just one line for each case.typename(C++20): Naturally that keyword features heavily in the codebase.New feature opportunities such as coroutines and execution policies for parallel algorithms.
Cost and Risk
Compiler Support
The main cost is dropping support for older compilers.
typename, [[likely]], [[unlikely]] and some other features. Baseline becomes 12 (2021) or 16 (2023).EDG, Intel and nvidia are currently not tested in CI but supporting versions exist.
Reverse dependencies
Since this is a header-only library, this choice affects every library that 1) depends on Boost.Geometry and 2) tracks Boost releases (if it just packages a frozen working version, it doesn't matter). Here is what I found so far:
More than a year later, this will probably have improved more. This list is by no means complete, it's just what I could find quickly. If there are other users where it would be a major issue, a deprecation warning may motivate feedback on that.
Examples and Measurements
The following is based on using Codex with GPT 5.6 Sol to produce a demonstration of refactoring opportunities. It's certainly not complete (I had to reprompt with several obvious missed opportunities and more remain) but it gives some rough line numbers, allows compile time benchmarks and examples. The branches can be seen on my github:
Examples
Concept (C++20) rewrite of Ring
Constraint (C++20) based dispatch of area
New
Old
constexpr if (C++17) based selection of distances strategy
New
C++20 Concept error messages
Refactoring measurements in lines
Develop to C++17 (keeps legacy type support for e.g. Boost.Variant): -871 lines
Develop to C++17 without legacy type (e.g. Boost.Variant which arguably becomes obsolete with std::variant) support: -2590 lines
Develop to C++20 with legacy type support: -4231 lines
Develop to C++20 without legacy type support: -6,929 lines
These refactorings are, as mentioned above, incomplete. I prompted Codex a couple of times with obvious oversights until I ran out of tokens, and I limited it to somewhat mechanical transformations (replacing partial specialisations on bools with constexpr if, sfinae with constraints, etc.).
Compile Time
With a big grain of salt because this is based purely on the incomplete LLM-refactorings and only two compiler versions compiling the full test suite, from develop to the C++20 branch:
Clang 22: no significant changes in compile time, 460MiB less RAM in total (-j20)
GCC 16: CPU time goes from 7064s to 6617s, RAM use from 31.44 GiB to 29.37 GiB, also -j20.
Roughly half the savings without dropping support for legacy types.
All reactions