Difference between revisions of "C++17"
Jump to navigation
Jump to search
(Add structured binding) |
|||
(10 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
This table lists C++14 and C++17 features and whether they can be used in Inkscape or not (yet). | This table lists C++14 and C++17 features and whether they can be used in Inkscape or not (yet). | ||
Add C++14 or C++17 features that you would like to use to the table, so that we know what to test for to increase the C++17 "allowance". | Add C++14 or C++17 features that you would like to use to the table, so that we know what to test for to increase the C++17 "allowance". | ||
See also [[C++11]], [[C++20]] | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 7: | Line 9: | ||
! Feature !! Since !! Can use? !! Comment | ! Feature !! Since !! Can use? !! Comment | ||
|- | |- | ||
| std::make_unique<Foo>(…) || C++14 || style="background: lightgreen;" | from 1.1 || Replaces std::unique_ptr<Foo>(new Foo(…)) | | <code>std::move</code> and rvalues || C++11 || style="background: lightgreen;" | from 1.0 || Allows passing ownership of internal resources between objects | ||
|- | |||
| <code>enum class</code> || C++11 || style="background: lightgreen;" | from 1.1 || Strong enum constants (take the name of the enum, can't be implicitly converted to <code>int</code>) | |||
|- | |||
| <code>std::make_unique<Foo>(…)</code> || C++14 || style="background: lightgreen;" | from 1.1 || Replaces <code>std::unique_ptr<Foo>(new Foo(…))</code> | |||
|- | |- | ||
| constexpr || C++14 || style="background: lightgreen;" | from 1.1 || Declares a variable as usable in a const expression | | <code>constexpr</code> || C++14 || style="background: lightgreen;" | from 1.1 || Declares a variable as usable in a const expression | ||
|- | |- | ||
| if constexpr || C++17 || style="background: lightgreen;" | from 1.1 || Guarantees the branches will be decided at compile-time | | <code>if constexpr</code> || C++17 || style="background: lightgreen;" | from 1.1 || Guarantees the branches will be decided at compile-time | ||
|- | |- | ||
| std::variant<…> || C++17 || style="background: lightgreen;" | from 1.1 || Type-safe union, where the contained type is known at runtime | | <code>std::variant<…></code> || C++17 || style="background: lightgreen;" | from 1.1 || Type-safe union, where the contained type is known at runtime | ||
|- | |- | ||
| std::optional<…> || C++17 || style="background: lightgreen;" | from 1.1 || Object type (not a pointer or reference) which can either exist or be nullopt | | <code>std::optional<…></code> || C++17 || style="background: lightgreen;" | from 1.1 || Object type (not a pointer or reference) which can either exist or be <code>std::nullopt</code> | ||
|- | |- | ||
| auto [x, y] = foo() || C++17 || style="background: lightgreen;" | from 1.1 || Structured binding, for returning more than a single value | | <code>auto [x, y] = foo();</code> || C++17 || style="background: lightgreen;" | from 1.1 || Structured binding, for returning more than a single value | ||
|- | |||
| <code>namespace A::B::C</code> || C++17 || style="background: lightgreen;" | from 1.1 || Nested namespaces | |||
|- | |||
| <code>inline static const int</code> || C++17 || style="background: lightgreen;" | from 1.1 || Inline variables (inside header files) | |||
|- | |||
| <code>std::filesystem<code> || C++17 || not yet || Filesystem library (may not be useful as we are using Gio::File). Also only supported from gcc 8, and Ubuntu 18.04 only has gcc 7. MacOS also doesn't support this. | |||
|- | |- | ||
| toxic feature of doom || || style="background: red;" | NO || Never use this (in case we stumble upon C++14/C++17 features that we really don't like) | | toxic feature of doom || || style="background: red;" | NO || Never use this (in case we stumble upon C++14/C++17 features that we really don't like) | ||
Line 37: | Line 49: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! !! GCC !! Clang | ! !! GCC !! Clang !! MSVC | ||
|- | |||
|C++17 || 7 (2017) || 4 (2017) (5 for constexpr lambda expressions) || 19.14 (2017) | |||
|- | |- | ||
|C++ | |C++20 || 10* (2020) || 10* (2020) || 19.25* | ||
|- | |- | ||
|C++ | |C++23 || 14* (2024) || 14# (2022) || 19.32# | ||
|} | |} | ||
'*' Mostly complete | '*' Mostly complete | ||
'#' About half complete | '#' About half complete |
Latest revision as of 08:44, 25 September 2024
Usage status
This table lists C++14 and C++17 features and whether they can be used in Inkscape or not (yet). Add C++14 or C++17 features that you would like to use to the table, so that we know what to test for to increase the C++17 "allowance".
Feature | Since | Can use? | Comment |
---|---|---|---|
std::move and rvalues |
C++11 | from 1.0 | Allows passing ownership of internal resources between objects |
enum class |
C++11 | from 1.1 | Strong enum constants (take the name of the enum, can't be implicitly converted to int )
|
std::make_unique<Foo>(…) |
C++14 | from 1.1 | Replaces std::unique_ptr<Foo>(new Foo(…))
|
constexpr |
C++14 | from 1.1 | Declares a variable as usable in a const expression |
if constexpr |
C++17 | from 1.1 | Guarantees the branches will be decided at compile-time |
std::variant<…> |
C++17 | from 1.1 | Type-safe union, where the contained type is known at runtime |
std::optional<…> |
C++17 | from 1.1 | Object type (not a pointer or reference) which can either exist or be std::nullopt
|
auto [x, y] = foo(); |
C++17 | from 1.1 | Structured binding, for returning more than a single value |
namespace A::B::C |
C++17 | from 1.1 | Nested namespaces |
inline static const int |
C++17 | from 1.1 | Inline variables (inside header files) |
std::filesystem |
C++17 | not yet | Filesystem library (may not be useful as we are using Gio::File). Also only supported from gcc 8, and Ubuntu 18.04 only has gcc 7. MacOS also doesn't support this. |
toxic feature of doom | NO | Never use this (in case we stumble upon C++14/C++17 features that we really don't like) |
Platform status
We need to keep coordinated with the section on Distro Dependencies.
Also see this page:
Note that __cplusplus
is always 1
for GCC 4.6 that is used on Windows. So #if __cplusplus < 201103L
or variants does not work to choose between C++03 or C++11 code.
C++17 is well supported by all major compilers.
Compiler version when feature complete:
GCC | Clang | MSVC | |
---|---|---|---|
C++17 | 7 (2017) | 4 (2017) (5 for constexpr lambda expressions) | 19.14 (2017) |
C++20 | 10* (2020) | 10* (2020) | 19.25* |
C++23 | 14* (2024) | 14# (2022) | 19.32# |
'*' Mostly complete '#' About half complete