dexonsmith added a comment.

I think th eAPI is designed to ensure users don't forget to check the error 
code.

What about a new API/iterator type that wraps the existing one and has a 
"normal" `operator++`?

- Take an error as an out-parameter on construction
- Make it an `llvm::Error` which guarantees a crash if not checked
- This would wrap the other type and store a reference to the `Error`. If 
there's an error during iteration, advances to end and sets the error.

Here's what I'm thinking:

  Optional<llvm::Error> DirError;
  for (vfs::error_directory_iterator File = D.getVFS().dir_begin(Cand.Path, 
DirError),
                                     FileEnd;
       File != FileEnd; ++File) {
    // ...
  }
  if (DirError)
    return errorToErrorCode(std::move(*IterationEC));

At that point, it'd be easy to add a `dir_range` wrapper that creates an 
iterator range:

  for (auto &File : dir_range(Path, DirError)) {
    // ...
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116659/new/

https://reviews.llvm.org/D116659

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D116659: [... Duncan P. N. Exon Smith via Phabricator via cfe-commits

Reply via email to