Skip to content

Commit f3794b8

Browse files
committed
DPL: move can_assign helper to the only used place
1 parent 5e6f66d commit f3794b8

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

Framework/Core/include/Framework/TypeTraits.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -220,38 +220,5 @@ struct is_boost_serializable<Type, boost::archive::binary_oarchive, std::void_t<
220220
: is_boost_serializable<typename Type::value_type, boost::archive::binary_oarchive> {
221221
};
222222

223-
/// Helper to get the corresponding std::function type for a callable object
224-
/// the default is void
225-
template <typename T>
226-
struct get_function {
227-
using type = void;
228-
};
229-
230-
/// the matching specialization builds the function type from the return type
231-
/// and types in the argument pack
232-
template <typename Ret, typename Class, typename... Args>
233-
struct get_function<Ret (Class::*)(Args...) const> {
234-
using type = std::function<Ret(Args...)>;
235-
};
236-
237-
/// check if a lambda can be assigned to concrete std::function
238-
/// default is false
239-
template <typename From, typename To, typename _ = void>
240-
struct can_assign : public std::false_type {
241-
};
242-
243-
/// specialize for callable types, i.e. having operator(), the 'From' type can be
244-
/// assigned if its corresponding function type is the same as 'To' type
245-
/// a direct comparison is not possible because lambdas are their own type
246-
template <typename From, typename To>
247-
struct can_assign<
248-
From, To,
249-
std::conditional_t<
250-
false,
251-
class_member_checker<
252-
decltype(&From::operator())>,
253-
void>> : public std::is_same<typename get_function<decltype(&From::operator())>::type, To> {
254-
};
255-
256223
} // namespace o2::framework
257224
#endif // FRAMEWORK_TYPETRAITS_H

Framework/Core/test/test_TypeTraits.cxx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,3 @@ BOOST_AUTO_TEST_CASE(TestIsSpan)
141141
BOOST_REQUIRE_EQUAL(is_span<decltype(b)>::value, false);
142142
BOOST_REQUIRE_EQUAL(is_span<decltype(c)>::value, false);
143143
}
144-
145-
BOOST_AUTO_TEST_CASE(TestCanAssign)
146-
{
147-
using Callback = std::function<bool(int, float)>;
148-
auto matching = [](int, float) -> bool {
149-
return true;
150-
};
151-
auto otherReturn = [](int, float) -> int {
152-
return 0;
153-
};
154-
auto otherParam = [](int, int) -> bool {
155-
return true;
156-
};
157-
BOOST_REQUIRE((can_assign<decltype(matching), Callback>::value == true));
158-
BOOST_REQUIRE((can_assign<decltype(otherReturn), Callback>::value == false));
159-
BOOST_REQUIRE((can_assign<decltype(otherParam), Callback>::value == false));
160-
}

Framework/Utils/include/DPLUtils/RootTreeWriter.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@ namespace o2
4040
namespace framework
4141
{
4242

43+
/// Helper to get the corresponding std::function type for a callable object
44+
/// the default is void
45+
template <typename T>
46+
struct get_function {
47+
using type = void;
48+
};
49+
50+
/// the matching specialization builds the function type from the return type
51+
/// and types in the argument pack
52+
template <typename Ret, typename Class, typename... Args>
53+
struct get_function<Ret (Class::*)(Args...) const> {
54+
using type = std::function<Ret(Args...)>;
55+
};
56+
57+
/// check if a lambda can be assigned to concrete std::function
58+
/// default is false
59+
template <typename From, typename To, typename _ = void>
60+
struct can_assign : public std::false_type {
61+
};
62+
63+
/// specialize for callable types, i.e. having operator(), the 'From' type can be
64+
/// assigned if its corresponding function type is the same as 'To' type
65+
/// a direct comparison is not possible because lambdas are their own type
66+
template <typename From, typename To>
67+
struct can_assign<
68+
From, To,
69+
std::conditional_t<
70+
false,
71+
class_member_checker<
72+
decltype(&From::operator())>,
73+
void>> : public std::is_same<typename get_function<decltype(&From::operator())>::type, To> {
74+
};
75+
4376
/// @class RootTreeWriter
4477
/// @brief A generic writer interface for ROOT TTree objects.
4578
///

Framework/Utils/test/test_RootTreeWriter.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,21 @@ BOOST_AUTO_TEST_CASE(test_RootTreeWriterSpec_store_types)
308308
// pointer type used as store type
309309
static_assert(std::is_same<Trait<std::vector<Polymorphic>>::store_type, std::vector<Polymorphic>*>::value == true);
310310
}
311+
312+
BOOST_AUTO_TEST_CASE(TestCanAssign)
313+
{
314+
using Callback = std::function<bool(int, float)>;
315+
auto matching = [](int, float) -> bool {
316+
return true;
317+
};
318+
auto otherReturn = [](int, float) -> int {
319+
return 0;
320+
};
321+
auto otherParam = [](int, int) -> bool {
322+
return true;
323+
};
324+
BOOST_REQUIRE((can_assign<decltype(matching), Callback>::value == true));
325+
BOOST_REQUIRE((can_assign<decltype(otherReturn), Callback>::value == false));
326+
BOOST_REQUIRE((can_assign<decltype(otherParam), Callback>::value == false));
327+
}
311328
} // namespace o2::test

0 commit comments

Comments
 (0)