Wyatt Hepler | c542a5d | 2020-01-15 15:43:10 -0800 | [diff] [blame] | 1 | .. _chapter-pw-polyfill: |
| 2 | |
| 3 | .. default-domain:: cpp |
| 4 | |
| 5 | .. highlight:: sh |
| 6 | |
| 7 | ----------- |
| 8 | pw_polyfill |
| 9 | ----------- |
Armando Montanez | 0054a9b | 2020-03-13 13:06:24 -0700 | [diff] [blame] | 10 | The ``pw_polyfill`` module backports C++17 features to C++11 and C++14. |
Wyatt Hepler | c542a5d | 2020-01-15 15:43:10 -0800 | [diff] [blame] | 11 | |
| 12 | Compatibility |
| 13 | ============= |
| 14 | C++11 |
| 15 | |
| 16 | Features |
| 17 | ======== |
| 18 | |
| 19 | Adapt code to compile with older versions of C++ |
| 20 | ------------------------------------------------ |
Armando Montanez | 0054a9b | 2020-03-13 13:06:24 -0700 | [diff] [blame] | 21 | The ``pw_polyfill`` module provides features for adapting C++17 code to work |
| 22 | when compiled with older C++ standards. |
Wyatt Hepler | c542a5d | 2020-01-15 15:43:10 -0800 | [diff] [blame] | 23 | |
| 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 | |
| 31 | In GN, Bazel, or CMake, depend on ``$dir_pw_polyfill``, ``//pw_polyfill``, |
| 32 | or ``pw_polyfill``, respectively. In other build systems, add |
| 33 | ``pw_polyfill/standard_library_public`` and ``pw_polyfill/public_overrides`` as |
| 34 | include paths. |
| 35 | |
| 36 | Override C++ standard library headers |
| 37 | ------------------------------------- |
| 38 | The headers in ``public_overrides`` provide wrappers for C++ standard library |
| 39 | headers, including ``<cstddef>``, ``<iterator>``, ``<type_traits>``. These are |
| 40 | provided through the ``"$dir_pw_polyfill:overrides"`` library, which the GN |
| 41 | build adds as a dependency for all targets. This makes some C++17 library |
| 42 | features available to targets compiled with older C++ standards, without needing |
| 43 | to change the code. |
| 44 | |
| 45 | To apply overrides in Bazel or CMake, depend on the |
| 46 | ``//pw_polyfill:overrides`` or ``pw_polyfill.overrides`` targets. In other build |
| 47 | systems, add ``pw_polyfill/standard_library_public`` and |
| 48 | ``pw_polyfill/public_overrides`` as include paths. |