| 1 | //===- llvm/ADT/SmallVectorExtras.h -----------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// This file defines less commonly used SmallVector utilities. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_ADT_SMALLVECTOREXTRAS_H |
| 15 | #define |
| 16 | |
| 17 | #include "llvm/ADT/STLExtras.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | /// Filter a range to a SmallVector with the element types deduced. |
| 23 | template <unsigned Size, class ContainerTy, class PredicateFn> |
| 24 | auto filter_to_vector(ContainerTy &&C, PredicateFn &&Pred) { |
| 25 | return to_vector<Size>(make_filter_range(std::forward<ContainerTy>(C), |
| 26 | std::forward<PredicateFn>(Pred))); |
| 27 | } |
| 28 | |
| 29 | /// Filter a range to a SmallVector with the element types deduced. |
| 30 | template <class ContainerTy, class PredicateFn> |
| 31 | auto filter_to_vector(ContainerTy &&C, PredicateFn &&Pred) { |
| 32 | return to_vector(make_filter_range(std::forward<ContainerTy>(C), |
| 33 | std::forward<PredicateFn>(Pred))); |
| 34 | } |
| 35 | |
| 36 | /// Map a range to a SmallVector with element types deduced from the mapping. |
| 37 | template <unsigned Size, class ContainerTy, class FuncTy> |
| 38 | auto map_to_vector(ContainerTy &&C, FuncTy &&F) { |
| 39 | return to_vector<Size>( |
| 40 | map_range(std::forward<ContainerTy>(C), std::forward<FuncTy>(F))); |
| 41 | } |
| 42 | |
| 43 | /// Map a range to a SmallVector with element types deduced from the mapping. |
| 44 | template <class ContainerTy, class FuncTy> |
| 45 | auto map_to_vector(ContainerTy &&C, FuncTy &&F) { |
| 46 | return to_vector( |
| 47 | map_range(std::forward<ContainerTy>(C), std::forward<FuncTy>(F))); |
| 48 | } |
| 49 | |
| 50 | } // namespace llvm |
| 51 | |
| 52 | #endif // LLVM_ADT_SMALLVECTOREXTRAS_H |
| 53 | |