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
80# define itkConceptConstraintsMacro() \
81 virtual void Enforcer() { &Constraints::constraints; }
82# define itkConceptMacro(name, concept) \
83 enum \
84 { \
85 name = sizeof concept \
86 }
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
110
114{
115
121
123namespace Detail
124{
125template <typename T>
127{};
128template <int>
130{};
131template <unsigned int>
134template <bool>
136{};
137
143template <typename T>
144inline void
147
153template <typename T>
154void
156{
157 const 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;
192
195 }
196
197 void
198 const_constraints(const T & a)
199 {
200 T c(a);
201 const T * p = &a;
202
205 }
206
207 T b;
208 };
209
211};
212
214template <typename T1, typename T2>
216{
218 {
219 void
221 {
222 auto b = static_cast<T2>(a);
223
225 }
226
227 T1 a;
228 };
230};
231
233template <typename T>
235{
237 {
238 void
240 {
241 T x = a;
243 }
244
245 void
246 const_constraints(const T & b)
247 {
248 a = b;
249 }
250
251 T a;
252 };
253
255};
256
259template <typename T1, typename T2 = T1>
261{
263 {
264 void
270
271 T1 a;
272 T2 b;
273 };
274
276};
277
280template <typename T1, typename T2 = T1>
282{
284 {
285 void
291
292 T1 a;
293 T2 b;
294 };
295
297};
298
301template <typename T1, typename T2 = T1>
303{
305 {
306 void
308 {
309 ITK_GCC_PRAGMA_PUSH
310 ITK_GCC_SUPPRESS_Wfloat_equal
313 ITK_GCC_PRAGMA_POP
314 }
315
316 T1 a;
317 T2 b;
318 };
319
321};
322
325template <typename T1, typename T2 = T1>
327{
329 {
330 void
332 {
337 ITK_GCC_PRAGMA_PUSH
338 ITK_GCC_SUPPRESS_Wfloat_equal
341 ITK_GCC_PRAGMA_POP
342 }
343
344 T1 a;
345 T2 b;
346 };
347
349};
350
353template <typename T1, typename T2 = T1, typename T3 = T1>
355{
357 {
358 void
360 {
361 a = static_cast<T3>(b + c);
362 a = static_cast<T3>(b - c);
364 }
365
366 void
367 const_constraints(const T1 & d, const T2 & e)
368 {
369 a = static_cast<T3>(d + e);
370 a = static_cast<T3>(d - e);
371 }
372
373 T3 a;
374 T1 b;
375 T2 c;
376 };
377
379};
380
381
384template <typename T1, typename T2 = T1>
386{
388 {
389 void
391 {
392 a += c;
393 a -= c;
395 }
396
397 void
398 const_constraints(const T1 & d)
399 {
400 a += d;
401 a -= d;
402 }
403
404 T2 a;
405 T1 c;
406 };
407
409};
410
412template <typename T1, typename T2 = T1, typename T3 = T1>
414{
416 {
417 void
419 {
420 a = static_cast<T3>(b * c);
422 }
423
424 void
425 const_constraints(const T1 & d, const T2 & e)
426 {
427 a = static_cast<T3>(d * e);
428 }
429
430 T3 a;
431 T1 b;
432 T2 c;
433 };
435};
436
438template <typename T1, typename T2 = T1>
440{
442 {
443 void
445 {
446 a *= b;
448 }
449
450 void
451 const_constraints(const T1 & d)
452 {
453 a *= d;
454 }
455
456 T2 a;
457 T1 b;
458 };
459
461};
462
464template <typename T1, typename T2 = T1, typename T3 = T1>
466{
468 {
469 void
471 {
472 a = static_cast<T3>(b / c);
474 }
475
476 void
477 const_constraints(const T1 & d, const T2 & e)
478 {
479 a = static_cast<T3>(d / e);
480 }
481
482 T3 a;
483 T1 b;
484 T2 c;
485 };
486
488};
489
490
492template <typename T1, typename T2 = T1>
494{
496 {
497 void
499 {
500 a /= c;
502 }
503
504 void
505 const_constraints(const T1 & d)
506 {
507 a /= d;
508 }
509
510 T1 c;
511 T2 a;
512 };
513
515};
516
517
520template <typename T1, typename T2 = T1, typename T3 = T1>
522{
524 {
525 void
527 {
528 a = static_cast<T3>(b & c);
529 a = static_cast<T3>(b | c);
530 a = static_cast<T3>(b ^ c);
531 a &= static_cast<T3>(c);
532 a |= static_cast<T3>(c);
533 a ^= static_cast<T3>(c);
535 }
536
537 void
538 const_constraints(const T1 & d, const T2 & e)
539 {
540 a = static_cast<T3>(d & e);
541 a = static_cast<T3>(d | e);
542 a = static_cast<T3>(d ^ e);
543 a &= static_cast<T3>(e);
544 a |= static_cast<T3>(e);
545 a ^= static_cast<T3>(e);
546 }
547
548 T3 a;
549 T1 b;
550 T2 c;
551 };
552
554};
555
557template <typename T1, typename T2 = T1, typename T3 = T1>
559{
561 {
562 void
564 {
565 a = static_cast<T3>(b[c]);
567 }
568
569 void
570 const_constraints(const T1 & d, const T2 & e)
571 {
572 a = static_cast<T3>(d[e]);
573 }
574
575 T3 a;
576 T1 b;
577 T2 c;
578 };
579
581};
582
584template <typename T>
586{
588 {
589 void
591 {
592 a = !a;
593 }
594
595 T a;
596 };
597
599};
600
602template <typename T>
604{
606 {
607 void
609 {
610 a++;
611 a--;
612 ++a;
613 --a;
614 }
615
616 T a;
617 };
618
620};
621
623template <typename T>
625{
627 {
628 void
630 {
631 std::cout << a;
632 }
633
634 T a;
635 };
636
638};
639
641template <typename T>
661
663template <typename T1, typename T2>
665{
667 {
668 void
674 };
676};
677
679template <unsigned int D1, unsigned int D2>
696
698template <typename T>
734
736template <typename T>
752
754template <typename T>
756{
758 {
759 void
764 };
765
767};
768
770template <typename T>
772{
774 {
775 void
777 {
778 T a;
779
780 a = T{};
782 }
783 };
784
786};
787
789template <typename T1, typename T2>
803
805template <unsigned int D1, unsigned int D2>
807{
809 {
812
813 void
815 {}
816 void
817 f(Type2, int = 0)
818 {}
819
820 void
822 {
824 this->f(tt);
825 }
826 };
828};
829
831template <unsigned int D1, unsigned int D2>
833{
835 {
839
840 void
842 {}
843 void
844 f(Type2, int = 0)
845 {}
846 void
847 f(Type3, int = 0, int = 0)
848 {}
849
850 void
852 {
854 this->f(tt);
855 }
856 };
858};
859
861template <typename T>
863{
865 static constexpr bool Integral = std::is_integral_v<T>;
878
880};
881
882
884template <typename T>
904
905
907template <typename T>
909{
911 static constexpr bool NonIntegral = std::is_integral_v<T>;
924
926};
927
929template <typename T>
931{
933 static constexpr bool Integral = std::is_integral_v<T>;
934 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
950
952};
953
955template <typename T>
957{
959 static constexpr bool Integral = std::is_integral_v<T>;
960 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
977
979};
980} // namespace itk::Concept
981
982#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)
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