proxygen
IStream.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <istream>
19 #include <string>
20 
21 #include <folly/gen/Core.h>
22 
23 namespace folly {
24 namespace gen {
25 namespace detail {
26 
30 class IStreamByLine : public GenImpl<std::string&&, IStreamByLine> {
31  public:
32  IStreamByLine(std::istream& in) : in_(in) {}
33 
34  template <class Body>
35  bool apply(Body&& body) const {
36  for (std::string line; std::getline(in_, line);) {
37  if (!body(std::move(line))) {
38  return false;
39  }
40  }
41  return true;
42  }
43 
44  // Technically, there could be infinite files (e.g. /dev/random), but people
45  // who open those can do so at their own risk.
46  static constexpr bool infinite = false;
47 
48  private:
49  std::istream& in_;
50 };
51 
52 } // namespace detail
53 
54 inline detail::IStreamByLine byLine(std::istream& in) {
55  return detail::IStreamByLine(in);
56 }
57 
58 } // namespace gen
59 } // namespace folly
IStreamByLine(std::istream &in)
Definition: IStream.h:32
bool apply(Body &&body) const
Definition: IStream.h:35
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void BENCHFUN() getline(size_t iters, size_t arg)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
auto byLine(File file, char delim= '\n')
Definition: File-inl.h:148
static constexpr bool infinite
Definition: IStream.h:46
const char * string
Definition: Conv.cpp:212