ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
55
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 }
87
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
122
124namespace Detail
125{
126template <typename T>
128{};
129template <int>
131{};
132template <unsigned int>
135template <bool>
137{};
138
144template <typename T>
145inline void
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;
194
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 }
246
247
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
273
274
275 T1 a;
276 T2 b;
277 };
278
280};
281
284template <typename T1, typename T2 = T1>
286{
288 {
289 void
295
296
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 }
320
321
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 }
349
350
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 }
372
373
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 }
404
405
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 }
432
433
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 }
459
460
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 }
486
487
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 }
515
516
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 }
549
550
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 }
582
583
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>
677
679template <typename T1, typename T2>
681{
683 {
684 void
690 };
692};
693
694
696template <unsigned int D1, unsigned int D2>
714
716template <typename T>
753
755template <typename T>
757{
759 {
760 void
767 };
768
769
771};
772
774template <typename T>
776{
778 {
779 void
784 };
785
786
788};
789
791template <typename T>
793{
795 {
796 void
798 {
799 T a;
800
801 a = T{};
803 }
804 };
805
807};
808
810template <typename T1, typename T2>
825
827template <unsigned int D1, unsigned int D2>
829{
831 {
834
835 void
837 {}
838 void
839 f(Type2, int = 0)
840 {}
841
842 void
844 {
846 this->f(tt);
847 }
848 };
850};
851
853template <unsigned int D1, unsigned int D2>
855{
857 {
861
862 void
864 {}
865 void
866 f(Type2, int = 0)
867 {}
868 void
869 f(Type3, int = 0, int = 0)
870 {}
871
872 void
874 {
876 this->f(tt);
877 }
878 };
880};
881
883template <typename T>
885{
887 static constexpr bool Integral = std::is_integral_v<T>;
901
903};
904
905
907template <typename T>
928
929
931template <typename T>
933{
935 static constexpr bool NonIntegral = std::is_integral_v<T>;
949
951};
952
954template <typename T>
956{
958 static constexpr bool Integral = std::is_integral_v<T>;
959 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
976
978};
979
981template <typename T>
983{
985 static constexpr bool Integral = std::is_integral_v<T>;
986 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
1004
1006};
1007} // end namespace Concept
1008} // end namespace itk
1009
1010#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)
static constexpr unsigned int Dimension
void RequireBooleanExpression(const T &t)
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< Self::IsExact > ExactT
Detail::UniqueType_bool< Self::Integral > IntegralT
Detail::UniqueType_bool< true > TrueT
Detail::UniqueType_bool< false > FalseT
static constexpr bool IsExact
static constexpr bool Integral
Detail::UniqueType_bool< Self::IsExact > ExactT
Detail::UniqueType_bool< false > FalseT
Detail::UniqueType_bool< Self::Integral > IntegralT
Detail::UniqueType_bool< true > TrueT
Detail::UniqueType_bool< Self::Integral > IntegralT
static constexpr bool Integral
Detail::UniqueType_bool< false > FalseT
Detail::UniqueType_bool< Self::NonIntegral > NonIntegralT
static constexpr bool NonIntegral
Detail::UniqueType_bool< Self::Unsigned > UnsignedT
void const_constraints(const T1 &d, const T2 &e)
Detail::UniqueType_unsigned_int< D1 - 1 > Type2
Detail::UniqueType_unsigned_int< D1 - 2 > Type3
Detail::UniqueType_unsigned_int< D1 > Type1
Detail::UniqueType_unsigned_int< D1 - 1 > Type2
Detail::UniqueType_unsigned_int< D2 > DT2
Detail::UniqueType_unsigned_int< D1 > DT1
Detail::UniqueType_bool< Self::IsSigned > SignedT
Detail::UniqueType_bool< true > TrueT
static constexpr bool IsSigned