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 | ----------- |
| 10 | The pw_polyfill module backports C++17 features to C++11 and C++14. |
| 11 | |
| 12 | Compatibility |
| 13 | ============= |
| 14 | C++11 |
| 15 | |
| 16 | Features |
| 17 | ======== |
| 18 | |
| 19 | Adapt code to compile with older versions of C++ |
| 20 | ------------------------------------------------ |
| 21 | The pw_polyfill module provides features for adapting C++17 code to work when |
| 22 | compiled with older C++ standards. |
| 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. |