genericgeometry/misc.hh
00001 #ifndef DUNE_GENERICGEOMETRY_MISC_HH
00002 #define DUNE_GENERICGEOMETRY_MISC_HH
00003
00004 #include <dune/common/static_assert.hh>
00005
00006 namespace Dune
00007 {
00008
00009 namespace GenericGeometry
00010 {
00011
00012 template< unsigned int n >
00013 struct Faculty
00014 {
00015 enum { value = n * Faculty< n-1 > :: value };
00016 };
00017
00018 template<>
00019 struct Faculty< 0 >
00020 {
00021 enum { value = 1 };
00022 };
00023
00024
00025
00026 template< bool condition, template< bool > class True, template< bool > class False >
00027 struct ProtectedIf;
00028
00029 template< template< bool > class True, template< bool > class False >
00030 struct ProtectedIf< true, True, False >
00031 : public True< true >
00032 {};
00033
00034 template< template< bool > class True, template< bool > class False >
00035 struct ProtectedIf< false, True, False >
00036 : public False< false >
00037 {};
00038
00039
00040
00041 template< template< int > class Operation, int first, int last >
00042 struct ForLoop
00043 {
00044 static void apply ()
00045 {
00046 Operation< first > :: apply();
00047 ForLoop< Operation, first+1, last > :: apply();
00048 }
00049
00050 template< class Type >
00051 static void apply ( Type ¶m )
00052 {
00053 Operation< first > :: apply( param );
00054 ForLoop< Operation, first+1, last > :: apply( param );
00055 }
00056
00057 template< class Type1, class Type2 >
00058 static void apply ( Type1 ¶m1, Type2 ¶m2 )
00059 {
00060 Operation< first > :: apply( param1, param2 );
00061 ForLoop< Operation, first+1, last > :: apply( param1, param2 );
00062 }
00063
00064 template< class Type1, class Type2, class Type3 >
00065 static void apply ( Type1 ¶m1, Type2 ¶m2, Type3 ¶m3 )
00066 {
00067 Operation< first > :: apply( param1, param2, param3 );
00068 ForLoop< Operation, first+1, last > :: apply( param1, param2, param3 );
00069 }
00070
00071 private:
00072 dune_static_assert( (first <= last), "ForLoop: first > last" );
00073 };
00074
00075 template< template< int > class Operation, int last >
00076 struct ForLoop< Operation, last, last >
00077 {
00078 static void apply ()
00079 {
00080 Operation< last > :: apply();
00081 }
00082
00083 template< class Type >
00084 static void apply ( Type ¶m )
00085 {
00086 Operation< last > :: apply( param );
00087 }
00088
00089 template< class Type1, class Type2 >
00090 static void apply ( Type1 ¶m1, Type2 ¶m2 )
00091 {
00092 Operation< last > :: apply( param1, param2 );
00093 }
00094
00095 template< class Type1, class Type2, class Type3 >
00096 static void apply ( Type1 ¶m1, Type2 ¶m2, Type3 ¶m3 )
00097 {
00098 Operation< last > :: apply( param1, param2, param3 );
00099 }
00100 };
00101
00102 }
00103
00104 }
00105
00106 #endif