aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/vespa/eval/eval/check_type.h
blob: 0502d5acbc4c85a0e49f0bb03ecd61bb1dc4feaf (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "node_visitor.h"

namespace vespalib {
namespace eval {
namespace nodes {

/**
 * A templated visitor used to check if the visited node matches any
 * of the given types.
 **/

template <typename... TYPES> struct CheckTypeVisitor;

template <>
struct CheckTypeVisitor<> : EmptyNodeVisitor {
    bool result = false;
};

template <typename HEAD, typename... TAIL>
struct CheckTypeVisitor<HEAD, TAIL...> : CheckTypeVisitor<TAIL...> {
    virtual void visit(const HEAD &) override { this->result = true; }
};

template <typename... TYPES>
bool check_type(const nodes::Node &node) {
    CheckTypeVisitor<TYPES...> check;
    node.accept(check);
    return check.result;
}

} // namespace vespalib::eval::nodes
} // namespace vespalib::eval
} // namespace vespalib