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
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;
193
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 }
245
246 void
247 const_constraints(const T & b)
248 {
249 a = b;
250 }
251
252 T a;
253 };
254
256};
257
260template <typename T1, typename T2 = T1>
262{
264 {
265 void
271
272 T1 a;
273 T2 b;
274 };
275
277};
278
281template <typename T1, typename T2 = T1>
283{
285 {
286 void
292
293 T1 a;
294 T2 b;
295 };
296
298};
299
302template <typename T1, typename T2 = T1>
304{
306 {
307 void
309 {
310 ITK_GCC_PRAGMA_PUSH
311 ITK_GCC_SUPPRESS_Wfloat_equal
314 ITK_GCC_PRAGMA_POP
315 }
316
317 T1 a;
318 T2 b;
319 };
320
322};
323
326template <typename T1, typename T2 = T1>
328{
330 {
331 void
333 {
338 ITK_GCC_PRAGMA_PUSH
339 ITK_GCC_SUPPRESS_Wfloat_equal
342 ITK_GCC_PRAGMA_POP
343 }
344
345 T1 a;
346 T2 b;
347 };
348
350};
351
354template <typename T1, typename T2 = T1, typename T3 = T1>
356{
358 {
359 void
361 {
362 a = static_cast<T3>(b + c);
363 a = static_cast<T3>(b - c);
365 }
366
367 void
368 const_constraints(const T1 & d, const T2 & e)
369 {
370 a = static_cast<T3>(d + e);
371 a = static_cast<T3>(d - e);
372 }
373
374 T3 a;
375 T1 b;
376 T2 c;
377 };
378
380};
381
382
385template <typename T1, typename T2 = T1>
387{
389 {
390 void
392 {
393 a += c;
394 a -= c;
396 }
397
398 void
399 const_constraints(const T1 & d)
400 {
401 a += d;
402 a -= d;
403 }
404
405 T2 a;
406 T1 c;
407 };
408
410};
411
413template <typename T1, typename T2 = T1, typename T3 = T1>
415{
417 {
418 void
420 {
421 a = static_cast<T3>(b * c);
423 }
424
425 void
426 const_constraints(const T1 & d, const T2 & e)
427 {
428 a = static_cast<T3>(d * e);
429 }
430
431 T3 a;
432 T1 b;
433 T2 c;
434 };
436};
437
439template <typename T1, typename T2 = T1>
441{
443 {
444 void
446 {
447 a *= b;
449 }
450
451 void
452 const_constraints(const T1 & d)
453 {
454 a *= d;
455 }
456
457 T2 a;
458 T1 b;
459 };
460
462};
463
465template <typename T1, typename T2 = T1, typename T3 = T1>
467{
469 {
470 void
472 {
473 a = static_cast<T3>(b / c);
475 }
476
477 void
478 const_constraints(const T1 & d, const T2 & e)
479 {
480 a = static_cast<T3>(d / e);
481 }
482
483 T3 a;
484 T1 b;
485 T2 c;
486 };
487
489};
490
491
493template <typename T1, typename T2 = T1>
495{
497 {
498 void
500 {
501 a /= c;
503 }
504
505 void
506 const_constraints(const T1 & d)
507 {
508 a /= d;
509 }
510
511 T1 c;
512 T2 a;
513 };
514
516};
517
518
521template <typename T1, typename T2 = T1, typename T3 = T1>
523{
525 {
526 void
528 {
529 a = static_cast<T3>(b & c);
530 a = static_cast<T3>(b | c);
531 a = static_cast<T3>(b ^ c);
532 a &= static_cast<T3>(c);
533 a |= static_cast<T3>(c);
534 a ^= static_cast<T3>(c);
536 }
537
538 void
539 const_constraints(const T1 & d, const T2 & e)
540 {
541 a = static_cast<T3>(d & e);
542 a = static_cast<T3>(d | e);
543 a = static_cast<T3>(d ^ e);
544 a &= static_cast<T3>(e);
545 a |= static_cast<T3>(e);
546 a ^= static_cast<T3>(e);
547 }
548
549 T3 a;
550 T1 b;
551 T2 c;
552 };
553
555};
556
558template <typename T1, typename T2 = T1, typename T3 = T1>
560{
562 {
563 void
565 {
566 a = static_cast<T3>(b[c]);
568 }
569
570 void
571 const_constraints(const T1 & d, const T2 & e)
572 {
573 a = static_cast<T3>(d[e]);
574 }
575
576 T3 a;
577 T1 b;
578 T2 c;
579 };
580
582};
583
585template <typename T>
587{
589 {
590 void
592 {
593 a = !a;
594 }
595
596 T a;
597 };
598
600};
601
603template <typename T>
605{
607 {
608 void
610 {
611 a++;
612 a--;
613 ++a;
614 --a;
615 }
616
617 T a;
618 };
619
621};
622
624template <typename T>
626{
628 {
629 void
631 {
632 std::cout << a;
633 }
634
635 T a;
636 };
637
639};
640
642template <typename T>
662
664template <typename T1, typename T2>
666{
668 {
669 void
675 };
677};
678
680template <unsigned int D1, unsigned int D2>
697
699template <typename T>
735
737template <typename T>
753
755template <typename T>
757{
759 {
760 void
765 };
766
768};
769
771template <typename T>
773{
775 {
776 void
778 {
779 T a;
780
781 a = T{};
783 }
784 };
785
787};
788
790template <typename T1, typename T2>
804
806template <unsigned int D1, unsigned int D2>
808{
810 {
813
814 void
816 {}
817 void
818 f(Type2, int = 0)
819 {}
820
821 void
823 {
825 this->f(tt);
826 }
827 };
829};
830
832template <unsigned int D1, unsigned int D2>
834{
836 {
840
841 void
843 {}
844 void
845 f(Type2, int = 0)
846 {}
847 void
848 f(Type3, int = 0, int = 0)
849 {}
850
851 void
853 {
855 this->f(tt);
856 }
857 };
859};
860
862template <typename T>
864{
866 static constexpr bool Integral = std::is_integral_v<T>;
879
881};
882
883
885template <typename T>
905
906
908template <typename T>
910{
912 static constexpr bool NonIntegral = std::is_integral_v<T>;
925
927};
928
930template <typename T>
932{
934 static constexpr bool Integral = std::is_integral_v<T>;
935 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
951
953};
954
956template <typename T>
958{
960 static constexpr bool Integral = std::is_integral_v<T>;
961 static constexpr bool IsExact = std::numeric_limits<typename NumericTraits<T>::ValueType>::is_exact;
978
980};
981} // end namespace Concept
982} // end namespace itk
983
984#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