My Project
|
The bsl::fmt implements a similar syntax to that of std::format, We adopt a similar approach with some tweaks of course to ensure AUTOSAR compliance include: More...
#include <fmt.hpp>
Public Member Functions | |
constexpr | fmt (fmt_options const &ops, V const &val) noexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string. More... | |
constexpr | fmt (fmt_options const &ops, V const &val, bsl::uintmax width) noexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string. Note that this version also accepts a dynamic width, meaning the width can be determined at runtime. If the width is provided, the width in the format string is ignored. More... | |
constexpr | fmt (cstr_type const str, V const &val) noexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string. More... | |
constexpr | fmt (cstr_type const str, V const &val, bsl::uintmax const width) noexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string. Note that this version also accepts a dynamic width, meaning the width can be determined at runtime. If the width is provided, the width in the format string is ignored. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T , typename U > | |
constexpr out< T > | operator<< (out< T > const o, fmt< U > &&arg) noexcept |
Outputs the provided formatted argument to the provided output type. More... | |
template<typename T , typename U > | |
constexpr out< T > | operator<< (out< T > const o, fmt< U > &&arg) noexcept |
Outputs the provided formatted argument to the provided output type. If you want to provide your own custom outputter, DO NOT overload this function. Instead, overload the fmt_impl function. More... | |
template<typename T , typename U , enable_if_t<!is_bool< U >::value, bool > = true, enable_if_t<!is_same< U, char_type >::value, bool > = true, enable_if_t<!is_pointer< U >::value, bool > = true, enable_if_t<!is_integral< U >::value, bool > = true, enable_if_t<!is_null_pointer< U >::value, bool > = true> | |
constexpr out< T > | operator<< (out< T > const o, U const &arg) noexcept |
Outputs the provided argument to the provided output type. If you want to provide your own custom outputter, DO NOT overload this function. Instead, overload the fmt_impl function. More... | |
The bsl::fmt implements a similar syntax to that of std::format, We adopt a similar approach with some tweaks of course to ensure AUTOSAR compliance include:
General Syntax:
The sign, # and 0 options are only valid when an integer type is being formatted.
Rules for Optional Field [fill-and-align]:
The fill-and-align option tells bsl::fmt how to align the resulting output. The fill states what character should be used as padding (defaults to a space), and can be any character (except for '\0' which would result in UB). The align character determines the type of justification (either left, right or center). If the width field is missing, the fill-and-align field has no effect. In addition, if this field is combined with the '0' sign aware field, this field has no effect.
Results in the following output:
Rules for Optional Field [sign]:
The sign option states how an integer type should display its positive or negative sign.
Results in the following output:
Rules for Optional Field [#]:
The # option enables the alternative form for integer types. If the type field is missing, this option is ignored.
Results in the following output:
Rules for Optional Field [0]:
The 0 option enables the use of sign aware 0 padding. If this field is combined with the fill-and-align field, the fill-and-align field is ignored. The problem with fill-and-align is that if you want to, for example, output the hexidecimal number 0x2A as 0x002A, there is no way to do that with fill-and-align as the 0s would be on the wrong side of '0x'. Therefore, this option ignores fill-and-align and instead uses the width field to determine how many 0s to add to the output in the correct position within the output. Like fill-and-align, if the width field is missing, this option has no effect.
Results in the following output:
Rules for Optional Field [width]:
Unlike std::format, negative numbers are not supported. The width field determines the total length of the resulting output, with all options included. In addition, the bsl::fmt library supports dynamic width as well. If the dynamic width is provided, this field is ignored and the dynamic width is used instead.
Results in the following output:
type rules [bool]:
If bsl::fmt{} is given a boolean, the type field indicates the following:
Results in the following output:
type rules [bsl::char_type]:
If bsl::fmt{} is given a bsl::char_type, the type field indicates the following:
Results in the following output:
type rules [bsl::cstr_type]:
If bsl::fmt{} is given a bsl::cstr_type, the type field indicates the following:
Results in the following output:
type rules [integral]:
If bsl::fmt{} is given an integral type, the type field indicates the following:
Results in the following output:
For all other types, the BSL provides the "<<" syntax, but the use of bsl::fmt is not supported.
If you wish to implement support for your own types, you can do so why overloading the following function in the "bsl" namespace
You can also overload the following if you wish to provide output support but do not wish to provide bsl::fmt{} support (this option will result in more efficient code):
V | the type of value being formatted for output |
|
inlinenoexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string.
ops | the format options used to format the output of val |
val | the value to output given the provided format string |
|
inlinenoexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string. Note that this version also accepts a dynamic width, meaning the width can be determined at runtime. If the width is provided, the width in the format string is ignored.
ops | the format options used to format the output of val |
val | the value to output given the provided format string |
width | a dynamic width which overrides the width field in the format string (used to set the width field at runtime). |
|
inlinenoexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string.
str | the format options used to format the output of val |
val | the value to output given the provided format string |
|
inlinenoexcept |
Creates a bsl::fmt, which when passed to an outputter will output the provided value given the provided format string. Note that this version also accepts a dynamic width, meaning the width can be determined at runtime. If the width is provided, the width in the format string is ignored.
str | the format options used to format the output of val |
val | the value to output given the provided format string |
width | a dynamic width which overrides the width field in the format string (used to set the width field at runtime). |
|
friend |
Outputs the provided formatted argument to the provided output type.
T | the type of outputter provided |
U | the type of value being ouputter using bsl::fmt |
o | the instance of the outputter used to output the value. |
arg | a bsl::fmt that contains the value being outputted as well as any format instructions. |
|
related |
Outputs the provided formatted argument to the provided output type. If you want to provide your own custom outputter, DO NOT overload this function. Instead, overload the fmt_impl function.
T | the type of outputter provided |
U | the type of value being ouputter using bsl::fmt |
o | the instance of the outputter used to output the value. |
arg | a bsl::fmt that contains the value being outputted as well as any format instructions. |
|
related |
Outputs the provided argument to the provided output type. If you want to provide your own custom outputter, DO NOT overload this function. Instead, overload the fmt_impl function.
T | the type of outputter provided |
U | the type of value being ouputter using bsl::fmt |
o | the instance of the outputter used to output the value. |
arg | the value to output |