Skip to content

Commit 2e232bc

Browse files
jmcarcelltmadlener
andauthored
Require C++20 and update to C++20 (#698)
* Require C++20 in podio and ROOT * Use consteval when possible and remove checks for C++20 * Use concepts and simplify templates * Change enable_ifs by requires * Fix the documentation for links * Remove an unused header and use std::disjunction * Use algorithms from std::ranges * Use concepts when possible and add comments when it's not possible * Remove dead code * Use std::ranges::find * Remove the ubuntu workflow since it is built with C++17 * Update docs for the frame * Add missing is_detected_v * Upper-case the concept collectionType * Add a minimum ROOT version with support for C++20 * Add back an ubuntu workflow with C++20 * Update the ROOT version * Update README.md Co-authored-by: Thomas Madlener <[email protected]> * Change the format to C++20 * Make sure to also format links.md * Remove no longer applicable enable_if from doc * [format] clang-format auto fixes --------- Co-authored-by: jmcarcell <[email protected]> Co-authored-by: Thomas Madlener <[email protected]>
1 parent a747cb0 commit 2e232bc

27 files changed

+136
-211
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ SpacesInContainerLiterals: true
104104
SpacesInCStyleCastParentheses: false
105105
SpacesInParentheses: false
106106
SpacesInSquareBrackets: false
107-
Standard: c++17
107+
Standard: c++20
108108
TabWidth: 8
109109
UseTab: Never
110110
...

.github/workflows/coverity.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: cvmfs-contrib/github-action-cvmfs@v4
1414
- uses: aidasoft/run-lcg-view@v4
1515
with:
16-
coverity-cmake-command: 'cmake -DCMAKE_CXX_STANDARD=17 -DENABLE_SIO=ON -DENABLE_JULIA=ON -DUSE_EXTERNAL_CATCH2=OFF ..'
16+
coverity-cmake-command: 'cmake -DCMAKE_CXX_STANDARD=20 -DENABLE_SIO=ON -DENABLE_JULIA=ON -DUSE_EXTERNAL_CATCH2=OFF ..'
1717
coverity-project: 'AIDASoft%2Fpodio'
1818
coverity-project-token: ${{ secrets.PODIO_COVERITY_TOKEN }}
1919
github-pat: ${{ secrets.READ_COVERITY_IMAGE }}

.github/workflows/edm4hep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
echo "::group::Build Catch2"
3939
cd $STARTDIR/catch2
4040
mkdir build && cd build
41-
cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=../install -G Ninja ..
41+
cmake -DCMAKE_CXX_STANDARD=20 -DCMAKE_INSTALL_PREFIX=../install -G Ninja ..
4242
ninja -k0 install
4343
export CMAKE_PREFIX_PATH=$STARTDIR/catch2/install:$CMAKE_PREFIX_PATH
4444
echo "::endgroup::"

.github/workflows/key4hep.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
cmake -DENABLE_SIO=ON \
3131
-DENABLE_JULIA=OFF \
3232
-DCMAKE_INSTALL_PREFIX=../install \
33-
-DCMAKE_CXX_STANDARD=17 \
33+
-DCMAKE_CXX_STANDARD=20 \
3434
-DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always -Werror -Wno-error=deprecated-declarations " \
3535
-DUSE_EXTERNAL_CATCH2=AUTO \
3636
-DENABLE_RNTUPLE=ON \

.github/workflows/ubuntu.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
name: ubuntu
23

34
on:
@@ -13,8 +14,8 @@ jobs:
1314
strategy:
1415
fail-fast: false
1516
matrix:
16-
LCG: ["dev3/x86_64-ubuntu2204-gcc11-opt",
17-
"dev4/x86_64-ubuntu2204-gcc11-opt"]
17+
LCG: ["dev3/x86_64-ubuntu2404-gcc13-opt",
18+
"dev4/x86_64-ubuntu2404-gcc13-opt"]
1819
steps:
1920
- uses: actions/checkout@v4
2021
- uses: cvmfs-contrib/github-action-cvmfs@v4
@@ -30,7 +31,7 @@ jobs:
3031
-DENABLE_JULIA=ON \
3132
-DENABLE_DATASOURCE=ON \
3233
-DCMAKE_INSTALL_PREFIX=../install \
33-
-DCMAKE_CXX_STANDARD=17 \
34+
-DCMAKE_CXX_STANDARD=20 \
3435
-DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always -Werror -Wno-error=deprecated-declarations " \
3536
-DUSE_EXTERNAL_CATCH2=OFF \
3637
-DPODIO_SET_RPATH=ON \

CMakeLists.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ endif()
3636
# ``-DCMAKE_CXX_STANDARD=<standard>`` when invoking CMake
3737
set(CMAKE_CXX_STANDARD 20 CACHE STRING "")
3838

39-
if(NOT CMAKE_CXX_STANDARD MATCHES "17|20")
39+
if(NOT CMAKE_CXX_STANDARD MATCHES "20|23")
4040
message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}")
4141
endif()
4242

@@ -88,10 +88,7 @@ endif()
8888
if(ENABLE_DATASOURCE)
8989
list(APPEND root_components_needed ROOTDataFrame)
9090
endif()
91-
find_package(ROOT REQUIRED COMPONENTS ${root_components_needed})
92-
if((ENABLE_RNTUPLE) AND (${ROOT_VERSION} VERSION_LESS 6.28.02))
93-
message(FATAL_ERROR "You are trying to build podio with support for the new ROOT NTuple format, but your ROOT version is too old. Please update ROOT to at least version 6.28.02")
94-
endif()
91+
find_package(ROOT 6.28.04 REQUIRED COMPONENTS ${root_components_needed})
9592

9693
# ROOT_CXX_STANDARD was introduced in https://github.com/root-project/root/pull/6466
9794
# before that it's an empty variable so we check if it's any number > 0
@@ -112,18 +109,13 @@ else()
112109
message(STATUS "Determined ROOT c++ standard: " ${ROOT_CXX_STANDARD})
113110
endif()
114111

115-
if(ROOT_CXX_STANDARD VERSION_LESS 17)
116-
message(FATAL_ERROR "You are trying to build podio against a version of ROOT that has not been built with a sufficient c++ standard. podio requires c++17 or higher")
112+
if(ROOT_CXX_STANDARD VERSION_LESS 20)
113+
message(FATAL_ERROR "You are trying to build podio against a version of ROOT that has not been built with a sufficient c++ standard. podio requires c++20 or higher")
117114
endif()
118115
if(NOT ROOT_CXX_STANDARD VERSION_EQUAL CMAKE_CXX_STANDARD)
119116
message(WARNING "You are trying to build podio with a different c++ standard than ROOT. C++${CMAKE_CXX_STANDARD} was required but ROOT was built with C++${ROOT_CXX_STANDARD}")
120117
endif()
121118

122-
# ROOT only sets usage requirements from 6.14, so for
123-
# earlier versions need to hack in INTERFACE_INCLUDE_DIRECTORIES
124-
if(ROOT_VERSION VERSION_LESS 6.14)
125-
set_property(TARGET ROOT::Core APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}")
126-
endif()
127119
list(APPEND PODIO_IO_HANDLERS ROOT)
128120

129121
# python setup (including python package discovery and install dir)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use a recent LCG or Key4hep stack release.
1818

1919
On Mac OS or Ubuntu, you need to install the following software.
2020

21-
### ROOT 6.08.06
21+
### ROOT 6.28.04
2222

23-
Install ROOT 6.08.06 (or later) and set up your ROOT environment:
23+
Install ROOT 6.28.04 (or later) built with c++20 support and set up your ROOT environment:
2424

2525
source <root_path>/bin/thisroot.sh
2626

cmake/podioConfig.cmake.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ endif()
4949
if(NOT TARGET podio::podio)
5050
include("${CMAKE_CURRENT_LIST_DIR}/podioTargets.cmake")
5151
include("${CMAKE_CURRENT_LIST_DIR}/podioMacros.cmake")
52-
53-
# ROOT only sets usage requirements from 6.14, so for
54-
# earlier versions need to hack in INTERFACE_INCLUDE_DIRECTORIES
55-
if(ROOT_VERSION VERSION_LESS 6.14)
56-
set_property(TARGET podio::podio APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}")
57-
endif()
5852
endif()
5953

6054
check_required_components(podio)

doc/frame.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Some compilers and static code analysis tools are able to detect the accidental
3535
3636
For putting in parameters the basic principle is very similar, with the major difference being, that for *trivial* types `getParameter` will actually return by value.
3737
38-
For all use cases there is some `enable_if` machinery in place to ensure that only valid collections and valid parameter types can actually be used.
39-
These checks also make sure that it is impossible to put in collections without handing over ownership to the `Frame`.
38+
For all use cases there is a concept requirement to ensure that only valid collections and valid parameter types can actually be used.
39+
Additional checks also make sure that it is impossible to put in collections without handing over ownership to the `Frame`.
4040
4141
### Usage examples for collection data
4242
These are a few very basic usage examples that highlight the main functionality (and potential pitfalls).

doc/links.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,27 +236,27 @@ default handle types. This is ensured through `static_assert`s in the
236236
`GetDefaultHandleType` helper templates are used to retrieve the correct type
237237
from any `FromT` regardless of whether it is a mutable or a default handle type
238238
With this in mind, effectively all mutating operations on `Link`s are
239-
defined using [*SFINAE*](https://en.cppreference.com/w/cpp/language/sfinae)
240-
using the following template structure (taking here `setFrom` as an example)
239+
defined using the following template structure (taking here `setFrom` as an example)
241240

242241
```cpp
243-
template <typename FromU,
244-
typename = std::enable_if_t<Mutable &&
245-
std::is_same_v<detail::GetDefaultHandleType<FromU>, FromT>>>
242+
template <typename FromU>
243+
requires(Mutable && std::is_same_v<detail::GetDefaultHandleType<FromU>, FromT> &&
244+
detail::isDefaultHandleType<FromU>)
246245
void setFrom(FromU value);
247246
```
248247

249-
This is a SFINAE friendly way to ensure that this definition is only viable if
250-
the following conditions are met
251-
- The object this method is called on has to be `Mutable`. (first part inside the `std::enable_if`)
252-
- The passed in `value` is either a `Mutable` or default class of type `FromT`. (second part inside the `std::enable_if`)
248+
Compilation will fail unless the following conditions are met
249+
- The object this method is called on has to be `Mutable`.
250+
- The passed in `value` is either a `Mutable` or default class of type `FromT`.
253251

254252
In some cases the template signature looks like this
255253

256254
```cpp
257-
template<bool Mut = Mutable,
258-
typename = std::enable_if<Mut && Mutable>>
259-
void setWeight(float weight);
255+
template <bool Mut = Mutable>
256+
requires(Mut && Mutable)
257+
void setWeight(float value) {
258+
m_obj->data.weight = value;
259+
}
260260
```
261261

262262
The reason to have a defaulted `bool` template parameter here is the same as the

0 commit comments

Comments
 (0)