Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

sequence
PrevUpHomeNext

Creates an object that, when formatted, applies a per-element function to a range.

Synopsis

Defined in header <boost/mysql/sequence.hpp>

template<
    class Range,
    class FormatFn>
format_sequence< sequence_range_t< Range >, typename std::decay< FormatFn >::type >
sequence(
    Range&& range,
    FormatFn&& fn,
    constant_string_view glue = ", ");
Description

Objects returned by this function satisfy Formattable. Formatting such objects invokes fn for each element in range, outputting glue between invocations. This generates an effect similar to std::ranges::views::join.

By default, this function creates an owning object by decay-copying range into it. C arrays are copied into std::array objects. This behavior can be disabled by passing std::reference_wrapper objects, which are converted to references (as std::make_tuple does). The sequence_range_t type trait accounts for these transformations.

Formally:

  • If Range is a (possibly cv-qualified) C array reference (as per std::is_array<Range>), and the array has N elements of type U, the output range type is std::array<std::remove_cv< U >, N>, and the range is created as if std::to_array was called.
  • If Range is a std::reference_wrapper< U > object, or a reference to one, the output range type is U&. This effectively disables copying the input range. The resulting object will be a view type, and the caller is responsible for lifetime management.
  • Otherwise, the output range type is std::remove_cvref_t<Range>, and it will be created by forwarding the passed range.

FormatFn is always decay-copied into the resulting object.

The glue string is always stored as a view, as it should usually point to a compile-time constant.

Type requirements

The resulting range and format function should be compatible, and any required copy/move operations should be well defined. Formally:

  • std::decay_t<FormatFn> should be a formatter function compatible with the elements of the output range. See format_sequence for the formal requirements.
  • If Range is a std::reference_wrapper< U >, or a reference to one, no further requirements are placed on U.
  • If Range is a lvalue reference to a C array, its elements should be copy-constructible (as per std::to_array requirements).
  • If Range is a rvalue reference to a C array, its elements should be move-constructible (as per std::to_array requirements).
  • Performing a decay-copy of FormatFn should be well defined.
Exception safety

Basic guarantee. Propagates any exception thrown when constructing the output range and format function.

Convenience header <boost/mysql.hpp>


PrevUpHomeNext