File: test_ct_dispatch.cpp

package info (click to toggle)
gridtools 2.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,480 kB
  • sloc: cpp: 228,792; python: 17,561; javascript: 9,164; ansic: 4,101; sh: 850; makefile: 231; f90: 201
file content (45 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * GridTools
 *
 * Copyright (c) 2014-2023, ETH Zurich
 * All rights reserved.
 *
 * Please, refer to the LICENSE file in the root directory.
 * SPDX-License-Identifier: BSD-3-Clause
 */
#include <gridtools/common/ct_dispatch.hpp>

#include <gtest/gtest.h>

namespace gridtools {
    namespace {
        TEST(ct_dispatch, smoke) {
            auto testee = [](size_t n) { return ct_dispatch<10>([](auto n) { return decltype(n)::value; }, n); };
            for (size_t i = 0; i != 10; ++i)
                EXPECT_EQ(testee(i), i);
        }

        int counter = 0;

        int count() {
            ++counter;
            return 0;
        }

        template <size_t>
        struct foo {
            static int dummy;
        };

        template <size_t I>
        int foo<I>::dummy = count();

        void bar(int n) {
            ct_dispatch<42>([](auto n) { (void)foo<decltype(n)::value>::dummy; }, n);
        }

        // check that foo is instantiated 42 times without even calling bar.
        TEST(ct_dispatch, instantiations_number) { EXPECT_EQ(counter, 42); }

    } // namespace
} // namespace gridtools