Files
swift-mirror/stdlib/core/LogicValue.swift
Chris Lattner 8991456ff2 Switch infix/postfix/prefix to be declaration modifiers instead of attributes,
eliminating the @'s from them when used on func's.  This is progress towards
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword

This also consolidates rejection of custom operator definitions into one
place and makes it consistent, and adds postfix "?" to the list of rejected
operators.

This also changes the demangler to demangle weak/inout/postfix and related things
without the @.



Swift SVN r19929
2014-07-14 15:51:49 +00:00

39 lines
1.4 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// BooleanType
//===----------------------------------------------------------------------===//
public prefix func !<T : BooleanType>(a: T) -> Bool {
return !a.getLogicValue()
}
// Short circuiting logical operators.
// FIXME: these operators should be fully generic
// BLOCKED ON: <rdar://problem/13251236> [remapping bound function type not
// implemented yet (deduced closure types)].
//
// FIXME: the generic versions of these operators probably shouldn't
// be @transparent; ideally they will be overloaded with transparent
// bool-specific operators. BLOCKED ON: <rdar://problem/11510876>
// [Implement overload resolution].
@transparent public
func &&(lhs: BooleanType, rhs: @auto_closure () -> BooleanType) -> Bool {
return lhs.getLogicValue() ? rhs().getLogicValue() : false
}
@transparent public
func ||(lhs: BooleanType, rhs: @auto_closure () -> BooleanType) -> Bool {
return lhs.getLogicValue() ? true : rhs().getLogicValue()
}