Try to split a string into a fixed number of fields by delimiter, using folly::tryTo<> for conversions. types by delimiter. ‐ On success, all output values will be initialized and the 'Unit{}' value is returned. Arguments are assigned in reverse order. ‐ On failure, the first failing 'ConversionCode' is returned with its associated substring in a 'SubstringConversionCode'. ‐ String splitting is performed prior to each conversion; field values will not contain the delimiter. ‐ All custom error codes are mapped to ConversionCode::CUSTOM.

Synopsis

Declared in <folly/String.h>

template<
    class Delim,
    class... OutputTypes>
requires StrictConjunction<IsConvertible<OutputTypes>...>::value
Expected<Unit, SubstringConversionCode>
trySplitTo(
    StringPiece input,
    Delim const& delimiter,
    OutputTypes&... outputs);

Description

Examples:

folly::StringPiece name, key, value; if (folly::trySplitTo(line, 't', name, key, value)) ...

folly::StringPiece name; double value; int id; if (folly::trySplitTo(line, 't', name, value, id)) ...

Return Value

Unit on success, or the first conversion error on failure.

Parameters

Name

Description

input

The string to split.

delimiter

The delimiter to split on.

outputs

The output fields to populate, in reverse order.

Created with MrDocs