mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Teach IRGen how to emit thunks for SpecializeInsts that aren't immediately called and actually get used as values. This allows generic function instance to get passed around as values (again), and is a step along the way to making closures in generic contexts work (so we can specialize the local function, then partially apply its specialized context). This doesn't work yet if we specialize to local archetypes--SIL needs to learn that we need a [thick]-typed thunk for local archetype specializations, in order to pack the metadata and wtables for the local type variables. Swift SVN r5083
66 lines
2.1 KiB
C++
66 lines
2.1 KiB
C++
//===- Range.h - A lightweight pair of iterators ----------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file provides Range, a template class which makes it easy to
|
|
// turn a pair of iterators into a "collection" suitable for C++11's
|
|
// for loop.
|
|
//
|
|
// Note that this is kept in Swift because it's really only useful in
|
|
// C++11, and there aren't any major open-source subprojects of LLVM
|
|
// that can use C++11 yet.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_BASIC_RANGE_H
|
|
#define SWIFT_BASIC_RANGE_H
|
|
|
|
#include <algorithm>
|
|
#include <utility>
|
|
|
|
namespace swift {
|
|
/// A pair of iterators which can be used as the collection of a
|
|
/// C++11 for-loop.
|
|
template <typename T> class Range {
|
|
T Begin;
|
|
T End;
|
|
public:
|
|
Range(const T &begin, const T &end) : Begin(begin), End(end) {}
|
|
T begin() { return Begin; }
|
|
T end() { return End; }
|
|
bool empty() const { return Begin == End; }
|
|
};
|
|
|
|
template<typename T>
|
|
inline Range<T> make_range(const T &begin, const T &end) {
|
|
return {begin, end};
|
|
}
|
|
|
|
template<typename T>
|
|
inline auto reversed(T &&container)
|
|
-> decltype(make_range(container.rbegin(), container.rend())) {
|
|
return make_range(container.rbegin(), container.rend());
|
|
}
|
|
|
|
// Wrapper for std::transform that creates a new back-insertable container
|
|
// and transforms a range into it.
|
|
template<typename T, typename InputRange, typename MapFn>
|
|
T map(InputRange &&range, MapFn &&mapFn) {
|
|
T result;
|
|
std::transform(std::begin(range), std::end(range),
|
|
std::back_inserter(result),
|
|
std::forward<MapFn>(mapFn));
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endif
|