CppAD: A C++ Algorithmic Differentiation Package 20110419
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_CHECK_NUMERIC_TYPE_INCLUDED 00003 # define CPPAD_CHECK_NUMERIC_TYPE_INCLUDED 00004 00005 /* -------------------------------------------------------------------------- 00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-06 Bradley M. Bell 00007 00008 CppAD is distributed under multiple licenses. This distribution is under 00009 the terms of the 00010 Common Public License Version 1.0. 00011 00012 A copy of this license is included in the COPYING file of this distribution. 00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00014 -------------------------------------------------------------------------- */ 00015 /* 00016 $begin CheckNumericType$$ 00017 $spell 00018 cppad.hpp 00019 CppAD 00020 $$ 00021 00022 $section Check NumericType Class Concept$$ 00023 00024 $index numeric, check$$ 00025 $index check, numeric$$ 00026 $index concept, check numeric$$ 00027 00028 $head Syntax$$ 00029 $code # include <cppad/check_numeric_type.hpp>$$ 00030 $pre 00031 $$ 00032 $syntax%CheckNumericType<%NumericType%>()%$$ 00033 00034 00035 $head Purpose$$ 00036 The syntax 00037 $syntax% 00038 CheckNumericType<%NumericType%>() 00039 %$$ 00040 preforms compile and run time checks that the type specified 00041 by $italic NumericType$$ satisfies all the requirements for 00042 a $xref/NumericType/$$ class. 00043 If a requirement is not satisfied, 00044 a an error message makes it clear what condition is not satisfied. 00045 00046 $head Include$$ 00047 The file $code cppad/check_numeric_type.hpp$$ is included by $code cppad/cppad.hpp$$ 00048 but it can also be included separately with out the rest 00049 if the CppAD include files. 00050 00051 $head Example$$ 00052 $children% 00053 example/check_numeric_type.cpp 00054 %$$ 00055 The file $xref/CheckNumericType.cpp/$$ 00056 contains an example and test of this function. 00057 It returns true, if it succeeds an false otherwise. 00058 The comments in this example suggest a way to change the example 00059 so an error message occurs. 00060 00061 $end 00062 --------------------------------------------------------------------------- 00063 */ 00064 00065 00066 00067 namespace CppAD { 00068 00069 # ifdef NDEBUG 00070 template <class NumericType> 00071 inline void CheckNumericType(void) 00072 { } 00073 # else 00074 template <class NumericType> 00075 NumericType CheckNumericType(void) 00076 { // only need execute once per value NumericType type 00077 static bool runOnce = false; 00078 if( runOnce ) 00079 return NumericType(0); 00080 runOnce = true; 00081 00082 /* 00083 contructors 00084 */ 00085 NumericType check_NumericType_default_constructor; 00086 NumericType check_NumericType_constructor_from_int(1); 00087 00088 const NumericType x(1); 00089 00090 NumericType check_NumericType_copy_constructor(x); 00091 00092 // assignment 00093 NumericType check_NumericType_assignment; 00094 check_NumericType_assignment = x; 00095 00096 /* 00097 unary operators 00098 */ 00099 const NumericType check_NumericType_unary_plus(1); 00100 NumericType check_NumericType_unary_plus_result = 00101 + check_NumericType_unary_plus; 00102 00103 const NumericType check_NumericType_unary_minus(1); 00104 NumericType check_NumericType_unary_minus_result = 00105 - check_NumericType_unary_minus; 00106 00107 /* 00108 binary operators 00109 */ 00110 const NumericType check_NumericType_binary_addition(1); 00111 NumericType check_NumericType_binary_addition_result = 00112 check_NumericType_binary_addition + x; 00113 00114 const NumericType check_NumericType_binary_subtraction(1); 00115 NumericType check_NumericType_binary_subtraction_result = 00116 check_NumericType_binary_subtraction - x; 00117 00118 const NumericType check_NumericType_binary_multiplication(1); 00119 NumericType check_NumericType_binary_multiplication_result = 00120 check_NumericType_binary_multiplication * x; 00121 00122 const NumericType check_NumericType_binary_division(1); 00123 NumericType check_NumericType_binary_division_result = 00124 check_NumericType_binary_division / x; 00125 00126 /* 00127 computed assignment operators 00128 */ 00129 NumericType 00130 check_NumericType_computed_assignment_addition(1); 00131 check_NumericType_computed_assignment_addition += x; 00132 00133 NumericType 00134 check_NumericType_computed_assignment_subtraction(1); 00135 check_NumericType_computed_assignment_subtraction -= x; 00136 00137 NumericType 00138 check_NumericType_computed_assignment_multiplication(1); 00139 check_NumericType_computed_assignment_multiplication *= x; 00140 00141 NumericType 00142 check_NumericType_computed_assignment_division(1); 00143 check_NumericType_computed_assignment_division /= x; 00144 00145 /* 00146 use all values so as to avoid warnings 00147 */ 00148 check_NumericType_default_constructor = x; 00149 return 00150 + check_NumericType_default_constructor 00151 + check_NumericType_constructor_from_int 00152 + check_NumericType_copy_constructor 00153 + check_NumericType_assignment 00154 + check_NumericType_unary_plus_result 00155 + check_NumericType_unary_minus_result 00156 + check_NumericType_binary_addition_result 00157 + check_NumericType_binary_subtraction_result 00158 + check_NumericType_binary_multiplication_result 00159 + check_NumericType_binary_division_result 00160 + check_NumericType_computed_assignment_addition 00161 + check_NumericType_computed_assignment_subtraction 00162 + check_NumericType_computed_assignment_multiplication 00163 + check_NumericType_computed_assignment_division 00164 ; 00165 } 00166 # endif 00167 00168 } // end namespace CppAD 00169 00170 # endif