Project
Loading...
Searching...
No Matches
test_StaticFor.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>
13
15#include "Framework/StaticFor.h"
16
17using namespace o2::framework;
18
19template <int someNumber>
21{
22 INFO("calling function with non-type template argument " << someNumber);
23}
24
25TEST_CASE("TestStaticFor")
26{
27 // check if it is actually static
28 static_for<0, 0>([&](auto i) {
29 static_assert(std::same_as<decltype(i), std::integral_constant<int, 0>>);
30
31 static_assert(std::same_as<decltype(i.value), const int>);
32 REQUIRE(i.value == 0);
33 REQUIRE(i == 0);
34
35 // the following checks will fail
36 // static_assert(std::same_as<decltype(i), std::integral_constant<int, 1>>);
37 // REQUIRE(i.value == 1);;
38 // REQUIRE(i == 1);;
39 });
40
41 // dont start at 0
42 static_for<5, 5>([&](auto i) {
43 static_assert(std::same_as<decltype(i), std::integral_constant<int, 5>>);
44 });
45
46 // check if argument can be used as non-type template argument
47 static_for<0, 2>([&](auto i) {
48 dummyFunc<i>();
49 dummyFunc<i.value>();
50 constexpr auto index = i.value;
51 dummyFunc<index>();
52 });
53
54 // use static loop in combination with CONST_STR
55 static constexpr std::string_view staticNames[] = {"Bob", "Alice", "Eve"};
56 static_for<0, 2>([&](auto i) {
57 constexpr int index = i.value;
58
59 // compiler will complain if constexpr is not enforced for index access:
60
61 constexpr auto sayHello = CONST_STR("Hello ") + CONST_STR(staticNames[index]);
62
63 INFO(sayHello.str);
64 });
65}
int32_t i
#define CONST_STR(literal)
GLuint index
Definition glcorearb.h:781
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
void dummyFunc()