Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require C++20 and update to C++20 #698

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: cvmfs-contrib/github-action-cvmfs@v4
- uses: aidasoft/run-lcg-view@v4
with:
coverity-cmake-command: 'cmake -DCMAKE_CXX_STANDARD=17 -DENABLE_SIO=ON -DENABLE_JULIA=ON -DUSE_EXTERNAL_CATCH2=OFF ..'
coverity-cmake-command: 'cmake -DCMAKE_CXX_STANDARD=20 -DENABLE_SIO=ON -DENABLE_JULIA=ON -DUSE_EXTERNAL_CATCH2=OFF ..'
coverity-project: 'AIDASoft%2Fpodio'
coverity-project-token: ${{ secrets.PODIO_COVERITY_TOKEN }}
github-pat: ${{ secrets.READ_COVERITY_IMAGE }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/edm4hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
echo "::group::Build Catch2"
cd $STARTDIR/catch2
mkdir build && cd build
cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=../install -G Ninja ..
cmake -DCMAKE_CXX_STANDARD=20 -DCMAKE_INSTALL_PREFIX=../install -G Ninja ..
ninja -k0 install
export CMAKE_PREFIX_PATH=$STARTDIR/catch2/install:$CMAKE_PREFIX_PATH
echo "::endgroup::"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/key4hep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
cmake -DENABLE_SIO=ON \
-DENABLE_JULIA=OFF \
-DCMAKE_INSTALL_PREFIX=../install \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always -Werror -Wno-error=deprecated-declarations " \
-DUSE_EXTERNAL_CATCH2=AUTO \
-DENABLE_RNTUPLE=ON \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose gcc11 doesn't yet have enough support for the features that we need?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ROOT being built with C++17 and the check failing, I'm quite sure otherwise it would pass. I think Ubuntu24 will be there soon so maybe we can check in a few days.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. In that case we could potentially add an ubuntu workflow based on a key4hep stack?

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
-DENABLE_JULIA=ON \
-DENABLE_DATASOURCE=ON \
-DCMAKE_INSTALL_PREFIX=../install \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always -Werror -Wno-error=deprecated-declarations " \
-DUSE_EXTERNAL_CATCH2=OFF \
-DPODIO_SET_RPATH=ON \
Expand Down
13 changes: 4 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ endif()

# Set up C++ Standard
# ``-DCMAKE_CXX_STANDARD=<standard>`` when invoking CMake
set(CMAKE_CXX_STANDARD 17 CACHE STRING "")
set(CMAKE_CXX_STANDARD 20 CACHE STRING "")

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

Expand Down Expand Up @@ -108,18 +108,13 @@ else()
message(STATUS "Determined ROOT c++ standard: " ${ROOT_CXX_STANDARD})
endif()

if(ROOT_CXX_STANDARD VERSION_LESS 17)
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")
if(ROOT_CXX_STANDARD VERSION_LESS 20)
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")
endif()
if(NOT ROOT_CXX_STANDARD VERSION_EQUAL CMAKE_CXX_STANDARD)
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}")
endif()

# ROOT only sets usage requirements from 6.14, so for
# earlier versions need to hack in INTERFACE_INCLUDE_DIRECTORIES
if(ROOT_VERSION VERSION_LESS 6.14)
set_property(TARGET ROOT::Core APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}")
endif()
jmcarcell marked this conversation as resolved.
Show resolved Hide resolved
list(APPEND PODIO_IO_HANDLERS ROOT)

# python setup (including python package discovery and install dir)
Expand Down
6 changes: 0 additions & 6 deletions cmake/podioConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ endif()
if(NOT TARGET podio::podio)
include("${CMAKE_CURRENT_LIST_DIR}/podioTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/podioMacros.cmake")

# ROOT only sets usage requirements from 6.14, so for
# earlier versions need to hack in INTERFACE_INCLUDE_DIRECTORIES
if(ROOT_VERSION VERSION_LESS 6.14)
set_property(TARGET podio::podio APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}")
endif()
tmadlener marked this conversation as resolved.
Show resolved Hide resolved
endif()

check_required_components(podio)
Expand Down
13 changes: 5 additions & 8 deletions doc/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,15 @@ default handle types. This is ensured through `static_assert`s in the
`GetDefaultHandleType` helper templates are used to retrieve the correct type
from any `FromT` regardless of whether it is a mutable or a default handle type
With this in mind, effectively all mutating operations on `Link`s are
defined using [*SFINAE*](https://en.cppreference.com/w/cpp/language/sfinae)
using the following template structure (taking here `setFrom` as an example)
defined using the following template structure (taking here `setFrom` as an example)

```cpp
template <typename FromU,
typename = std::enable_if_t<Mutable &&
std::is_same_v<detail::GetDefaultHandleType<FromU>, FromT>>>
void setFrom(FromU value);
template <typename FromU>
requires(Mutable&& std::is_same_v<detail::GetDefaultHandleType<FromU>, FromT>&&
detail::isDefaultHandleType<FromU>) void setFrom(FromU value);
Comment on lines +200 to +202
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting here should match the one in the source code

```

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

Expand Down
30 changes: 13 additions & 17 deletions include/podio/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define PODIO_FRAME_H

#include "podio/CollectionBase.h"
#include "podio/CollectionBufferFactory.h"
#include "podio/CollectionIDTable.h"
#include "podio/FrameCategories.h" // mainly for convenience
#include "podio/GenericParameters.h"
Expand All @@ -23,17 +22,13 @@

namespace podio {

/// Alias template for enabling overloads only for Collections
/// Concept for enabling overloads only for Collection r-values
template <typename T>
using EnableIfCollection = typename std::enable_if_t<isCollection<T>>;
concept CollectionRValueType = collectionType<T> && !std::is_lvalue_reference_v<T>;

/// Alias template for enabling overloads only for Collection r-values
/// Concept for enabling overloads for r-values
template <typename T>
using EnableIfCollectionRValue = typename std::enable_if_t<isCollection<T> && !std::is_lvalue_reference_v<T>>;

/// Alias template for enabling overloads for r-values
template <typename T>
using EnableIfRValue = typename std::enable_if_t<!std ::is_lvalue_reference_v<T>>;
concept RValueType = !std::is_lvalue_reference_v<T>;

namespace detail {
/// The minimal interface for raw data types
Expand Down Expand Up @@ -165,7 +160,7 @@ class Frame {
/// @tparam FrameDataT Arbitrary data container that provides access to the
/// collection buffers as well as the metadata, when
/// requested by the Frame.
template <typename FrameDataT, typename = EnableIfRValue<FrameDataT>>
template <RValueType FrameDataT>
Frame(FrameDataT&&);

/// A Frame is move-only
Expand Down Expand Up @@ -193,7 +188,7 @@ class Frame {
///
/// @returns A const reference to the collection if it is available or to
/// an empty (static) collection
template <typename CollT, typename = EnableIfCollection<CollT>>
template <collectionType CollT>
const CollT& get(const std::string& name) const;

/// Get a collection pointer from the Frame by name.
Expand All @@ -218,7 +213,7 @@ class Frame {
///
/// @returns A const reference to the collection that has just been
/// inserted
template <typename CollT, typename = EnableIfCollectionRValue<CollT>>
template <CollectionRValueType CollT>
const CollT& put(CollT&& coll, const std::string& name);

/// (Destructively) move a collection into the Frame.
Expand Down Expand Up @@ -271,8 +266,9 @@ class Frame {
/// is supported by GenericParameters
/// @param key The name under which this parameter should be stored
/// @param values The values of the parameter. A copy will be put into the Frame
template <typename T, typename = std::enable_if_t<detail::isInTuple<T, SupportedGenericDataTypes>>>
inline void putParameter(const std::string& key, std::initializer_list<T>&& values) {
template <typename T>
requires detail::isInTuple<T, SupportedGenericDataTypes> inline void putParameter(const std::string& key,
std::initializer_list<T>&& values) {
putParameter<std::vector<T>>(key, std::move(values));
}

Expand Down Expand Up @@ -374,11 +370,11 @@ template <typename FrameDataT>
Frame::Frame(std::unique_ptr<FrameDataT> data) : m_self(std::make_unique<FrameModel<FrameDataT>>(std::move(data))) {
}

template <typename FrameDataT, typename>
template <RValueType FrameDataT>
Frame::Frame(FrameDataT&& data) : Frame(std::make_unique<FrameDataT>(std::move(data))) {
}

template <typename CollT, typename>
template <collectionType CollT>
const CollT& Frame::get(const std::string& name) const {
const auto* coll = dynamic_cast<const CollT*>(m_self->get(name));
if (coll) {
Expand All @@ -400,7 +396,7 @@ inline void Frame::put(std::unique_ptr<podio::CollectionBase> coll, const std::s
}
}

template <typename CollT, typename>
template <CollectionRValueType CollT>
const CollT& Frame::put(CollT&& coll, const std::string& name) {
const auto* retColl = static_cast<const CollT*>(m_self->put(std::make_unique<CollT>(std::move(coll)), name));
if (retColl) {
Expand Down
8 changes: 4 additions & 4 deletions include/podio/UserDataCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

#define PODIO_ADD_USER_TYPE(type) \
template <> \
constexpr const char* userDataTypeName<type>() { \
consteval const char* userDataTypeName<type>() { \
return #type; \
} \
template <> \
constexpr const char* userDataCollTypeName<type>() { \
consteval const char* userDataCollTypeName<type>() { \
return "podio::UserDataCollection<" #type ">"; \
}

Expand All @@ -31,12 +31,12 @@ using EnableIfSupportedUserType = std::enable_if_t<detail::isInTuple<T, Supporte
/// helper template to provide readable type names for basic types with macro
/// PODIO_ADD_USER_TYPE(type)
template <typename BasicType, typename = EnableIfSupportedUserType<BasicType>>
constexpr const char* userDataTypeName();
consteval const char* userDataTypeName();

/// Helper template to provide the fully qualified name of a UserDataCollection.
/// Implementations are populated by the PODIO_ADD_USER_TYPE macro.
template <typename BasicType, typename = EnableIfSupportedUserType<BasicType>>
constexpr const char* userDataCollTypeName();
consteval const char* userDataCollTypeName();

PODIO_ADD_USER_TYPE(float)
PODIO_ADD_USER_TYPE(double)
Expand Down
Loading
Loading