ITK  5.4.0
Insight Toolkit
itkConceptChecking.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18/*=========================================================================
19 *
20 * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21 *
22 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23 *
24 * For complete copyright, license and disclaimer of warranty information
25 * please refer to the NOTICE file at the top of the ITK source tree.
26 *
27 *=========================================================================*/
28#ifndef itkConceptChecking_h
29#define itkConceptChecking_h
30
31#include "itkPixelTraits.h"
32#include "itkNumericTraits.h"
33#include <iostream>
34
36#ifndef ITK_CONCEPT_NO_CHECKING
37# if defined(_MSC_VER) && !defined(__ICL)
38# define ITK_CONCEPT_IMPLEMENTATION_VTABLE
39// TST_RMV_20100730 #elif defined(__SUNPRO_CC)
40// TST_RMV_20100730 #define ITK_CONCEPT_IMPLEMENTATION_VTABLE
41# else
42# define ITK_CONCEPT_IMPLEMENTATION_STANDARD
43# endif
44#endif
45
47#if defined(ITK_CONCEPT_IMPLEMENTATION_STANDARD)
48
56// Leave ()'s off the sizeof to force the caller to pass them in the
57// concept argument of the itkConceptMacro. This is necessary because
58// the argument may contain commas.
59# define itkConceptConstraintsMacro() \
60 template <void (Constraints::*)()> \
61 struct Enforcer \
62 {}; \
63 using EnforcerInstantiation = Enforcer<&Constraints::constraints>; \
64 ITK_MACROEND_NOOP_STATEMENT
65# define itkConceptMacro(name, concept) \
66 enum \
67 { \
68 name = sizeof concept \
69 }; \
70 ITK_MACROEND_NOOP_STATEMENT
71
72#elif defined(ITK_CONCEPT_IMPLEMENTATION_VTABLE)
73
79# define itkConceptConstraintsMacro() \
80 virtual void Enforcer() { &Constraints::constraints; }
81# define itkConceptMacro(name, concept) \
82 enum \
83 { \
84 name = sizeof concept \
85 }
88#elif defined(ITK_CONCEPT_IMPLEMENTATION_CALL)
89
91# define itkConceptConstraintsMacro()
92# define itkConceptMacro(name, concept) \
93 enum \
94 { \
95 name = 0 \
96 }
97
98#else
99
101# define itkConceptConstraintsMacro()
102# define itkConceptMacro(name, concept) \
103 enum \
104 { \
105 name = 0 \
106 }
107
108#endif
109
110namespace itk
111{
114namespace Concept
115{
116
124namespace Detail
125{
126template <typename T>
128{};
129template <int>
131{};
132template <unsigned int>
134{};
135template <bool>
137{};
138
144template <typename T>
146{}
147
153template <typename T>
154void
156{
157 bool x = t;
158
160}
161} // namespace Detail
162
164template <typename T>
166{
168 {
169 void
171 {
172 T a;
173
175 }
176 };
177
179};
180
182template <typename T>
184{
186 {
187 void
189 {
190 T a(b);
191 T * p = &a;
196 }
197
198 void
199 const_constraints(const T & a)
200 {
201 T c(a);
202 const T * p = &a;
203
206 }
207
208 T b;
209 };
210
212};
213
215template <typename T1, typename T2>
217{
219 {
220 void
222 {
223 auto b = static_cast<T2>(a);
224
226 }
227
228 T1 a;
229 };
231};
232
234template <typename T>
236{
238 {
239 void
241 {
242 T x = a;
244 }
247 void
248 const_constraints(const T & b)
249 {
250 a = b;
251 }
252
253 T a;
254 };
255
257};
258
261template <typename T1, typename T2 = T1>
263{
265 {
266 void
268 {
271 }
274 T1 a;
275 T2 b;
276 };
277
279};
280
283template <typename T1, typename T2 = T1>
285{
287 {
288 void
290 {
293 }
296 T1 a;
297 T2 b;
298 };
299
301};
302
305template <typename T1, typename T2 = T1>
307{
309 {
310 void
312 {
313 ITK_GCC_PRAGMA_PUSH
314 ITK_GCC_SUPPRESS_Wfloat_equal
317 ITK_GCC_PRAGMA_POP
318 }
321 T1 a;
322 T2 b;
323 };
324
326};
327
330template <typename T1, typename T2 = T1>
332{
334 {
335 void
337 {
342 ITK_GCC_PRAGMA_PUSH
343 ITK_GCC_SUPPRESS_Wfloat_equal
346 ITK_GCC_PRAGMA_POP
347 }
350 T1 a;
351 T2 b;
352 };
353
355};
356
359template <typename T1, typename T2 = T1, typename T3 = T1>
361{
363 {
364 void
366 {
367 a = static_cast<T3>(b + c);
368 a = static_cast<T3>(b - c);
370 }
373 void
374 const_constraints(const T1 & d, const T2 & e)
375 {
376 a = static_cast<T3>(d + e);
377 a = static_cast<T3>(d - e);
378 }
379
380 T3 a;
381 T1 b;
382 T2 c;
383 };
384
386};
387
388
391template <typename T1, typename T2 = T1>
393{
395 {
396 void
398 {
399 a += c;
400 a -= c;
402 }
405 void
406 const_constraints(const T1 & d)
407 {
408 a += d;
409 a -= d;
410 }
411
412 T2 a;
413 T1 c;
414 };
415
417};
418
420template <typename T1, typename T2 = T1, typename T3 = T1>
422{
424 {
425 void
427 {
428 a = static_cast<T3>(b * c);
430 }
433 void
434 const_constraints(const T1 & d, const T2 & e)
435 {
436 a = static_cast<T3>(d * e);
437 }
438
439 T3 a;
440 T1 b;
441 T2 c;
442 };
444};
445
447template <typename T1, typename T2 = T1>
449{
451 {
452 void
454 {
455 a *= b;
457 }
460 void
461 const_constraints(const T1 & d)
462 {
463 a *= d;
464 }
465
466 T2 a;
467 T1 b;
468 };
469
471};
472
474template <typename T1, typename T2 = T1, typename T3 = T1>
476{
478 {
479 void
481 {
482 a = static_cast<T3>(b / c);
484 }
487 void
488 const_constraints(const T1 & d, const T2 & e)
489 {
490 a = static_cast<T3>(d / e);
491 }
492
493 T3 a;
494 T1 b;
495 T2 c;
496 };
497
499};
500
501
503template <typename T1, typename T2 = T1>
505{
507 {
508 void
510 {
511 a /= c;
513 }
516 void
517 const_constraints(const T1 & d)
518 {
519 a /= d;
520 }
521
522 T1 c;
523 T2 a;
524 };
525
527};
528
529
532template <typename T1, typename T2 = T1, typename T3 = T1>
534{
536 {
537 void
539 {
540 a = static_cast<T3>(b & c);
541 a = static_cast<T3>(b | c);
542 a = static_cast<T3>(b ^ c);
543 a &= static_cast<T3>(c);
544 a |= static_cast<T3>(c);
545 a ^= static_cast<T3>(c);
547 }
550 void
551 const_constraints(const T1 & d, const T2 & e)
552 {
553 a = static_cast<T3>(d & e);
554 a = static_cast<T3>(d | e);
555 a = static_cast<T3>(d ^ e);
556 a &= static_cast<T3>(e);
557 a |= static_cast<T3>(e);
558 a ^= static_cast<T3>(e);
559 }
560
561 T3 a;
562 T1 b;
563 T2 c;
564 };
565
567};
568
570template <typename T1, typename T2 = T1, typename T3 = T1>
572{
574 {
575 void
577 {
578 a = static_cast<T3>(b[c]);
580 }
583 void
584 const_constraints(const T1 & d, const T2 & e)
585 {
586 a = static_cast<T3>(d[e]);
587 }
588
589 T3 a;
590 T1 b;
591 T2 c;
592 };
593
595};
596
598template <typename T>
600{
602 {
603 void
605 {
606 a = !a;
607 }
608
609 T a;
610 };
611
613};
614
616template <typename T>
618{
620 {
621 void
623 {
624 a++;
625 a--;
626 ++a;
627 --a;
628 }
629
630 T a;
631 };
632
634};
635
637template <typename T>
639{
641 {
642 void
644 {
645 std::cout << a;
646 }
647
648 T a;
649 };
650
652};
653
655template <typename T>
656struct Signed
657{
658 using Self = Signed;
659 static constexpr bool IsSigned = NumericTraits<T>::is_signed;
661 {
664 void
666 {
667 SignedT a = TrueT();
671 }
672 };
673
675};
676
678template <typename T1, typename T2>
680{
682 {
683 void
685 {
688 }
689 };
691};
695template <unsigned int D1, unsigned int D2>
697{
699 {
702 void
704 {
705 DT1 a = DT2();
709 }
710 };
712};
713
715template <typename T>
717{
719 {
720 void
722 {
730 T a{};
733 // Test these methods that take an instance of T to
734 // allow for types with variable length.
738
745 }
746 };
747
749};
750
752template <typename T>
754{
756 {
757 void
759 {
761 unsigned int a = PixelTraits<T>::Dimension;
763 }
764 };
768};
769
771template <typename T>
773{
775 {
776 void
778 {
780 }
781 };
785};
786
788template <typename T>
790{
792 {
793 void
795 {
796 T a;
797
798 a = T{};
800 }
801 };
802
804};
805
807template <typename T1, typename T2>
809{
811 {
812 void
814 {
816 }
817 };
821};
822
824template <unsigned int D1, unsigned int D2>
826{
828 {
831
832 void f(Type1) {}
833 void
834 f(Type2, int = 0)
835 {}
836
837 void
839 {
841 this->f(tt);
842 }
843 };
845};
846
848template <unsigned int D1, unsigned int D2>
850{
852 {
856
857 void f(Type1) {}
858 void
859 f(Type2, int = 0)
860 {}
861 void
862 f(Type3, int = 0, int = 0)
863 {}
864
865 void
867 {
869 this->f(tt);
870 }
871 };
873};
874
876template <typename T>
878{
880 static constexpr bool Integral = std::is_integral_v<T>;
882 {
885 void
887 {
888 IntegralT a = TrueT();
892 }
893 };
894
896};
897
898
900template <typename T>
902{
904 static constexpr bool Unsigned = !NumericTraits<T>::is_signed;
906 {
909 void
911 {
912 UnsignedT a = TrueT();
916 }
917 };
918
920};
921
922
924template <typename T>
926{
928 static constexpr bool NonIntegral = std::is_integral_v<T>;
930 {
933 void
935 {
936 NonIntegralT a = FalseT();
940 }
941 };
942
944};
945
947template <typename T>
949{
951 static constexpr bool Integral = std::is_integral_v<T>;
952 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
954 {
958 void
960 {
961 IntegralT a = FalseT();
962 ExactT b = FalseT();
967 }
968 };
969
971};
972
974template <typename T>
976{
978 static constexpr bool Integral = std::is_integral_v<T>;
979 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
981 {
986 void
988 {
989 IntegralT a = FalseT();
990 ExactT b = TrueT();
995 }
996 };
997
999};
1000} // end namespace Concept
1001} // end namespace itk
1002
1003#endif
Define additional traits for native types such as int or float.
static bool IsNegative(T val)
static constexpr T NonpositiveMin()
static bool IsPositive(T val)
static bool IsNonpositive(T val)
static bool IsNonnegative(T val)
Traits for a pixel that define the dimension and component type.
void RequireBooleanExpression(const T &t)
static constexpr double e
Definition: itkMath.h:56
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void const_constraints(const T1 &d, const T2 &e)
void const_constraints(const T1 &d, const T2 &e)
void const_constraints(const T1 &d, const T2 &e)
void const_constraints(const T1 &d, const T2 &e)
Detail::UniqueType_bool< true > TrueT
Detail::UniqueType_bool< false > FalseT
static constexpr bool IsExact
static constexpr bool Integral
Detail::UniqueType_bool< false > FalseT
static constexpr bool Integral
Detail::UniqueType_bool< true > TrueT
static constexpr bool Integral
Detail::UniqueType_bool< false > FalseT
static constexpr bool NonIntegral
void const_constraints(const T1 &d, const T2 &e)
Detail::UniqueType_unsigned_int< D2 > DT2
Detail::UniqueType_bool< true > TrueT
static constexpr bool IsSigned