17 #ifndef LLVM_ADT_STLEXTRAS_H
18 #define LLVM_ADT_STLEXTRAS_H
37 struct identity :
public std::unary_function<Ty, Ty> {
47 struct less_ptr :
public std::binary_function<Ty, Ty, bool> {
49 return *left < *right;
54 struct greater_ptr :
public std::binary_function<Ty, Ty, bool> {
56 return *right < *left;
68 template<
typename Ret,
typename ...Params>
70 Ret (*callback)(
intptr_t callable, Params ...params);
73 template<
typename Callable>
74 static Ret callback_fn(
intptr_t callable, Params ...params) {
75 return (*reinterpret_cast<Callable*>(callable))(
76 std::forward<Params>(params)...);
80 template <
typename Callable>
82 typename std::enable_if<
83 !std::is_same<
typename std::remove_reference<Callable>::type,
85 : callback(callback_fn<typename std::remove_reference<Callable>::type>),
86 callable(reinterpret_cast<
intptr_t>(&callable)) {}
88 return callback(callable, std::forward<Params>(params)...);
111 template <
class RootIt,
class UnaryFunc>
116 typedef typename std::iterator_traits<RootIt>::iterator_category
118 typedef typename std::iterator_traits<RootIt>::difference_type
129 inline const UnaryFunc &
getFunc()
const {
return Fn; }
132 : current(I), Fn(F) {}
174 return current == X.current;
179 return current - X.current;
183 template <
class Iterator,
class Func>
184 inline mapped_iterator<Iterator, Func>
194 template <
class ItTy,
class FuncTy>
206 template <
typename T>
bool operator()(
const T &lhs,
const T &rhs)
const {
207 return lhs.first < rhs.first;
214 template <
typename T>
bool operator()(
const T &lhs,
const T &rhs)
const {
215 return lhs.second < rhs.second;
229 template <
size_t...
I>
232 template <std::size_t
N, std::size_t...
I>
234 template <std::size_t...
I>
238 template <
class... Ts>
246 template <
class T, std::
size_t N>
254 if (std::less<T>()(*reinterpret_cast<const T*>(P1),
255 *reinterpret_cast<const T*>(P2)))
257 if (std::less<T>()(*reinterpret_cast<const T*>(P2),
258 *reinterpret_cast<const T*>(P1)))
267 (
const void*,
const void*) {
268 return array_pod_sort_comparator<T>;
286 template<
class IteratorTy>
290 auto NElts = End - Start;
291 if (NElts <= 1)
return;
295 template <
class IteratorTy>
297 IteratorTy Start, IteratorTy End,
299 const typename std::iterator_traits<IteratorTy>::value_type *,
300 const typename std::iterator_traits<IteratorTy>::value_type *)) {
303 auto NElts = End - Start;
304 if (NElts <= 1)
return;
305 qsort(&*Start, NElts,
sizeof(*Start),
306 reinterpret_cast<int (*)(
const void *,
const void *)
>(
Compare));
315 template<
typename Container>
317 for (
typename Container::iterator
I = C.begin(), E = C.end();
I != E; ++
I)
324 template<
typename Container>
326 for (
typename Container::iterator
I = C.begin(), E = C.end();
I != E; ++
I)
333 template<
typename R,
class UnaryPredicate>
336 std::forward<UnaryPredicate>(
P));
352 template <
class T,
class... Args>
353 typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
355 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
367 typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0,
368 std::unique_ptr<T>>::type
370 return std::unique_ptr<T>(
new typename std::remove_extent<T>::type[n]());
374 template <
class T,
class... Args>
375 typename std::enable_if<std::extent<T>::value != 0>::type
384 template<
typename First,
typename Second>
387 return std::hash<First>()(P.first) * 31 + std::hash<Second>()(P.second);
393 template <
typename A,
typename B>
bool operator()(
A &&a, B &&b)
const {
394 return std::forward<A>(a) < std::forward<B>(b);
400 template <
typename A,
typename B>
bool operator()(
A &&a, B &&b)
const {
401 return std::forward<A>(a) == std::forward<B>(b);
407 template <
typename T>
struct deref {
412 template <
typename A,
typename B>
416 return func(*lhs, *rhs);
void DeleteContainerSeconds(Container &C)
In a container of pairs (usually a map) whose second element is a pointer, deletes the second element...
void DeleteContainerPointers(Container &C)
For a container of pointers, deletes the pointers and then clears the container.
const Ty & operator()(const Ty &self) const
Function object to check whether the second component of a std::pair compares less than the second co...
mapped_iterator operator+(difference_type n) const
int(*)(const void *, const void *) get_array_pod_sort_comparator(const T &)
get_array_pod_sort_comparator - This is an internal helper function used to get type deduction of T r...
Ret operator()(Params...params) const
An efficient, type-erasing, non-owning reference to a callable.
A functor like C++14's std::less<void> in its absence.
UnaryFunc::result_type value_type
int array_pod_sort_comparator(const void *P1, const void *P2)
Adapt std::less<T> for array_pod_sort.
function_ref(Callable &&callable, typename std::enable_if< !std::is_same< typename std::remove_reference< Callable >::type, function_ref >::value >::type *=nullptr)
mapped_iterator(const RootIt &I, UnaryFunc F)
bool operator()(A &&a, B &&b) const
bool operator()(const T &lhs, const T &rhs) const
Alias for the common case of a sequence of size_ts.
mapped_iterator< ItTy, FuncTy > map_iterator(const ItTy &I, FuncTy F)
std::iterator_traits< RootIt >::iterator_category iterator_category
mapped_iterator & operator--()
LLVM_CONSTEXPR size_t array_lengthof(T(&)[N])
Find the length of an array.
bool operator()(A &&a, B &&b) const
std::iterator_traits< RootIt >::difference_type difference_type
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
mapped_iterator & operator++()
size_t operator()(const std::pair< First, Second > &P) const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
mapped_iterator operator++(int)
bool operator<(const mapped_iterator &X) const
Ty & operator()(Ty &self) const
value_type operator*() const
A functor like C++14's std::equal<void> in its absence.
bool operator()(const T &lhs, const T &rhs) const
const UnaryFunc & getFunc() const
mapped_iterator & operator+=(difference_type n)
Creates a compile-time integer sequence for a parameter pack.
bool operator()(const Ty *left, const Ty *right) const
difference_type operator-(const mapped_iterator &X) const
bool operator()(const Ty *left, const Ty *right) const
Represents a compile-time sequence of integers.
static LLVM_CONSTEXPR size_t size()
mapped_iterator operator--(int)
const RootIt & getCurrent() const
bool operator==(const mapped_iterator &X) const
bool operator!=(const mapped_iterator &X) const
void operator+(int, ilist_iterator< T >)=delete
bool all_of(R &&Range, UnaryPredicate &&P)
Provide wrappers to std::all_of which take ranges instead of having to pass being/end explicitly...
mapped_iterator & operator-=(difference_type n)
auto operator()(A &lhs, B &rhs) const -> decltype(func(*lhs,*rhs))
Binary functor that adapts to any other binary functor after dereferencing operands.
reference operator[](difference_type n) const
Function object to check whether the first component of a std::pair compares less than the first comp...
mapped_iterator operator-(difference_type n) const