Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document user-defined literals #206

Merged
merged 1 commit into from
Oct 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ The Format API also supports positional arguments useful for localization:

fmt::print("I'd rather be {1} than {0}.", "right", "happy");

Named arguments can be created with ``fmt::arg``. This makes it easier to track
what goes where when multiple values are being inserted:

.. code:: c++

fmt::print("Hello, {name}! The answer is {number}. Goodbye, {name}.",
fmt::arg("name", "World"), fmt::arg("number", 42));

If your compiler supports C++11 user-defined literals, the suffix ``_a`` offers
an alternative, slightly terser syntax for named arguments:

.. code:: c++

fmt::print("Hello, {name}! The answer is {number}. Goodbye, {name}.",
"name"_a="World", "number"_a=42);

The ``_format`` suffix may be used to format string literals similar to Python:

.. code:: c++

std::string message = "{0}{1}{0}"_format("abra", "cad");

Other than the placement of the format string on the left of the operator,
``_format`` is functionally identical to ``fmt::format``. In order to use the
literal operators, they must be made visible with the directive
``using namespace fmt::literals;``. Note that this brings in only ``_a`` and
``_format`` but nothing else from the ``fmt`` namespace.

.. _write-api:

Write API
Expand Down Expand Up @@ -128,13 +156,22 @@ compilers where it has been tested and known to work:

* Mac OS X with GCC 4.2.1 and Clang 4.2, 5.1.0

* 64-bit Windows with Visual C++ 2010 and
`2013 <https://ci.appveyor.com/project/vitaut/cppformat>`_
* 64-bit Windows with Visual C++ 2010, 2013 and
`2015 <https://ci.appveyor.com/project/vitaut/cppformat>`_

* 32-bit Windows with Visual C++ 2010

Although the library uses C++11 features when available, it also works with older
compilers and standard library implementations.
compilers and standard library implementations. The only thing to keep in mind
for C++98 portability:

* Variadic templates: minimum GCC 4.4, Clang 2.9 or VS2013. This feature allow
the Format API to accept an unlimited number of arguments. With older compilers
the maximum is 15.

* User-defined literals: minimum GCC 4.7, Clang 3.1 or VS2015. The suffixes
``_format`` and ``_a`` are functionally equivalent to the functions
``fmt::format`` and ``fmt::arg``.

The output of all formatting functions is consistent across platforms. In particular,
formatting a floating-point infinity always gives ``inf`` while the output
Expand Down