fmt
Loading...
Searching...
No Matches
ranges.cppm File Reference
module fmt

Formatters for ranges, tuples and maps. More...

#include "fmt/macros.hpp"
#include <cerrno>
#include <climits>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <version>
import fmt:format;
import std;

Classes

class  fmt::detail::IsMap< T >
class  fmt::detail::IsSet< T >
struct  fmt::detail::HasMemberFnBeginEndT< T, Enable >
struct  fmt::detail::HasMemberFnBeginEndT< T, void_t< decltype(*std::declval< T >().begin()), decltype(std::declval< T >().end())> >
struct  fmt::detail::HasConstBeginEnd< T, Enable >
struct  fmt::detail::HasMutableBeginEnd< T, Enable >
struct  fmt::detail::HasConstBeginEnd< T, void_t< decltype(*detail::rangeBegin(std::declval< const remove_cvref_t< T > & >())), decltype(detail::rangeEnd(std::declval< const remove_cvref_t< T > & >()))> >
struct  fmt::detail::HasMutableBeginEnd< T, void_t< decltype(*detail::rangeBegin(std::declval< T & >())), decltype(detail::rangeEnd(std::declval< T & >())), int > >
struct  fmt::detail::IsRange< T, _ >
struct  fmt::detail::IsRange< T, void >
class  fmt::detail::IsTupleLike< T >
struct  fmt::detail::IsOptionalLike< T, _ >
struct  fmt::detail::IsOptionalLike< T, void_t< decltype(std::declval< T >().has_value()), decltype(std::declval< T >().value())> >
class  fmt::detail::IsTupleFormattable< T, C, bool >
class  fmt::detail::IsTupleFormattable< T, C, true >
struct  fmt::detail::RangeFormatKind< T >
struct  fmt::detail::ParseEmptySpecs< Char >
struct  fmt::detail::FormatTupleElement< FormatContext >
struct  fmt::IsTupleLike< T >
struct  fmt::IsTupleFormattable< T, C >
struct  fmt::Formatter< Tuple, Char, enable_if_t< fmt::IsTupleLike< Tuple >::value &&fmt::IsTupleFormattable< Tuple, Char >::value > >
struct  fmt::IsRange< T, Char >
struct  fmt::detail::IsFormattableDelayed< R, Char >
struct  fmt::Conjunction<... >
struct  fmt::Conjunction< P >
struct  fmt::Conjunction< P1, Pn... >
struct  fmt::RangeFormatter< T, Char, enable_if_t< Conjunction< std::is_same< T, remove_cvref_t< T > >, IsFormattable< T, Char > >::value > >
struct  fmt::RangeFormatKind< T, Char, Enable >
struct  fmt::Formatter< R, Char, enable_if_t< Conjunction< bool_constant< RangeFormatKind< R, Char >::value !=RangeFormat::disabled &&RangeFormatKind< R, Char >::value !=RangeFormat::map &&RangeFormatKind< R, Char >::value !=RangeFormat::string &&RangeFormatKind< R, Char >::value !=RangeFormat::debug_string >, detail::IsFormattableDelayed< R, Char > >::value > >
struct  fmt::Formatter< R, Char, enable_if_t< Conjunction< bool_constant< RangeFormatKind< R, Char >::value==RangeFormat::map >, detail::IsFormattableDelayed< R, Char > >::value > >
struct  fmt::Formatter< R, Char, enable_if_t< RangeFormatKind< R, Char >::value==RangeFormat::string||RangeFormatKind< R, Char >::value==RangeFormat::debug_string > >
struct  fmt::JoinView< It, Sentinel, Char >
struct  fmt::Formatter< JoinView< It, Sentinel, Char >, Char >
struct  fmt::TupleJoinView< Tuple, Char >
struct  fmt::Formatter< TupleJoinView< Tuple, Char >, Char, enable_if_t< IsTupleLike< Tuple >::value > >
struct  fmt::detail::All< Container >
struct  fmt::IsContainerAdaptor< T >
struct  fmt::Formatter< T, Char, enable_if_t< Conjunction< IsContainerAdaptor< T >, bool_constant< RangeFormatKind< T, Char >::value==RangeFormat::disabled > >::value > >

Typedefs

template<typename T, T... N>
using fmt::detail::integer_sequence = std::integer_sequence<T, N...>
template<size_t... N>
using fmt::detail::index_sequence = std::index_sequence<N...>
template<size_t N>
using fmt::detail::make_index_sequence = std::make_index_sequence<N>
template<typename T>
using fmt::detail::TupleIndexSequence
template<typename Char, typename... T>
using fmt::detail::tuple::result_t = std::tuple<Formatter<remove_cvref_t<T>, Char>...>
template<typename Range>
using fmt::detail::RangeReferenceType
template<typename Range>
using fmt::detail::UncvrefType = remove_cvref_t<RangeReferenceType<Range>>
template<RangeFormat K>
using fmt::detail::RangeFormatConstant = std::integral_constant<RangeFormat, K>
template<typename Char, typename Element>
using fmt::detail::RangeFormatterType = Formatter<remove_cvref_t<Element>, Char>
template<typename R>
using fmt::detail::MaybeConstRange

Enumerations

enum class  fmt::RangeFormat : int {
  disabled = 0 , map = 1 , set = 2 , sequence = 3 ,
  string = 4 , debug_string = 5
}

Functions

template<typename T, size_t N>
auto fmt::detail::rangeBegin (const T(&arr)[N]) -> const T *
template<typename T, size_t N>
auto fmt::detail::rangeEnd (const T(&arr)[N]) -> const T *
template<typename T>
constexpr auto fmt::detail::rangeBegin (T &&rng) -> decltype(static_cast< T && >(rng).begin())
template<typename T>
constexpr auto fmt::detail::rangeEnd (T &&rng) -> decltype(static_cast< T && >(rng).end())
template<typename T>
auto fmt::detail::rangeBegin (T &&rng) -> enable_if_t<!HasMemberFnBeginEndT< T && >::value, decltype(begin(static_cast< T && >(rng)))>
template<typename T>
auto fmt::detail::rangeEnd (T &&rng) -> enable_if_t<!HasMemberFnBeginEndT< T && >::value, decltype(end(static_cast< T && >(rng)))>
template<typename Tuple, typename F, size_t... Is>
constexpr auto fmt::detail::forEach (index_sequence< Is... >, Tuple &&t, F &&f) -> void
template<typename Tuple, typename F>
constexpr auto fmt::detail::forEach (Tuple &&t, F &&f) -> void
template<typename Tuple1, typename Tuple2, typename F, size_t... Is>
auto fmt::detail::forEach2 (index_sequence< Is... >, Tuple1 &&t1, Tuple2 &&t2, F &&f) -> void
template<typename Tuple1, typename Tuple2, typename F>
auto fmt::detail::forEach2 (Tuple1 &&t1, Tuple2 &&t2, F &&f) -> void
template<typename Tuple, typename Char, size_t... Is>
auto fmt::detail::tuple::getFormatters (index_sequence< Is... >) -> result_t< Char, decltype(get< Is >(std::declval< Tuple >()))... >
template<typename It, typename Sentinel>
auto fmt::join (It begin, Sentinel end, StringView sep) -> JoinView< It, Sentinel >
template<typename Range>
requires (!IsTupleLike<Range>::value)
constexpr auto fmt::join (Range &&r, StringView sep) -> JoinView< decltype(detail::rangeBegin(r)), decltype(detail::rangeEnd(r))>
template<typename Tuple>
requires (IsTupleLike<Tuple>::value)
constexpr auto fmt::join (const Tuple &tuple FMT_LIFETIMEBOUND, StringView sep) -> TupleJoinView< Tuple, char >
template<typename T>
auto fmt::join (std::initializer_list< T > list, StringView sep) -> JoinView< const T *, const T * >

Detailed Description

Formatters for ranges, tuples and maps.

Interface partition fmt:ranges.

Typedef Documentation

◆ MaybeConstRange

template<typename R>
using fmt::detail::MaybeConstRange
Initial value:
conditional_t<HasConstBeginEnd<R>::value, const R, R>

◆ RangeReferenceType

template<typename Range>
using fmt::detail::RangeReferenceType
Initial value:
decltype(*detail::rangeBegin(std::declval<Range&>()))

◆ TupleIndexSequence

template<typename T>
using fmt::detail::TupleIndexSequence
Initial value:
make_index_sequence<std::tuple_size<T>::value>

Enumeration Type Documentation

◆ RangeFormat

enum class fmt::RangeFormat : int
exportstrong

How a range should be formatted.

  • disabled: the type is not formatted as a range.
  • map: as {k: v, ...}, for map-like ranges.
  • set: as {a, b, ...}, for set-like ranges.
  • sequence: as [a, b, ...], the default for other ranges.
  • string: as a string.
  • debug_string: as a quoted, escaped string.
See also
range_format_kind to select the kind for a type.

Function Documentation

◆ join() [1/4]

template<typename Tuple>
requires (IsTupleLike<Tuple>::value)
auto fmt::join ( const Tuple &tuple FMT_LIFETIMEBOUND,
StringView sep ) -> TupleJoinView< Tuple, char >
constexprexport

Returns a view that formats a tuple with elements separated by sep.

Format specifiers apply to every element, so they must be valid for all of them.

Parameters
tuplethe tuple to join. The view refers to it, so it must outlive the formatting call.
septhe separator written between elements.
Returns
a view to pass to a formatting function.

Example:

auto t = std::tuple<int, char>(1, 'a');
fmt::print("{}", fmt::join(t, ", "));  // 1, a

◆ join() [2/4]

template<typename It, typename Sentinel>
auto fmt::join ( It begin,
Sentinel end,
StringView sep ) -> JoinView< It, Sentinel >
export

Returns a view that formats the iterator range [begin, end) with elements separated by sep.

Parameters
beginthe first element.
endthe sentinel marking the end of the range.
septhe separator written between elements.
Returns
a view to pass to a formatting function.
See also
join(Range&&, StringView) for the container overload.

◆ join() [3/4]

template<typename Range>
requires (!IsTupleLike<Range>::value)
auto fmt::join ( Range && r,
StringView sep ) -> JoinView< decltype(detail::rangeBegin(r)), decltype(detail::rangeEnd(r))>
constexprexport

Returns a view that formats r with elements separated by sep.

Unlike formatting the range directly, this writes no brackets and applies any format specifiers to each element rather than to the range as a whole.

Parameters
rthe range to join. The view refers to it, so it must outlive the formatting call; joining a temporary dangles.
septhe separator written between elements.
Returns
a view to pass to a formatting function.

Example:

auto v = std::vector<int>{1, 2, 3};
fmt::print("{}", fmt::join(v, ", "));    // 1, 2, 3
fmt::print("{:02}", fmt::join(v, ", "));  // 01, 02, 03

◆ join() [4/4]

template<typename T>
auto fmt::join ( std::initializer_list< T > list,
StringView sep ) -> JoinView< const T *, const T * >
export

Returns a view that formats an initializer list with elements separated by sep.

Deprecated
Use the range overload with a named container instead; the list is a temporary and the view does not extend its lifetime.
Parameters
listthe elements to join.
septhe separator written between elements.