From: Tom Jackson Date: Thu, 14 Nov 2013 23:41:09 +0000 (-0800) Subject: Move byLine to FileGen.h, add explanatory note X-Git-Tag: v0.22.0~800 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=48bc965369f889754c1cff956f56747a480f1003;p=folly.git 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 --- diff --git a/folly/experimental/FileGen-inl.h b/folly/experimental/FileGen-inl.h index 21b0589c..d28966b7 100644 --- a/folly/experimental/FileGen-inl.h +++ b/folly/experimental/FileGen-inl.h @@ -120,13 +120,19 @@ class FileWriter : public Operator { std::unique_ptr buffer_; }; -} // namespace detail - -inline auto byLine(File file, char delim='\n') -> -decltype(fromFile(std::move(file)) | eachAs() | resplit(delim)) { - return fromFile(std::move(file)) | eachAs() | resplit(delim); +} // !detail +/** + * Generator which reads lines from a file. + * Note: This produces StringPieces which reference temporary strings which are + * only valid during iteration. + */ +inline auto byLine(File file, char delim = '\n') + -> decltype(fromFile(std::move(file)) + | eachAs() + | resplit(delim)) { + return fromFile(std::move(file)) + | eachAs() + | resplit(delim); } -} // namespace gen -} // namespace folly - +}} // !folly::gen diff --git a/folly/experimental/FileGen.h b/folly/experimental/FileGen.h index 234b0c18..35d98355 100644 --- a/folly/experimental/FileGen.h +++ b/folly/experimental/FileGen.h @@ -65,8 +65,7 @@ S toFile(File file, std::unique_ptr buffer) { return S(std::move(file), std::move(buffer)); } -} // namespace gen -} // namespace folly +}} // !folly::gen #include "folly/experimental/FileGen-inl.h"