# Shall we start using C++17 at the master branch?

**URL:** https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828
**Category:** Engineering
**Created:** [March 23, 2023, 3:33pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828 "2023-03-23T15:33:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [March 23, 2023, 3:33pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/1 "2023-03-23T15:33:26Z")

</div>

In the last few days, I prepared a pull request to upgrade the ITK master branch to C++17, with help from @dzenanz and @mihail.isakov Please check: PR #3969 [ENH: Upgrade ITK from C++14 to C++17 by N-Dekker · Pull Request #3969 · InsightSoftwareConsortium/ITK · GitHub](https://github.com/InsightSoftwareConsortium/ITK/pull/3969)

C++17 is a major step forward. It includes quite a few interesting new features: [C++17 - Wikipedia](https://en.wikipedia.org/wiki/C%2B%2B17)

However, moving forward to C++17 would also mean saying goodbye to a few old compiler versions. I think we should then at least require GCC 7, LLVM Clang 5, Apple Clang 10 (Xcode 10.0), VS2017 version 15.7, or Intel C++ 19.1, and drop support for earlier versions. Would that be OK?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [March 27, 2023, 2:21pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/2 "2023-03-27T14:21:03Z")

</div>

@Niels_Dekker et al thanks for looking into this, submitting a PR, and creating this thread!

I have been using C++17 with ITK for quite some time, and it does have very nice advantages.

There is not a ITK/toolchain usage scenario I am aware of where the toolchain cannot be upgraded to support C++17 when upgrading ITK.

When upgrading the required standard version, we should also make a note in the ITK Software Guide and describe the associated minimum compiler versions here:

> <https://github.com/InsightSoftwareConsortium/ITKSoftwareGuide/blob/e8ae54e2c6c5de858227f7d513049187ef0126ab/SoftwareGuide/Latex/Introduction/Installation.tex#L36-L38>

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [March 27, 2023, 3:40pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/3 "2023-03-27T15:40:24Z")

</div>

Thanks Matt. I believe that the required compiler versions that I proposed with PR #3969 basically support all C++17 _language_ features. For some of the C++17 `std` _library_ features, even more recent compiler versions may be needed. For example, `std::filesystem` is added with GCC 8, whereas the PR only requires GCC 7. And clang still does not support the parallel C++17 algorithms from `<algorithm>`. For details, you may have a look at [Compiler support for C++17 - cppreference.com](https://en.cppreference.com/w/cpp/compiler_support/17) of course!

Note also that the PR still supports VS2017 (at least from version 15.7), even though I wouldn’t mind dropping that one either 😺

> [@Drop support for Visual Studio 2017?](https://discourse.itk.org/t/drop-support-for-visual-studio-2017/4944):
>
> Microsoft is dropping “vs2017-win2016” from their hosted pipelines for Azure Pipelines. An attempt to use it to test [elastix](https://github.com/SuperElastix/elastix) produced the following error message: ##[error]This is a scheduled windows-2016 brownout. The windows-2016 environment is deprecated and will be removed on April 1st, 2022. For more details, see [Windows-2016 environment removal postponed until April 1st, 2022 · Issue #5238 · actions/virtual-environments · GitHub](https://github.com/actions/virtual-environments/issues/5238) ,##[error]The remote provider was unable to process the re…

So I just want to say that PR #3969 is quite a modest proposal 😇

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 27, 2023, 4:05pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/4 "2023-03-27T16:05:52Z")

</div>

I want `std::filesystem` to be available. It is one of the major additions to C++17. Can you update the PR to require GCC 8?

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [March 27, 2023, 5:38pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/5 "2023-03-27T17:38:31Z")

</div>

> [@dzenanz](#):
>
> want `std::filesystem` to be available. It is one of the major additions to C++17. Can you update the PR to require GCC 8?

GCC 8 would be OK to me as well, thanks @dzenanz, but then, why not require at least GCC 9? GCC 9 has some more C++17 library features, as you can see at [Compiler support for C++17 - cppreference.com](https://en.cppreference.com/w/cpp/compiler_support/17) GCC 9 was released almost four years ago already, and according to [GCC 9 Release Series - GNU Project](https://gcc.gnu.org/gcc-9/) it has:

> #### Runtime Library (libstdc++)
> 
> - Improved support for C++17, including:
> - The C++17 implementation is no longer experimental.
> - Parallel algorithms and `<execution>` (requires [Thread Building Blocks](https://github.com/oneapi-src/oneTBB) 2018 or newer).
> - `<memory_resource>`.
> - Using the types and functions in `<filesystem>` does not require linking with `-lstdc++fs` now.

At the [elastix](https://github.com/SuperElastix/elastix) CI, we use GCC 9.4.0 on Ubuntu 20.04, so that’s no problem.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 27, 2023, 5:47pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/6 "2023-03-27T17:47:42Z")

</div>

I would be fine with that, too.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [March 27, 2023, 7:06pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/7 "2023-03-27T19:06:35Z")

</div>

As @Niels_Dekker mentioned, `filesystem` support and parallel `algorithm` support, while wonderful to have as @dzenanz pointed out, are not currently broadly available, and we should not require it. They could optionally be used when available, but I do not think we can require them at this point.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 27, 2023, 7:11pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/8 "2023-03-27T19:11:03Z")

</div>

OK, then, GCC7 now, and GCC9 an ITK version or two later 😃

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [March 27, 2023, 8:57pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/9 "2023-03-27T20:57:00Z")

</div>

So with this proposal we are not going to be able to purely adopt CXX 17. What does this mean for how ITK will work with CMake to ensure the required features are there? Currently its easy to do something like: `target_compile_features( SimpleITKIO PUBLIC cxx_std_14 )` Are we going back to explicitly listing the C++ compile features ITK requires?

---

<div class="post-metadata">

### Author: ![jamesobutler](https://discourse.itk.org/user_avatar/discourse.itk.org/jamesobutler/32/1807_2.png) [@jamesobutler](https://discourse.itk.org/u/jamesobutler)
#### Post date: [March 28, 2023, 12:12am UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/10 "2023-03-28T00:12:03Z")

</div>

As it relates to applications that use ITK:

- 3D Slicer has required Visual Studio 2017 (VS 15.7) or newer since it required C++14 ([COMP: Require at least C++14 · Slicer/Slicer@bc2b3f4 · GitHub](https://github.com/Slicer/Slicer/commit/bc2b3f4049ef32486cf43ad16903820fc8767f27)) in February 2022.
- 3D Slicer has required C++17 ([COMP: Require at least C++17 (#6237) · Slicer/Slicer@dedb6c0 · GitHub](https://github.com/Slicer/Slicer/commit/dedb6c04d5f987d168e58dfda067717a7039b439)) since July 2022 as part of activities prepping for Qt 6 support.

Therefore the move for ITK to move to C++17 is fine on the 3D Slicer side 👍

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [March 28, 2023, 2:52pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/11 "2023-03-28T14:52:12Z")

</div>

> [@blowekamp](#):
>
> So with this proposal we are not going to be able to purely adopt CXX 17. What does this mean for how ITK will work with CMake to ensure the required features are there?

With the currently proposed minimum required compiler version, all C++17 _language_ features will become available. Only _a few_ C++17 `std` library features may then not yet be used, within the implementation of ITK. (This is just a limitation to ITK _developers_. ITK _users_ do not need to be bothered, as they may have a newer compiler version for their application.)

Specifically, GCC 7 has all the C++17 language features, but its C++17 `std` library is still incomplete and “experimental”. So _personally_ I would like ITK to move forward to GCC 9. But I don’t know if there are still ITK users out there using GCC 7 or GCC 8, do you?

If there are still ITK users that are using GCC 7 or GCC 8, I’m OK with requiring GCC 7 for now.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [March 28, 2023, 2:59pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/12 "2023-03-28T14:59:53Z")

</div>

I was looking for the current CMake best practices for these types of required features. It looks likes some answers can be found here:  
[https://cmake.org/cmake/help/latest/prop\_gbl/CMAKE\_CXX\_KNOWN\_FEATURES.html?highlight=lambda](https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html?highlight=lambda)

In particular:

> These individual features are now less relevant and projects should generally prefer to use the high level meta features instead. Individual compile features are not provided for C++ 17 or later.

So it sounds like the suggestion to just do: `target_compile_features( mylib PUBLIC cxx_std_17 )` even if the compiler has an incomplete `std` library for the standard.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [March 28, 2023, 3:20pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/13 "2023-03-28T15:20:40Z")

</div>

> [@Niels\_Dekker](#):
>
> ITK users out there using GCC 7

GCC 7 is the default version in Ubuntu 18.04, and there are still some people using it, but it is near End of Life (EOL).

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [March 28, 2023, 3:27pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/14 "2023-03-28T15:27:26Z")

</div>

> [@matt.mccormick](#):
>
> GCC 7 is the default version in Ubuntu 18.04, and there are still some people using it, but it is near End of Life (EOL).

Standard support of 18.04 ends on May 31, 2023. What is the target date for the next release? If it is after that date does it still need to be supported by ITK?

The full EOL with Ubuntu Pro is extended to 2028.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [March 28, 2023, 4:05pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/15 "2023-03-28T16:05:55Z")

</div>

We are looking at June for ITK 5.4, but I done not think bumping required GCC beyond 7 is going to address the `std` completeness issue – e.g. `filesystem` support is still newer across toolchains and it is not available in wasm toolchains, possibly others.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [April 2, 2023, 11:28am UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/16 "2023-04-02T11:28:43Z")

</div>

> [@matt.mccormick](#):
>
> When upgrading the required standard version, we should also make a note in the ITK Software Guide and describe the associated minimum compiler versions here:
> 
> [ITKSoftwareGuide/SoftwareGuide/Latex/Introduction/Installation.tex at e8ae54e2c6c5de858227f7d513049187ef0126ab · InsightSoftwareConsortium/ITKSoftwareGuide · GitHub](https://github.com/InsightSoftwareConsortium/ITKSoftwareGuide/blob/e8ae54e2c6c5de858227f7d513049187ef0126ab/SoftwareGuide/Latex/Introduction/Installation.tex#L36-L38)

Thanks Matt, can you possibly make that a PR for ITKSoftwareGuide?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [April 3, 2023, 12:23pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/17 "2023-04-03T12:23:38Z")

</div>

Done here:

> <https://github.com/InsightSoftwareConsortium/ITKSoftwareGuide/pull/198>
>
> This follows changes in the main repository, described in this commit: https://g…ithub.com/InsightSoftwareConsortium/ITK/commit/45407f3560d91af247c95a1f48d21cbbb8ff6b8d

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [April 4, 2024, 2:05pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/18 "2024-04-04T14:05:07Z")

</div>

@matt.mccormick @dzenanz As it is one year later now, would it be about time to drop GCC 7, and maybe move forward to requiring at least GCC 9?

As @blowekamp remarked at [Use PathType for file paths by blowekamp · Pull Request #2085 · SimpleITK/SimpleITK · GitHub](https://github.com/SimpleITK/SimpleITK/pull/2085#issuecomment-2037060699)

> The big hold out there was Ubuntu 18.04, which is now EOL’d.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [April 4, 2024, 2:19pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/19 "2024-04-04T14:19:25Z")

</div>

The next release candidate is expected soon, so maybe after that? I primarily use Windows, so I don’t have a strong opinion about minimum GCC version, aside from “higher is better” 😃

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [April 4, 2024, 2:22pm UTC](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828/20 "2024-04-04T14:22:19Z")

</div>

> [@dzenanz](#):
>
> The next release candidate is expected soon, so maybe after that?

Another release candidate? I am not sure why actually releases are not occurring.

More specific to the point, I would expect the requirements for the next release (non-RC) to be set, and after the release the build requirements may change.

[Next page](https://discourse.itk.org/t/shall-we-start-using-c-17-at-the-master-branch/5828.md?page=2)
