blob: 48ef25f96924ffeae64ec0a2895883403fb3c052 [file] [log] [blame]
Wyatt Heplerc542a5d2020-01-15 15:43:10 -08001.. _chapter-pw-polyfill:
2
3.. default-domain:: cpp
4
5.. highlight:: sh
6
7-----------
8pw_polyfill
9-----------
Armando Montanez0054a9b2020-03-13 13:06:24 -070010The ``pw_polyfill`` module backports C++17 features to C++11 and C++14.
Wyatt Heplerc542a5d2020-01-15 15:43:10 -080011
12Compatibility
13=============
14C++11
15
16Features
17========
18
19Adapt code to compile with older versions of C++
20------------------------------------------------
Armando Montanez0054a9b2020-03-13 13:06:24 -070021The ``pw_polyfill`` module provides features for adapting C++17 code to work
22when compiled with older C++ standards.
Wyatt Heplerc542a5d2020-01-15 15:43:10 -080023
24 - ``pw_polyfill/standard.h`` -- provides a macro for checking the C++ standard
25 - ``pw_polyfill/language_features.h`` -- provides macros for adapting code to
26 work without newer language features
27 - ``pw_polyfill/standard_library/`` -- adapters for C++ standard library
28 features, such as ``std::byte``, ``std::size``/``std::data``, and type
29 traits convenience aliases
30
31In GN, Bazel, or CMake, depend on ``$dir_pw_polyfill``, ``//pw_polyfill``,
32or ``pw_polyfill``, respectively. In other build systems, add
33``pw_polyfill/standard_library_public`` and ``pw_polyfill/public_overrides`` as
34include paths.
35
36Override C++ standard library headers
37-------------------------------------
38The headers in ``public_overrides`` provide wrappers for C++ standard library
39headers, including ``<cstddef>``, ``<iterator>``, ``<type_traits>``. These are
40provided through the ``"$dir_pw_polyfill:overrides"`` library, which the GN
41build adds as a dependency for all targets. This makes some C++17 library
42features available to targets compiled with older C++ standards, without needing
43to change the code.
44
45To apply overrides in Bazel or CMake, depend on the
46``//pw_polyfill:overrides`` or ``pw_polyfill.overrides`` targets. In other build
47systems, add ``pw_polyfill/standard_library_public`` and
48``pw_polyfill/public_overrides`` as include paths.