diff --git a/llvm/include/llvm/ADT/Visitor.h b/llvm/include/llvm/ADT/Visitor.h new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/ADT/Visitor.h @@ -0,0 +1,42 @@ +//===- llvm/ADT/Visitor.h - Visitors constructed from lambdas. --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines the Visitor class, which is a utility that constructs +// visitors from lambdas. Can be used for e.g. visiting PointerUnion. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_ADT_VISITOR_H +#define LLVM_ADT_VISITOR_H + +namespace llvm { + +template struct Visitor; + +template +struct Visitor : HEAD, Visitor { + explicit Visitor(HEAD head, TAIL... tail) + : HEAD(head), Visitor(tail...) {} + + using HEAD::operator(); + using Visitor::operator(); +}; + +template struct Visitor : HEAD { + explicit Visitor(HEAD f0) : HEAD(f0) {} + + using HEAD::operator(); +}; + +template auto makeVisitor(LAMBDAS... lambdas) { + return Visitor(lambdas...); +} + +} // namespace llvm + +#endif