Skip to content

Commit

Permalink
Change the format to C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Nov 18, 2024
1 parent 83c21e9 commit f8f329d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
Standard: c++20
TabWidth: 8
UseTab: Never
...
58 changes: 36 additions & 22 deletions include/podio/detail/Link.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class LinkT {

/// Implicit conversion of mutable to immutable links
template <typename FromU, typename ToU>
requires Mutable&& sameTypes<FromU, ToU> operator LinkT<FromU, ToU, false>() const {
requires Mutable && sameTypes<FromU, ToU>
operator LinkT<FromU, ToU, false>() const {
return Link<FromU, ToU>(m_obj);
}

Expand All @@ -88,7 +89,8 @@ class LinkT {
/// @returns A mutable deep-copy of this link which is independent of the
/// original one
template <typename FromU = FromT, typename ToU = ToT>
requires sameTypes<FromU, ToU> MutableLink<FromU, ToU> clone(bool cloneRelations = true) const {
requires sameTypes<FromU, ToU>
MutableLink<FromU, ToU> clone(bool cloneRelations = true) const {
auto tmp = new LinkObjT(podio::ObjectID{}, m_obj->data);
if (cloneRelations) {
if (m_obj->m_from) {
Expand All @@ -103,7 +105,8 @@ class LinkT {

/// Create an empty Link handle
template <bool Mut = Mutable>
requires(!Mut && !Mutable) static Link<FromT, ToT> makeEmpty() {
requires(!Mut && !Mutable)
static Link<FromT, ToT> makeEmpty() {
return {nullptr};
}

Expand All @@ -117,7 +120,8 @@ class LinkT {

/// Set the weight of the link
template <bool Mut = Mutable>
requires(Mut&& Mutable) void setWeight(float value) {
requires(Mut && Mutable)
void setWeight(float value) {
m_obj->data.weight = value;
}

Expand All @@ -135,8 +139,9 @@ class LinkT {
/// at compile time. We need to differentiate between the handles, only to
/// make the python bindings work
template <typename FromU>
requires(Mutable&& std::is_same_v<detail::GetDefaultHandleType<FromU>, FromT>&&
detail::isDefaultHandleType<FromU>) void setFrom(FromU value) {
requires(Mutable && std::is_same_v<detail::GetDefaultHandleType<FromU>, FromT> &&
detail::isDefaultHandleType<FromU>)
void setFrom(FromU value) {
m_obj->m_from = std::make_unique<detail::GetDefaultHandleType<FromU>>(value);
}

Expand All @@ -146,8 +151,9 @@ class LinkT {
/// at compile time. We need to differentiate between the handles, only to
/// make the python bindings work
template <typename FromU>
requires(Mutable&& std::is_same_v<detail::GetMutableHandleType<FromT>, FromU>&&
detail::isMutableHandleType<FromU>) void setFrom(FromU value) {
requires(Mutable && std::is_same_v<detail::GetMutableHandleType<FromT>, FromU> &&
detail::isMutableHandleType<FromU>)
void setFrom(FromU value) {
setFrom(detail::GetDefaultHandleType<FromU>(value));
}

Expand All @@ -157,7 +163,8 @@ class LinkT {
/// at compile time. We need this overload to allow for an implicit conversion
/// to interface types in case the relation contains an interface type.
template <typename FromU>
requires(Mutable&& detail::isInterfaceInitializableFrom<FromT, FromU>) void setFrom(FromU value) {
requires(Mutable && detail::isInterfaceInitializableFrom<FromT, FromU>)
void setFrom(FromU value) {
setFrom(FromT(value));
}

Expand All @@ -175,8 +182,8 @@ class LinkT {
/// at compile time. We need to differentiate between the handles, only to
/// make the python bindings work
template <typename ToU>
requires(Mutable&& std::is_same_v<detail::GetDefaultHandleType<ToU>, ToT>&&
detail::isDefaultHandleType<ToU>) void setTo(ToU value) {
requires(Mutable && std::is_same_v<detail::GetDefaultHandleType<ToU>, ToT> && detail::isDefaultHandleType<ToU>)
void setTo(ToU value) {
m_obj->m_to = std::make_unique<detail::GetDefaultHandleType<ToU>>(value);
}

Expand All @@ -186,8 +193,8 @@ class LinkT {
/// at compile time. We need to differentiate between the handles, only to
/// make the python bindings work
template <typename ToU>
requires(Mutable&& std::is_same_v<detail::GetMutableHandleType<ToT>, ToU>&&
detail::isMutableHandleType<ToU>) void setTo(ToU value) {
requires(Mutable && std::is_same_v<detail::GetMutableHandleType<ToT>, ToU> && detail::isMutableHandleType<ToU>)
void setTo(ToU value) {
setTo(detail::GetDefaultHandleType<ToU>(value));
}

Expand All @@ -197,7 +204,8 @@ class LinkT {
/// at compile time. We need this overload to allow for an implicit conversion
/// to interface types in case the relation contains an interface type.
template <typename ToU>
requires(Mutable&& detail::isInterfaceInitializableFrom<ToT, ToU>) void setTo(ToU value) {
requires(Mutable && detail::isInterfaceInitializableFrom<ToT, ToU>)
void setTo(ToU value) {
setTo(ToT(value));
}

Expand All @@ -210,7 +218,8 @@ class LinkT {
/// @tparam T the desired type
/// @returns T the element of the Link
template <typename T>
requires(!std::is_same_v<ToT, FromT> && isFromOrToT<T>) T get() const {
requires(!std::is_same_v<ToT, FromT> && isFromOrToT<T>)
T get() const {
if constexpr (std::is_same_v<T, FromT>) {
return getFrom();
} else {
Expand All @@ -228,7 +237,8 @@ class LinkT {
/// - 1: The To element of the Link
/// - 2: The weight of the Link
template <size_t Index>
requires(Index < 3) auto get() const {
requires(Index < 3)
auto get() const {
if constexpr (Index == 0) {
return getFrom();
} else if constexpr (Index == 1) {
Expand All @@ -246,9 +256,10 @@ class LinkT {
/// @tparam T type of value (**inferred!**)
/// @param value the element to set for this link.
template <typename T>
requires(Mutable && !std::is_same_v<ToT, FromT> &&
(isMutableFromOrToT<T> || detail::isInterfaceInitializableFrom<ToT, T> ||
detail::isInterfaceInitializableFrom<FromT, T>)) void set(T value) {
requires(Mutable && !std::is_same_v<ToT, FromT> &&
(isMutableFromOrToT<T> || detail::isInterfaceInitializableFrom<ToT, T> ||
detail::isInterfaceInitializableFrom<FromT, T>))
void set(T value) {
if constexpr (std::is_same_v<T, FromT>) {
setFrom(std::move(value));
} else {
Expand Down Expand Up @@ -287,12 +298,14 @@ class LinkT {
}

template <typename FromU, typename ToU>
requires sameTypes<FromU, ToU> bool operator==(const LinkT<FromU, ToU, !Mutable>& other) const {
requires sameTypes<FromU, ToU>
bool operator==(const LinkT<FromU, ToU, !Mutable>& other) const {
return m_obj == other.m_obj;
}

template <typename FromU, typename ToU>
requires sameTypes<FromU, ToU> bool operator!=(const LinkT<FromU, ToU, !Mutable>& other) const {
requires sameTypes<FromU, ToU>
bool operator!=(const LinkT<FromU, ToU, !Mutable>& other) const {
return !(*this == other);
}

Expand All @@ -311,7 +324,8 @@ class LinkT {
}

template <bool Mut = Mutable>
requires(!Mut && !Mutable) LinkT(LinkObjT* obj) : m_obj(podio::utils::MaybeSharedPtr<LinkObjT>(obj)) {
requires(!Mut && !Mutable)
LinkT(LinkObjT* obj) : m_obj(podio::utils::MaybeSharedPtr<LinkObjT>(obj)) {
}

podio::utils::MaybeSharedPtr<LinkObjT> m_obj{nullptr};
Expand Down
4 changes: 1 addition & 3 deletions include/podio/utilities/TypeHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ namespace det {
using detected_or = detail::detector<DefT, void, Op, Args...>;

template <template <typename...> typename Op, typename... Args>
constexpr bool is_detected_v = requires {
typename Op<Args...>;
};
constexpr bool is_detected_v = requires { typename Op<Args...>; };

} // namespace det

Expand Down

0 comments on commit f8f329d

Please sign in to comment.