Replaced include/swift/Basic/Algorithm.h with calls to standard algorithms

LLVM now requires C++14, and the header says the algorithms are
backported from C++14.
This commit is contained in:
Dmitri Gribenko
2020-02-24 14:48:02 +01:00
parent d81161aa47
commit d4ff77550e
3 changed files with 4 additions and 41 deletions

View File

@@ -1,35 +0,0 @@
//===--- Algorithm.h - ------------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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
//
//===----------------------------------------------------------------------===//
//
// This file defines helper algorithms, some of which are ported from C++14,
// which may not be available on all platforms yet.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_BASIC_ALGORITHM_H
#define SWIFT_BASIC_ALGORITHM_H
namespace swift {
/// Returns the minimum of `a` and `b`, or `a` if they are equivalent.
template <typename T>
constexpr const T &min(const T &a, const T &b) {
return !(b < a) ? a : b;
}
/// Returns the maximum of `a` and `b`, or `a` if they are equivalent.
template <typename T>
constexpr const T &max(const T &a, const T &b) {
return (a < b) ? b : a;
}
} // end namespace swift
#endif // SWIFT_BASIC_ALGORITHM_H

View File

@@ -17,13 +17,12 @@
#ifndef SWIFT_BASIC_FLAGGEDPOINTER_H #ifndef SWIFT_BASIC_FLAGGEDPOINTER_H
#define SWIFT_BASIC_FLAGGEDPOINTER_H #define SWIFT_BASIC_FLAGGEDPOINTER_H
#include <algorithm>
#include <cassert> #include <cassert>
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/PointerLikeTypeTraits.h"
#include "Algorithm.h"
namespace swift { namespace swift {
/// This class implements a pair of a pointer and boolean flag. /// This class implements a pair of a pointer and boolean flag.
@@ -170,7 +169,7 @@ public:
enum { enum {
NumLowBitsAvailable = (BitPosition >= PtrTraits::NumLowBitsAvailable) NumLowBitsAvailable = (BitPosition >= PtrTraits::NumLowBitsAvailable)
? PtrTraits::NumLowBitsAvailable ? PtrTraits::NumLowBitsAvailable
: (swift::min(int(BitPosition + 1), : (std::min(int(BitPosition + 1),
int(PtrTraits::NumLowBitsAvailable)) - 1) int(PtrTraits::NumLowBitsAvailable)) - 1)
}; };
}; };

View File

@@ -34,7 +34,6 @@
#ifndef SWIFT_BASIC_PREFIXMAP_H #ifndef SWIFT_BASIC_PREFIXMAP_H
#define SWIFT_BASIC_PREFIXMAP_H #define SWIFT_BASIC_PREFIXMAP_H
#include "swift/Basic/Algorithm.h"
#include "swift/Basic/Debug.h" #include "swift/Basic/Debug.h"
#include "swift/Basic/LLVM.h" #include "swift/Basic/LLVM.h"
#include "swift/Basic/type_traits.h" #include "swift/Basic/type_traits.h"
@@ -53,8 +52,8 @@ template <class KeyElementType> class PrefixMapKeyPrinter;
/// A map whose keys are sequences of comparable values, optimized for /// A map whose keys are sequences of comparable values, optimized for
/// finding a mapped value for the longest matching initial subsequence. /// finding a mapped value for the longest matching initial subsequence.
template <class KeyElementType, class ValueType, template <class KeyElementType, class ValueType,
size_t InlineKeyCapacity size_t InlineKeyCapacity = std::max(
= max<size_t>((sizeof(void*) - 1) / sizeof(KeyElementType), 1)> (sizeof(void *) - 1) / sizeof(KeyElementType), size_t(1))>
class PrefixMap { class PrefixMap {
public: public:
using KeyType = ArrayRef<KeyElementType>; using KeyType = ArrayRef<KeyElementType>;