Difference between revisions of "C++20"

From Inkscape Wiki
Jump to navigation Jump to search
m (Mark std::views as unavailable on Apple clang)
(Mark as usable std::make_unique_for_overwrite, ranges and heterogenous lookup)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:


See also [[C++11]], [[C++17]].
See also [[C++11]], [[C++17]], [[C++23]].


Some things that will be interesting to use once C++20 is common:
Some things that will be interesting to use once C++20 is common:
Line 10: Line 10:
| <code>std::span</code>            || C++20 || style="background: lightgreen;" | from 1.4  || 10    || 11.0.3 || Handle buffers like standard library containers without risk of overflow.
| <code>std::span</code>            || C++20 || style="background: lightgreen;" | from 1.4  || 10    || 11.0.3 || Handle buffers like standard library containers without risk of overflow.
|-
|-
| <code>std::format</code>          || C++20 || style="background: pink;"       |           || 13    || N/A    || Better and more efficient formatting of strings. [https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html Text Formatting]
| <code>std::format</code>          || C++20 || style="background: lightgreen;" | from 1.5 || 13    || 15.3  || Better and more efficient formatting of strings. [https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html Text Formatting]
|-
|-
| <code>std::lerp</code>            || C++20 || style="background: lightgreen;" | from 1.4  ||  9    || 11.0.3 || Linear interpolation. (ui/tools/pencil-tool.cpp)
| <code>std::lerp</code>            || C++20 || style="background: lightgreen;" | from 1.4  ||  9    || 11.0.3 || Linear interpolation. (ui/tools/pencil-tool.cpp)
|-
|-
| <code>std::bit_floor</code>      || C++20 || style="background: lightgreen;" | from 1.4  || 9/10  || 11.0.3/13.0.0 || Compute floor(log2(x)). (helper/mathfns.h)
| <code>std::bit_floor</code>      || C++20 || style="background: lightgreen;" | from 1.4  || 9/10  || 11.0.3/13.0.0 || Compute <code>floor(log2(x))</code>. (helper/mathfns.h)
|-
|-
| <code>Concepts</code>            || C++20 ||                                   from 1.4? || 6/10  || 12.0.0 Partial || Safer templating. (ui/controller.h)
| Concepts                         || C++20 || style="background: lightgreen;" | from 1.5 || 6/10  || 12.0.0 Partial || Safer templating. (ui/controller.h)
|-
|-
| <code>Coroutines</code>          || C++20 ||                                             || 10    || 10.0.1 Partial || Simpler asynchronous code. (trace/trace.cpp)
| Coroutines                       || C++20 || style="background: lightgreen;" | from 1.5 || 10    || 10.0.1 Partial,<br/> 15.3 Full || Simpler asynchronous code. (trace/trace.cpp)
|-
|-
| <code>std::make_unique_for_overwrite</code> || C++20 || style="background: pink;" |       || 11    || N/A    || Don't zero arrays allocated using std::make_unique. (util/pool.cpp)
| <code>std::make_unique_for_overwrite</code>
                                    || C++20 || style="background: lightgreen;" | from 1.5 || 11    || 15.0.0 || Don't zero arrays allocated using std::make_unique. (util/pool.cpp)
|-
|-
| <code>Ranges</code>              || C++20 || style="background: pink;" |       from 1.4? ||        || ?     || for (init; decl : expr). (ui/dialog/swatches.cpp)
| Ranges                           || C++20 || style="background: lightgreen;" | from 1.5 ||        || ? || (ui/dialog/swatches.cpp)
|-
|-
| <code>[https://stackoverflow.com/a/60244416/5075760 Structural templates]</code> || C++20 || from 1.4? ||   || Partial     || Allow instances of arbitrary literal classes as template parameters. (display/drawing.cpp)
| [https://stackoverflow.com/a/60244416/5075760 Structural templates]
                                    || C++20 ||                                   from 1.4? ||       || Partial || Allow instances of arbitrary literal classes as template parameters. (display/drawing.cpp)
|-
|-
| <code>Mathematical Constants</code>|| C++20 ||                                           || 10     || 12.0.5 || Constants like std::numbers::pi.    
| Mathematical Constants           || C++20 ||                                             || 10     || 12.0.5 || Constants like <code>std::numbers::pi</code>.
|-
| Heterogenous lookup in <code>std::unordered_map</code>
                                    || C++20 || style="background: lightgreen;" | from 1.5 ||        ||        || Faster lookup, use of smart pointers as keys.
|-
|<code>consteval static</code> member functions
|C++20
| style="background: pink;" | not yet
|
|
|Guaranteed compile time evaluation of member functions (stronger than <code>constexpr</code>)
|}
|}


As of 6 September 2023, the CI runners for:
References:
* Linux:
** appimage:linux GNU 10.5 (Building on "oldest supported Ubuntu LTS release", we must wait until April 2025 to use a newer GNU version!) Note: Gtkmm4 is not available in Ubuntu 20.04 or 22.04!
** inkscape:linux GNU 11.4.0
* Windows
** inkscape:windows:build Gnu 13.1.0
** inkscape:windows:dist Same as above.
* macOS:
** inkscape::macos:arm Apple Clang 13.1.6
** inkscape:macos:x64: Apple Clang 14.0.0.


* General: https://en.cppreference.com/w/Template:cpp/compiler_support/20
* Apple Clang: https://developer.apple.com/documentation/xcode-release-notes


We strive to support lastest Debian stable and latest Ubuntu LTS. But this may not be possible for a gtk4 based release. Ideally, we would target gtkmm4 4.10 as it has a critical scrolling bug fix.
As of 21 September 2025, the CI runners for the various supported platforms are
* Linux: GCC 13.3.0 (on Ubuntu 24.04)
* Windows: GCC 15.1.0
* macOS: Apple Clang 17.0.0
* Android: Clang 19.0.0 (on Ubuntu 24.04)
 
We support the latest Debian stable and latest Ubuntu LTS.
{| class="wikitable"
{| class="wikitable"
|-
|-
! Distro                        || gcc    || clang  || gtkmm4
! Distro                        || gcc    || clang  || glib || glibmm || gtk4 || gtkmm4
|-
|-
| Debian 12 (Bookworm, stable)  || 12.2.0 || 15.0.6 || 4.8.3
| Debian 13 (Trixie)             || 14.2.0 || 19.0   || 2.84.4 || 2.84.0 || 4.18.6 || 4.18.0
|-
|-
| Ubuntu 22.04 (Jammy Jellyfish) || 12.3.0 || 15.0.7 || Not packaged!
| Ubuntu 24.04 (Noble)           || 13.3.0 || 18.1.3 || 2.80.0 || 2.78.1 || 4.14.2 || style="background: wheat;" | 4.10.1
|-
| Ubuntu 23.04 (Lunar)          || 13.1.0 || 16.0.0 || 4.10.1
|}
|}


Errors and Deprecated items that we use:
The build requires glibmm >= 2.78.1 and gtkmm4 >= 4.14, however Inkscape will compile its own gtkmm4 if the system version is too old, so building on Ubuntu 24.04 still works out of the box.
* error: call of overloaded ‘lerp(double, double&, double&)’ is ambiguous  (ui/knot/knot-holder-entity.cpp)
 
Deprecated items that we still use:
* warning: implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20 [-Wdeprecated] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0806r2.html
* warning: implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20 [-Wdeprecated] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0806r2.html
* warning: bitwise operation between different enumeration types ‘Box3D::Axis’ and ‘Box3D::FrontOrRear’ is deprecated [-Wdeprecated-enum-enum-conversion]
* warning: bitwise operation between different enumeration types ‘Box3D::Axis’ and ‘Box3D::FrontOrRear’ is deprecated [-Wdeprecated-enum-enum-conversion]

Latest revision as of 21:16, 21 September 2025

See also C++11, C++17, C++23.

Some things that will be interesting to use once C++20 is common:

Feature Since Can use? GCC Apple Clang Comment
std::span C++20 from 1.4 10 11.0.3 Handle buffers like standard library containers without risk of overflow.
std::format C++20 from 1.5 13 15.3 Better and more efficient formatting of strings. Text Formatting
std::lerp C++20 from 1.4 9 11.0.3 Linear interpolation. (ui/tools/pencil-tool.cpp)
std::bit_floor C++20 from 1.4 9/10 11.0.3/13.0.0 Compute floor(log2(x)). (helper/mathfns.h)
Concepts C++20 from 1.5 6/10 12.0.0 Partial Safer templating. (ui/controller.h)
Coroutines C++20 from 1.5 10 10.0.1 Partial,
15.3 Full
Simpler asynchronous code. (trace/trace.cpp)
std::make_unique_for_overwrite C++20 from 1.5 11 15.0.0 Don't zero arrays allocated using std::make_unique. (util/pool.cpp)
Ranges C++20 from 1.5 ? (ui/dialog/swatches.cpp)
Structural templates C++20 from 1.4? Partial Allow instances of arbitrary literal classes as template parameters. (display/drawing.cpp)
Mathematical Constants C++20 10 12.0.5 Constants like std::numbers::pi.
Heterogenous lookup in std::unordered_map C++20 from 1.5 Faster lookup, use of smart pointers as keys.
consteval static member functions C++20 not yet Guaranteed compile time evaluation of member functions (stronger than constexpr)

References:

As of 21 September 2025, the CI runners for the various supported platforms are

  • Linux: GCC 13.3.0 (on Ubuntu 24.04)
  • Windows: GCC 15.1.0
  • macOS: Apple Clang 17.0.0
  • Android: Clang 19.0.0 (on Ubuntu 24.04)

We support the latest Debian stable and latest Ubuntu LTS.

Distro gcc clang glib glibmm gtk4 gtkmm4
Debian 13 (Trixie) 14.2.0 19.0 2.84.4 2.84.0 4.18.6 4.18.0
Ubuntu 24.04 (Noble) 13.3.0 18.1.3 2.80.0 2.78.1 4.14.2 4.10.1

The build requires glibmm >= 2.78.1 and gtkmm4 >= 4.14, however Inkscape will compile its own gtkmm4 if the system version is too old, so building on Ubuntu 24.04 still works out of the box.

Deprecated items that we still use: