1 //===--- LazyDetector.h - Lazy ToolChain Detection --------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
12 #include "clang/Driver/Tool.h"
13 #include "clang/Driver/ToolChain.h"
18 /// Simple wrapper for toolchain detector with costly initialization. This
19 /// delays the creation of the actual detector until its first usage.
21 template <class T
> class LazyDetector
{
22 const driver::Driver
&D
;
24 const llvm::opt::ArgList
&Args
;
26 std::optional
<T
> Detector
;
29 LazyDetector(const driver::Driver
&D
, const llvm::Triple
&Triple
,
30 const llvm::opt::ArgList
&Args
)
31 : D(D
), Triple(Triple
), Args(Args
) {}
34 Detector
.emplace(D
, Triple
, Args
);
37 const T
*operator->() const {
38 return const_cast<T
const *>(
39 const_cast<LazyDetector
&>(*this).operator->());
43 } // end namespace clang
45 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H