Project
Loading...
Searching...
No Matches
test_FunctionalHelpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <catch_amalgamated.hpp>
14#include "Framework/Pack.h"
16
17using namespace o2::framework;
18
19template <typename T>
20using is_int_t = std::is_same<typename std::decay_t<T>, int>;
21
22template <typename T, typename T2>
23using is_same_as_second_t = std::is_same<typename std::decay_t<T>, T2>;
24
25template <int A, int B>
26struct TestStruct {
27};
28TEST_CASE("TestOverride")
29{
30 static_assert(pack_size(pack<int, float>{}) == 2, "Bad size for the pack");
31 static_assert(has_type<int>(pack<int, float>{}) == true, "int should be in the pack");
32 static_assert(has_type<double>(pack<int, float>{}) == false, "double should not be in the pack");
33 static_assert(has_type_v<int, pack<int, float>> == true, "int should be in the pack");
34 static_assert(has_type_v<double, pack<int, float>> == false, "double should not be in the pack");
35 static_assert(std::is_same_v<decltype(prune_voids_pack({}, pack<int, int, int, int, int, int, int, int, void>{})), pack<int, int, int, int, int, int, int, int>>, "prune last void");
36 static_assert(has_type_conditional_v<std::is_same, int, pack<int, float>> == true, "int should be in the pack");
37 static_assert(has_type_conditional_v<std::is_same, double, pack<int, float>> == false, "double should not be in the pack");
38
40 static_assert(has_type_at_v<int>(pck) == 2, "int should be at 2");
41 static_assert(has_type_at_v<double>(pck) == pack_size(pck) + 1, "double is not in the pack so the function returns size + 1");
42 static_assert(has_type_at_conditional_v<std::is_same, bool>(pack<int, float, bool>()) == 2, "bool should be at 2");
43 static_assert(has_type_at_conditional_v<std::is_same, bool>(pack<int, float, double>()) == 3 + 1, "bool is not in the pack so the function returns size + 1");
44
45 static_assert(std::is_same_v<selected_pack<is_int_t, int, float, char>, pack<int>>, "selector should select int");
46 static_assert(std::is_same_v<selected_pack<is_int_t, int, int, float, char>, pack<int, int>>, "selector should select int");
47 static_assert(std::is_same_v<selected_pack<is_int_t, float, int, int, float, char>, pack<int, int>>, "selector should select int");
48 static_assert(std::is_same_v<selected_pack_multicondition<is_same_as_second_t, pack<int>, pack<int, float, char>>, pack<int>>, "multiselector should select int");
49 static_assert(std::is_same_v<filtered_pack<is_int_t, int, float, char>, pack<float, char>>, "filter should remove int");
50 static_assert(std::is_same_v<intersected_pack_t<pack<int, float, char>, pack<float, double>>, pack<float>>, "filter intersect two packs");
51 static_assert(has_type<pack_element_t<0, pack<int>>>(pack<int>{}) == true, "foo");
52 print_pack<intersected_pack_t<pack<int>, pack<int>>>();
53 print_pack<intersected_pack_t<pack<TestStruct<0, -1>, int>, pack<TestStruct<0, -1>, float>>>();
54 static_assert(std::is_same_v<intersected_pack_t<pack<TestStruct<0, -1>, int>, pack<TestStruct<0, -1>, float>>, pack<TestStruct<0, -1>>>, "filter intersect two packs");
55 static_assert(std::is_same_v<concatenated_pack_t<pack<int, float, char>, pack<float, double>>, pack<int, float, char, float, double>>, "pack should be concatenated");
56 static_assert(std::is_same_v<concatenated_pack_t<pack<int, float, char>, pack<float, double>, pack<char, short>>, pack<int, float, char, float, double, char, short>>, "pack should be concatenated");
57
61 print_pack<p3>();
62 static_assert(std::is_same_v<p3, pack<float, bool, int, double, char>>, "pack should not have duplicated types");
63
64 static_assert(std::is_same_v<unique_pack_t<pack<int, float, int, float, char, char>>, pack<char, float, int>>, "pack should not have duplicated types");
65 static_assert(std::is_same_v<interleaved_pack_t<pack<int, float, int>, pack<char, bool, char>>, pack<int, char, float, bool, int, char>>, "interleaved packs of the same size");
66 static_assert(std::is_same_v<pack_to_tuple_t<pack<int, float, char>>, std::tuple<int, float, char>>, "pack should become a tuple");
67 static_assert(std::is_same_v<repeated_type_pack_t<float, 5>, pack<float, float, float, float, float>>, "pack should have float repeated 5 times");
68
69 struct ForwardDeclared;
70 static_assert(is_type_complete_v<ForwardDeclared> == false, "This should not be complete because the struct is simply forward declared.");
71
72 struct Declared {
73 };
74 static_assert(is_type_complete_v<Declared> == true, "This should be complete because the struct is fully declared.");
75
76 // Notice this will not work because the static assert above and the one below
77 // conflict and the first one wins. We can use is_type_complete_v only once per
78 // compilation unit.
79 //
80 // struct ForwardDeclared { int a;};
81 // static_assert(is_type_complete_v<ForwardDeclared> == true, "This should be complete because the struct is now fully declared.");
82
83 bool flag = false;
84 call_if_defined<struct Undeclared>([&flag](auto*) { flag = true; });
85 REQUIRE(flag == false);
86
87 flag = false;
88 call_if_defined<struct Declared>([&flag](auto*) { flag = true; });
89 REQUIRE(flag == true);
90}
constexpr int p2()
constexpr int p1()
constexpr to accelerate the coordinates changing
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
typename intersect_pack< S1, S2 >::type intersected_pack_t
Definition Pack.h:268
TEST_CASE("test_prepareArguments")
constexpr std::size_t pack_size(pack< Ts... > const &)
template function to determine number of types in a pack
Definition Pack.h:28
decltype(concatenate_pack_unique(Ps{}...)) concatenated_pack_unique_t
Definition Pack.h:319
consteval auto prune_voids_pack(Result result, pack<>)
Definition Pack.h:112
void print_pack()
Definition Pack.h:201
std::is_same< typename std::decay_t< T >, int > is_int_t
std::is_same< typename std::decay_t< T >, T2 > is_same_as_second_t