# Survey about updating VTK's minimal C++ standard version

**URL:** https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763
**Category:** Support
**Created:** [November 21, 2023, 11:03pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763 "2023-11-21T23:03:27Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [November 21, 2023, 11:03pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/1 "2023-11-21T23:03:27Z")

</div>

Hello VTK community!

VTK is a widely used library for visualization. As such, it has needed to support many different compilers, including gcc 4.8.5. As a result, VTK has been limited to using only features available in the C++11 standard.

We have heard from the institutions that previously needed gcc 4.8.5 support that they have moved to more recent gcc versions (greater than 8). At the same time, there is a lot of interest among VTK developers to move to a more recent standard, such as C++17. This opens the possibility of updating our C++ version in upcoming versions of VTK.

Before we do that, though, we would like to hear from you about the minimal compiler versions you need to use to compile VTK. **What’s the oldest compiler you need to support** , and if you know it, which version of C++ does it support.

Please let us know in the comments below.

Thanks!  
Cory

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [November 21, 2023, 11:03pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/2 "2023-11-21T23:03:48Z")

</div>



---

<div class="post-metadata">

### Author: ![ramen\_newdals](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ramen_newdals/32/7173_2.png) [@ramen\_newdals](https://discourse.vtk.org/u/ramen_newdals)
#### Post date: [November 27, 2023, 6:36pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/3 "2023-11-27T18:36:27Z")

</div>

All of the applications I work with/on can be built with gcc 13 and clang 15, but I do work on a highly limited subset.

Does moving towards a new C++ version entail incorporating new standard features into the core vtk data model? Curious what the goals of moving to C++17 are 🙂

---

<div class="post-metadata">

### Author: ![ugis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ugis/32/6790_2.png) [@ugis](https://discourse.vtk.org/u/ugis)
#### Post date: [November 28, 2023, 7:02am UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/4 "2023-11-28T07:02:12Z")

</div>

Hi Cory,

We build VTK with Visual Studio 2019, it seems that it does support C++17, although there might be some defects (not an expert in the area though). But thanks for asking for the input and good luck with the development!

Ugis

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dzenanz/32/212_2.png) [@dzenanz](https://discourse.vtk.org/u/dzenanz)
#### Post date: [November 28, 2023, 2:25pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/5 "2023-11-28T14:25:58Z")

</div>

A move to C++17 would be welcome. ITK has already switched. Here are the corresponding compiler versions:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/f871250c8d3d07541965fca97d146eaf60e4f6e2/Documentation/docs/supported_compilers.md#L5-L23>

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scivision/32/7897_2.png) [@scivision](https://discourse.vtk.org/u/scivision)
#### Post date: [December 18, 2023, 9:09pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/6 "2023-12-18T21:09:34Z")

</div>

For over a year, the oldest HPC I use default to at least GCC 8.x

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [January 9, 2024, 7:02pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/7 "2024-01-09T19:02:36Z")

</div>

> Does moving towards a new C++ version entail incorporating new standard features into the core vtk data model? Curious what the goals of moving to C++17 are

`string_view`, `optional`, `filesystem` are few things that can make developing new code in VTK fun. I’d like to use designated initializers from C++20. It makes implementation code descriptive and clean.

Random example:

```c++
struct TimerPayload
{
  int Timeout;
  bool Repeat;
  std::string Source;
};
TimerPayload payload{.Timeout=1000, .Repeat=false, .Source= __func__ };
this->InvokeEvent(vtkCommand::StartEvent, &payload);

```

Of course, with c++20, we’d get a lot more than just designated initializers 🙂

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [January 10, 2024, 3:56am UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/8 "2024-01-10T03:56:03Z")

</div>

Visual Studio 2017 supports C++17 compilation from version 3.5 onwards. The last update was version 4.8

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [February 7, 2024, 3:01pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/9 "2024-02-07T15:01:34Z")

</div>

Learned that C++17 supports [If statement with initializer](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html). I think it’s useful when dealing with iterators in VTK.

There are instances of code in VTK that assign and check the value in the argument of `if` to prevent accidentally dereferencing a null pointer and/or limiting the scope of a resource.

Example:

This is safer

```c++
if (auto gradients = pointData->GetArray("Gradients"))
{
  // print gradients
  auto r = vtk::DataArrayValueRange(gradients);
  std::copy(r.begin(), r.end(), std::ostream_iterator<double>(std::cout, '\n'));
}
// gradients variable cannot be accessed anymore.

```

instead of writing

```c++
auto gradients = pointData->GetArray("Gradients");
if (gradients != nullptr)
{
  // print gradients
  auto r = vtk::DataArrayValueRange(gradients);
  std::copy(r.begin(), r.end(), std::ostream_iterator<double>(std::cout, '\n'));
}
// gradients is nullptr, but the variable is still accessible!

```

As useful as that is, it’s not possible to do that with iterators. Right now, this, by itself, will fail to compile.

```c++
if (((auto iter = entries.find(key)) != entries.end))
{
  std::cout << iter->first << ':' << iter->second << std::endl;
}

```

leading one to write unsafe code

```c++
auto iter = entries.find(key);
if (auto iter = entries.find(key))
{
  std::cout << iter->first << ':' << iter->second << std::endl;
}
// compiler doesn't complain when iter is accidentally dereferenced, crashes at run time.
int a = iter->first;

```

With if-initialization statements in C++17, that can be re-written safely.

```c++
if (auto iter = entries.find(key); iter != entries.end())
{
  std::cout << iter->first << ':' << iter->second << std::endl;
}
// iter is inaccessible. compiler will complain if iter is dereferenced.

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [February 7, 2024, 6:44pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/10 "2024-02-07T18:44:04Z")

</div>

Can we please collect these things into issues; ideally an overarching issue for C++17 usage with individual issues for each pattern to adopt. If possible, ways to identify these patterns for migration would be ideal.

I don’t know if a C++ version exists, but [coccinelle](https://github.com/coccinelle/coccinelle) allows crafting “semantic patches” that perform code transformations. Maybe it could be hacked up enough for C++ usage by treating `::` as part of identifiers?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [February 9, 2024, 7:59pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/11 "2024-02-09T19:59:54Z")

</div>

Having heard no objections to updating VTK to require C++17, shall we proceed with making that change?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [February 13, 2024, 2:33pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/12 "2024-02-13T14:33:15Z")

</div>

I think we can; let’s bump CMake to do C++17. This probably involves some new warnings, so the MR might be larger. Documentation about minimum compilers needs updated too. `mindeps` might need a new `devtoolset` installed too.

Note that `clang-format` is currently set to using `Cpp11`. Updating that may involve some reformatting; we should try this without updating `clang-format` first; if we need to update, it’s a bit more involved (but hopefully doesn’t change too much to inhibit nice backporting; the main reason pre-branch formatting is vastly preferred).

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [February 26, 2024, 2:19am UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/13 "2024-02-26T02:19:40Z")

</div>

I have no issues wrt the VTK Examples, as some examples already use C++17. So it’s a yes from me.

---

<div class="post-metadata">

### Author: ![hakostra](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hakostra/32/2990_2.png) [@hakostra](https://discourse.vtk.org/u/hakostra)
#### Post date: [February 26, 2024, 11:51am UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/14 "2024-02-26T11:51:47Z")

</div>

This seems like a good idea.

I think the reason for the old GCC 4.8.5 requirement was RHEL 7 and it’s derivatives (Centos, …) have lived for a long time being very successful and stable using that compiler. However, official support for RHEL 7 ending in June this year will finally put the last nail in the coffin for any serious system still using these legacy operating systems, so the switch to a different and more modern distro have mostly already happened.

“EL-8” (RH, Rocky, Alma, Oracle, Centos Stream, …) based distros is a different era w.r.t. code development and tooling… As a developer myself I’m so glad I don’t have to deal with RHEL-7 any more!

So please get rid of the old stuff!

---

<div class="post-metadata">

### Author: ![longjiang321](https://discourse.vtk.org/user_avatar/discourse.vtk.org/longjiang321/32/8727_2.png) [@longjiang321](https://discourse.vtk.org/u/longjiang321)
#### Post date: [April 9, 2024, 1:39pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/15 "2024-04-09T13:39:02Z")

</div>

warmly welcome to support C++17, as the QT which is latest than 6.2 need C++17!!  
no body can stay at the old time forever !!

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [April 22, 2024, 9:26pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/16 "2024-04-22T21:26:25Z")

</div>

Currently, we have some issues compiling `vtkfmt` using C++17. Anyone experiencing the same issues. It cannot be so much pain to update `vtkfmt` to a more recent version of `fmt.

---

<div class="post-metadata">

### Author: ![longjiang321](https://discourse.vtk.org/user_avatar/discourse.vtk.org/longjiang321/32/8727_2.png) [@longjiang321](https://discourse.vtk.org/u/longjiang321)
#### Post date: [July 11, 2024, 10:30am UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/17 "2024-07-11T10:30:44Z")

</div>

does the team has any shedule about the upgrade ?? thank you in advance

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [February 10, 2025, 1:10pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/18 "2025-02-10T13:10:09Z")

</div>

VTK is now updated to require C++17 🎉 as of [this merge request](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11049).

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [February 11, 2025, 8:28pm UTC](https://discourse.vtk.org/t/survey-about-updating-vtks-minimal-c-standard-version/12763/19 "2025-02-11T20:28:21Z")

</div>

Thankyou for all your work.
