# Ease transition to const-correct VerifyPreconditions

**URL:** https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399
**Category:** Engineering
**Created:** [November 6, 2018, 9:53pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399 "2018-11-06T21:53:45Z")
**Posts on this page:** 7
**Page:** 1

<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: [November 6, 2018, 9:53pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399/1 "2018-11-06T21:53:45Z")

</div>

All the code which overrode `VerifyPreconditions()` and `VerifyInputInformation()` now fails to compile with an error message similar to this:

> 16\>c:\misc\bluequartz\simpl\source\simplib\itk\itkinplaceimagetodream3ddatafilter.h(57): error C3668: ‘itk::InPlaceImageToDream3DDataFilter\<TPixel,1\>::VerifyPreconditions’: method with override specifier ‘override’ did not override any base class methods

We could introduce a macro which would be `const` with legacy off, and `[empty string]` with legacy on. We could call it `ITK5_CONST` or something similar. Alternatively, we could remove `const` from the signatures of those two methods.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [November 6, 2018, 10:34pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399/2 "2018-11-06T22:34:49Z")

</div>

I have had some trouble with this, see [this commit](https://github.com/SimonRit/RTK/commit/88615b48274884801c99de7b23f6ebec758f0907). In general, I think that those backward incompatible changes should be avoided (and this thread should have started before committing these changes). Particularly since we cannot add tests on ITK\_\*\_VERSION in the code with all 5.\* versions having the same numbers (there has not been a non-alpha or non-beta release in a long time). I don’t think that the legacy on/off is a solution, in practice some people will report that the code does not compile with ITK\_LEGACY\_REMOVE.

---

<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: [November 7, 2018, 1:20pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399/3 "2018-11-07T13:20:00Z")

</div>

> [@dzenanz](#):
>
> We could introduce a macro which would be `const` with legacy off, and `[empty string]` with legacy on. We could call it `ITK5_CONST` or something similar.

I think that might work, for me at least. 😀

> [@dzenanz](#):
>
> Alternatively, we could remove `const` from the signatures of those two methods.

But then, when would there be a better moment to fix const-correctness of `VerifyPreconditions()` and `VerifyInputInformation()`?

By the way, there could be another workaround to ease the transition: offer _both_ const and non-const overloads of these two virtual member functions, in the base class (`itk::ProcessObject`). The non-const versions could then internally call the corresponding const versions. And ITK users could then override either one of them. (Of course, it would be recommended to override the const versions.)

My 2 cents

---

<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: [November 7, 2018, 2:18pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399/4 "2018-11-07T14:18:48Z")

</div>

> [@Niels\_Dekker](#):
>
> offer _both_ const and non-const overloads

I am not sure whether that could work, and what would be the side-effects and future maintenance burden of that. But it is an idea I haven’t thought of!

---

<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: [November 7, 2018, 2:53pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399/5 "2018-11-07T14:53:39Z")

</div>

I agree with the expected behavior with the following CMake variables:

```auto
  ITKV4_COMPATIBILITY:BOOL=ON
  ITK_LEGACY_REMOVE:BOOL=OFF

```

is that the old non-const methods should work. I did briefly implement the non-const versions calling the const versions in the ProcessObject, but that was riddled with warnings or error dues to incomplete overloads.

If something like `ITKv5_CONST` is added please also add it to the v4 release branch so it can be used for v4 and v5 code.

---

<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: [November 12, 2018, 9:32pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399/6 "2018-11-12T21:32:19Z")

</div>

OK, I am implementing the macro solution. I will call it `ITKv5_CONST`.

---

<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: [November 13, 2018, 4:26pm UTC](https://discourse.itk.org/t/ease-transition-to-const-correct-verifypreconditions/1399/7 "2018-11-13T16:26:37Z")

</div>

PR [here](https://github.com/InsightSoftwareConsortium/ITK/pull/173).

TODO: add `#define ITKv5_CONST` to itkMacro.h in release-4.13 branch.
