Doug Gregor 4823a260fd
Guard macro declarations behind hasFeature(Macros) (#1071)
To enable building this package with a "minimal" Swift toolchain whose
compiler does not have support for macros, guard the macro declarations
behind `#if hasFeature(Macros)`. This has no effect on anything but the
toolchain bootstrap process.
2024-12-05 11:24:06 -08:00

35 lines
1.5 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@available(FoundationPredicate 0.4, *)
public struct Expression<each Input, Output> : Sendable {
public let expression : any StandardPredicateExpression<Output>
public let variable: (repeat PredicateExpressions.Variable<each Input>)
public init(_ builder: (repeat PredicateExpressions.Variable<each Input>) -> any StandardPredicateExpression<Output>) {
self.variable = (repeat PredicateExpressions.Variable<each Input>())
self.expression = builder(repeat each variable)
}
public func evaluate(_ input: repeat each Input) throws -> Output {
try expression.evaluate(
.init(repeat (each variable, each input))
)
}
}
#if hasFeature(Macros)
@freestanding(expression)
@available(FoundationPredicate 0.4, *)
public macro Expression<each Input, Output>(_ body: (repeat each Input) -> Output) -> Expression<repeat each Input, Output> = #externalMacro(module: "FoundationMacros", type: "ExpressionMacro")
#endif