Skip to content

Commit 47e4c3f

Browse files
committed
base_of_template concept
1 parent 506607e commit 47e4c3f

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,29 +1704,29 @@ static constexpr auto haveKey(framework::pack<C...>, std::string const& key)
17041704
void notFoundColumn(const char* label, const char* key);
17051705
void missingOptionalPreslice(const char* label, const char* key);
17061706

1707-
template <soa::soa_table T, bool OPT = false>
1708-
static constexpr std::string getLabelFromTypeForKey(std::string const& key)
1709-
{
1710-
if constexpr (soa::is_type_with_originals_v<std::decay_t<T>>) {
1711-
using Os = typename std::decay_t<T>::originals;
1712-
auto locate = haveKey(Os{}, key);
1713-
auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1714-
if (it != locate.end()) {
1715-
return it->second;
1716-
}
1717-
} else {
1718-
auto locate = hasKey<std::decay_t<T>>(key);
1719-
if (locate.first) {
1720-
return locate.second;
1721-
}
1722-
}
1723-
if constexpr (!OPT) {
1724-
notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
1725-
} else {
1726-
return "[MISSING]";
1727-
}
1728-
O2_BUILTIN_UNREACHABLE();
1729-
}
1707+
// template <soa::soa_table T, bool OPT = false>
1708+
// static constexpr std::string getLabelFromTypeForKey(std::string const& key)
1709+
// {
1710+
// if constexpr (soa::is_type_with_originals_v<std::decay_t<T>>) {
1711+
// using Os = typename std::decay_t<T>::originals;
1712+
// auto locate = haveKey(Os{}, key);
1713+
// auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1714+
// if (it != locate.end()) {
1715+
// return it->second;
1716+
// }
1717+
// } else {
1718+
// auto locate = hasKey<std::decay_t<T>>(key);
1719+
// if (locate.first) {
1720+
// return locate.second;
1721+
// }
1722+
// }
1723+
// if constexpr (!OPT) {
1724+
// notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
1725+
// } else {
1726+
// return "[MISSING]";
1727+
// }
1728+
// O2_BUILTIN_UNREACHABLE();
1729+
// }
17301730

17311731
template <with_originals T, bool OPT = false>
17321732
static constexpr std::string getLabelFromTypeForKey(std::string const& key)

Framework/Core/include/Framework/ConfigParamRegistry.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ class ConfigParamRegistry
9090
return mStore->store().get<std::string>(key);
9191
} else if constexpr (std::is_same_v<T, std::string_view>) {
9292
return std::string_view{mStore->store().get<std::string>(key)};
93-
} else if constexpr (is_base_of_template_v<std::vector, T>) {
93+
} else if constexpr (base_of_template<std::vector, T>) {
9494
return vectorFromBranch<typename T::value_type>(mStore->store().get_child(key));
95-
} else if constexpr (is_base_of_template_v<o2::framework::Array2D, T>) {
95+
} else if constexpr (base_of_template<o2::framework::Array2D, T>) {
9696
return array2DFromBranch<typename T::element_t>(mStore->store().get_child(key));
97-
} else if constexpr (is_base_of_template_v<o2::framework::LabeledArray, T>) {
97+
} else if constexpr (base_of_template<o2::framework::LabeledArray, T>) {
9898
return labeledArrayFromBranch<typename T::element_t>(mStore->store().get_child(key));
9999
} else if constexpr (std::is_same_v<T, boost::property_tree::ptree>) {
100100
return mStore->store().get_child(key);

Framework/Foundation/include/Framework/Traits.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,27 @@ struct always_static_assert : std::false_type {
4141
template <typename... T>
4242
inline constexpr bool always_static_assert_v = always_static_assert<T...>::value;
4343

44-
template <template <typename...> class base, typename derived>
45-
struct is_base_of_template_impl {
46-
template <typename... Ts>
47-
static constexpr std::true_type test(const base<Ts...>*);
48-
static constexpr std::false_type test(...);
49-
using type = decltype(test(std::declval<derived*>()));
50-
};
44+
// template <template <typename...> class base, typename derived>
45+
// struct is_base_of_template_impl {
46+
// template <typename... Ts>
47+
// static constexpr std::true_type test(const base<Ts...>*);
48+
// static constexpr std::false_type test(...);
49+
// using type = decltype(test(std::declval<derived*>()));
50+
// };
51+
52+
// template <template <typename...> class base, typename derived>
53+
// using is_base_of_template = typename is_base_of_template_impl<base, derived>::type;
5154

52-
template <template <typename...> class base, typename derived>
53-
using is_base_of_template = typename is_base_of_template_impl<base, derived>::type;
55+
// template <template <typename...> class base, typename derived>
56+
// inline constexpr bool is_base_of_template_v = is_base_of_template<base, derived>::value;
57+
58+
template <template <typename...> typename B, typename D>
59+
concept base_of_template = requires {
60+
[]<typename... Ts>(B<Ts...>*){ }(std::declval<D*>());
61+
};
5462

55-
template <template <typename...> class base, typename derived>
56-
inline constexpr bool is_base_of_template_v = is_base_of_template<base, derived>::value;
63+
template <template <typename...> typename B, typename D>
64+
constexpr bool is_base_of_template_v = base_of_template<B, D>;
5765

5866
} // namespace o2::framework
5967

0 commit comments

Comments
 (0)