Commit 48bc9653 authored by Tom Jackson's avatar Tom Jackson Committed by Peter Griess

Move byLine to FileGen.h, add explanatory note

Summary: There's a bit of a gotcha here, let's provide at least a note on this.

Test Plan: Unit tests

Reviewed By: tudorb@fb.com

FB internal diff: D1058244
parent a57c72d7
...@@ -120,13 +120,19 @@ class FileWriter : public Operator<FileWriter> { ...@@ -120,13 +120,19 @@ class FileWriter : public Operator<FileWriter> {
std::unique_ptr<IOBuf> buffer_; std::unique_ptr<IOBuf> buffer_;
}; };
} // namespace detail } // !detail
/**
inline auto byLine(File file, char delim='\n') -> * Generator which reads lines from a file.
decltype(fromFile(std::move(file)) | eachAs<StringPiece>() | resplit(delim)) { * Note: This produces StringPieces which reference temporary strings which are
return fromFile(std::move(file)) | eachAs<StringPiece>() | resplit(delim); * only valid during iteration.
*/
inline auto byLine(File file, char delim = '\n')
-> decltype(fromFile(std::move(file))
| eachAs<StringPiece>()
| resplit(delim)) {
return fromFile(std::move(file))
| eachAs<StringPiece>()
| resplit(delim);
} }
} // namespace gen }} // !folly::gen
} // namespace folly
...@@ -65,8 +65,7 @@ S toFile(File file, std::unique_ptr<IOBuf> buffer) { ...@@ -65,8 +65,7 @@ S toFile(File file, std::unique_ptr<IOBuf> buffer) {
return S(std::move(file), std::move(buffer)); return S(std::move(file), std::move(buffer));
} }
} // namespace gen }} // !folly::gen
} // namespace folly
#include "folly/experimental/FileGen-inl.h" #include "folly/experimental/FileGen-inl.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment