[PATCH] D45166: [ELF] - Introduce helper for iterating over linker commands.

Rafael Avila de Espindola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 14:15:41 PDT 2018


espindola added a comment.

The code I have is:

  template <class CmdType> CmdType *castToCmdType(BaseCommand *Cmd) {
    return cast<CmdType>(Cmd);
  }
  template <class CmdType> bool isaCmdType(const BaseCommand *Cmd) {
    return isa<CmdType>(Cmd);
  }
  template <class CmdType>
  using Foo = llvm::filter_iterator<ArrayRef<BaseCommand *>::iterator,
                                    decltype(&isaCmdType<CmdType>)>;
  template <class CmdType>
  using Bar =
      llvm::mapped_iterator<Foo<CmdType>, decltype(castToCmdType<CmdType>) *>;
  template <class CmdType>
  llvm::iterator_range<Bar<CmdType>> filter(ArrayRef<BaseCommand *> V) {
    auto R = llvm::make_filter_range(V, isaCmdType<CmdType>);
    // FIXME: llvm should have a make_mapped_range
    auto B = map_iterator(R.begin(), castToCmdType<CmdType>);
    auto E = map_iterator(R.end(), castToCmdType<CmdType>);
    return llvm::make_range(B, E);
  }


https://reviews.llvm.org/D45166





More information about the llvm-commits mailing list