Difference between revisions of "C++17"
Jump to navigation
Jump to search
(Add std::variant and std::optional) |
(Add structured binding) |
||
Line 7: | Line 7: | ||
! 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(…)) | | std::make_unique<Foo>(…) || C++14 || style="background: lightgreen;" | from 1.1 || Replaces std::unique_ptr<Foo>(new Foo(…)) | ||
|- | |- | ||
| constexpr || C++14 || style="background: lightgreen;" | from 1.1 || Declares a variable as usable in a const expression | | constexpr || C++14 || style="background: lightgreen;" | from 1.1 || Declares a variable as usable in a const expression | ||
Line 16: | Line 16: | ||
|- | |- | ||
| std::optional<…> || C++17 || style="background: lightgreen;" | from 1.1 || Object type (not a pointer or reference) which can either exist or be nullopt | | std::optional<…> || C++17 || style="background: lightgreen;" | from 1.1 || Object type (not a pointer or reference) which can either exist or be nullopt | ||
|- | |||
| auto [x, y] = foo() || C++17 || style="background: lightgreen;" | from 1.1 || Structured binding, for returning more than a single value | |||
|- | |- | ||
| 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) |
Revision as of 11:18, 13 April 2020
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::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 nullopt |
auto [x, y] = foo() | C++17 | from 1.1 | Structured binding, for returning more than a single value |
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* | 10* | 19.22# |
'*' Mostly complete '#' About half complete