proxygen
folly::gen::detail::SplitTo< TargetContainer, Delimiter, Targets > Class Template Reference

#include <String-inl.h>

Public Member Functions

 SplitTo (Delimiter delimiter)
 
TargetContainer operator() (StringPiece line) const
 

Private Attributes

Delimiter delimiter_
 

Detailed Description

template<class TargetContainer, class Delimiter, class... Targets>
class folly::gen::detail::SplitTo< TargetContainer, Delimiter, Targets >

ParseToTuple - For splitting a record and immediatlely converting it to a target tuple type. Primary used through the 'eachToTuple' helper, like so:

auto config = split("1:a 2:b", ' ') | eachToTuple<int, string>() | as<vector<tuple<int, string>>>();

Definition at line 377 of file String-inl.h.

Constructor & Destructor Documentation

template<class TargetContainer , class Delimiter , class... Targets>
folly::gen::detail::SplitTo< TargetContainer, Delimiter, Targets >::SplitTo ( Delimiter  delimiter)
inlineexplicit

Definition at line 381 of file String-inl.h.

381 : delimiter_(delimiter) {}

Member Function Documentation

template<class TargetContainer , class Delimiter , class... Targets>
TargetContainer folly::gen::detail::SplitTo< TargetContainer, Delimiter, Targets >::operator() ( StringPiece  line) const
inline

Definition at line 383 of file String-inl.h.

References FOLLY_POP_WARNING, i, and folly::gen::split().

383  {
384  int i = 0;
385  StringPiece fields[sizeof...(Targets)];
386  // HACK(tjackson): Used for referencing fields[] corresponding to variadic
387  // template parameters.
388  auto eatField = [&]() -> StringPiece& { return fields[i++]; };
389  if (!split(
390  delimiter_,
391  line,
392  detail::passthrough<StringPiece&, Targets>(eatField())...)) {
393  throw std::runtime_error("field count mismatch");
394  }
395  i = 0;
396  return TargetContainer(To<Targets>()(eatField())...);
397  }
S split(const StringPiece source, char delimiter)
Definition: String.h:61
Range< const char * > StringPiece

Member Data Documentation

template<class TargetContainer , class Delimiter , class... Targets>
Delimiter folly::gen::detail::SplitTo< TargetContainer, Delimiter, Targets >::delimiter_
private

Definition at line 378 of file String-inl.h.


The documentation for this class was generated from the following file: