ITK  6.0.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>
145inline void
147{}
148
154template <typename T>
155void
157{
158 const bool x = t;
159
161}
162} // namespace Detail
163
165template <typename T>
167{
169 {
170 void
172 {
173 T a;
174
176 }
177 };
178
180};
181
183template <typename T>
185{
187 {
188 void
190 {
191 T a(b);
192 T * p = &a;
197 }
198
199 void
200 const_constraints(const T & a)
201 {
202 T c(a);
203 const T * p = &a;
204
207 }
208
209 T b;
210 };
211
213};
214
216template <typename T1, typename T2>
218{
220 {
221 void
223 {
224 auto b = static_cast<T2>(a);
225
227 }
228
229 T1 a;
230 };
232};
233
235template <typename T>
237{
239 {
240 void
242 {
243 T x = a;
245 }
248 void
249 const_constraints(const T & b)
250 {
251 a = b;
252 }
253
254 T a;
255 };
256
258};
259
262template <typename T1, typename T2 = T1>
264{
266 {
267 void
269 {
272 }
275 T1 a;
276 T2 b;
277 };
278
280};
281
284template <typename T1, typename T2 = T1>
286{
288 {
289 void
291 {
294 }
297 T1 a;
298 T2 b;
299 };
300
302};
303
306template <typename T1, typename T2 = T1>
308{
310 {
311 void
313 {
314 ITK_GCC_PRAGMA_PUSH
315 ITK_GCC_SUPPRESS_Wfloat_equal
318 ITK_GCC_PRAGMA_POP
319 }
322 T1 a;
323 T2 b;
324 };
325
327};
328
331template <typename T1, typename T2 = T1>
333{
335 {
336 void
338 {
343 ITK_GCC_PRAGMA_PUSH
344 ITK_GCC_SUPPRESS_Wfloat_equal
347 ITK_GCC_PRAGMA_POP
348 }
351 T1 a;
352 T2 b;
353 };
354
356};
357
360template <typename T1, typename T2 = T1, typename T3 = T1>
362{
364 {
365 void
367 {
368 a = static_cast<T3>(b + c);
369 a = static_cast<T3>(b - c);
371 }
374 void
375 const_constraints(const T1 & d, const T2 & e)
376 {
377 a = static_cast<T3>(d + e);
378 a = static_cast<T3>(d - e);
379 }
380
381 T3 a;
382 T1 b;
383 T2 c;
384 };
385
387};
388
389
392template <typename T1, typename T2 = T1>
394{
396 {
397 void
399 {
400 a += c;
401 a -= c;
403 }
406 void
407 const_constraints(const T1 & d)
408 {
409 a += d;
410 a -= d;
411 }
412
413 T2 a;
414 T1 c;
415 };
416
418};
419
421template <typename T1, typename T2 = T1, typename T3 = T1>
423{
425 {
426 void
428 {
429 a = static_cast<T3>(b * c);
431 }
434 void
435 const_constraints(const T1 & d, const T2 & e)
436 {
437 a = static_cast<T3>(d * e);
438 }
439
440 T3 a;
441 T1 b;
442 T2 c;
443 };
445};
446
448template <typename T1, typename T2 = T1>
450{
452 {
453 void
455 {
456 a *= b;
458 }
461 void
462 const_constraints(const T1 & d)
463 {
464 a *= d;
465 }
466
467 T2 a;
468 T1 b;
469 };
470
472};
473
475template <typename T1, typename T2 = T1, typename T3 = T1>
477{
479 {
480 void
482 {
483 a = static_cast<T3>(b / c);
485 }
488 void
489 const_constraints(const T1 & d, const T2 & e)
490 {
491 a = static_cast<T3>(d / e);
492 }
493
494 T3 a;
495 T1 b;
496 T2 c;
497 };
498
500};
501
502
504template <typename T1, typename T2 = T1>
506{
508 {
509 void
511 {
512 a /= c;
514 }
517 void
518 const_constraints(const T1 & d)
519 {
520 a /= d;
521 }
522
523 T1 c;
524 T2 a;
525 };
526
528};
529
530
533template <typename T1, typename T2 = T1, typename T3 = T1>
535{
537 {
538 void
540 {
541 a = static_cast<T3>(b & c);
542 a = static_cast<T3>(b | c);
543 a = static_cast<T3>(b ^ c);
544 a &= static_cast<T3>(c);
545 a |= static_cast<T3>(c);
546 a ^= static_cast<T3>(c);
548 }
551 void
552 const_constraints(const T1 & d, const T2 & e)
553 {
554 a = static_cast<T3>(d & e);
555 a = static_cast<T3>(d | e);
556 a = static_cast<T3>(d ^ e);
557 a &= static_cast<T3>(e);
558 a |= static_cast<T3>(e);
559 a ^= static_cast<T3>(e);
560 }
561
562 T3 a;
563 T1 b;
564 T2 c;
565 };
566
568};
569
571template <typename T1, typename T2 = T1, typename T3 = T1>
573{
575 {
576 void
578 {
579 a = static_cast<T3>(b[c]);
581 }
584 void
585 const_constraints(const T1 & d, const T2 & e)
586 {
587 a = static_cast<T3>(d[e]);
588 }
589
590 T3 a;
591 T1 b;
592 T2 c;
593 };
594
596};
597
599template <typename T>
601{
603 {
604 void
606 {
607 a = !a;
608 }
609
610 T a;
611 };
612
614};
615
617template <typename T>
619{
621 {
622 void
624 {
625 a++;
626 a--;
627 ++a;
628 --a;
629 }
630
631 T a;
632 };
633
635};
636
638template <typename T>
640{
642 {
643 void
645 {
646 std::cout << a;
647 }
648
649 T a;
650 };
651
653};
654
656template <typename T>
657struct Signed
658{
659 using Self = Signed;
660 static constexpr bool IsSigned = NumericTraits<T>::is_signed;
662 {
665 void
667 {
668 const SignedT a = TrueT();
672 }
673 };
674
676};
677
679template <typename T1, typename T2>
681{
683 {
684 void
686 {
689 }
690 };
692};
696template <unsigned int D1, unsigned int D2>
698{
700 {
703 void
705 {
706 DT1 const a = DT2();
710 }
711 };
713};
714
716template <typename T>
718{
720 {
721 void
723 {
731 T a{};
734 // Test these methods that take an instance of T to
735 // allow for types with variable length.
739
746 }
747 };
748
750};
751
753template <typename T>
755{
757 {
758 void
760 {
762 const unsigned int a = PixelTraits<T>::Dimension;
764 }
765 };
769};
770
772template <typename T>
774{
776 {
777 void
779 {
781 }
782 };
786};
787
789template <typename T>
791{
793 {
794 void
796 {
797 T a;
798
799 a = T{};
801 }
802 };
803
805};
806
808template <typename T1, typename T2>
810{
812 {
813 void
815 {
817 }
818 };
822};
823
825template <unsigned int D1, unsigned int D2>
827{
829 {
832
833 void
835 {}
836 void
837 f(Type2, int = 0)
838 {}
839
840 void
842 {
844 this->f(tt);
845 }
846 };
848};
849
851template <unsigned int D1, unsigned int D2>
853{
855 {
859
860 void
862 {}
863 void
864 f(Type2, int = 0)
865 {}
866 void
867 f(Type3, int = 0, int = 0)
868 {}
869
870 void
872 {
874 this->f(tt);
875 }
876 };
878};
879
881template <typename T>
883{
885 static constexpr bool Integral = std::is_integral_v<T>;
887 {
890 void
892 {
893 const IntegralT a = TrueT();
897 }
898 };
899
901};
902
903
905template <typename T>
907{
909 static constexpr bool Unsigned = !NumericTraits<T>::is_signed;
911 {
914 void
916 {
917 const UnsignedT a = TrueT();
921 }
922 };
923
925};
926
927
929template <typename T>
931{
933 static constexpr bool NonIntegral = std::is_integral_v<T>;
935 {
938 void
940 {
941 NonIntegralT a = FalseT();
945 }
946 };
947
949};
950
952template <typename T>
954{
956 static constexpr bool Integral = std::is_integral_v<T>;
957 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
959 {
963 void
965 {
966 const IntegralT a = FalseT();
967 const ExactT b = FalseT();
972 }
973 };
974
976};
977
979template <typename T>
981{
983 static constexpr bool Integral = std::is_integral_v<T>;
984 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
986 {
991 void
993 {
994 IntegralT a = FalseT();
995 ExactT b = TrueT();
1000 }
1001 };
1002
1004};
1005} // end namespace Concept
1006} // end namespace itk
1007
1008#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