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 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/include/templates.hh (Version 11.3.0) and /global/management/include/templates.hh (Version 9.3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // Module defining platform dependent features <<  26 //
                                                   >>  27 // $Id: templates.hh,v 1.13 2008/08/15 12:15:53 gcosmo Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-02 $
                                                   >>  29 //
                                                   >>  30 // 
                                                   >>  31 // -*- C++ -*-
                                                   >>  32 //
                                                   >>  33 // -----------------------------------------------------------------------
                                                   >>  34 // This file should define some platform dependent features and some
                                                   >>  35 // useful utilities.
                                                   >>  36 // -----------------------------------------------------------------------
                                                   >>  37 
                                                   >>  38 // =======================================================================
                                                   >>  39 // Gabriele Cosmo - Created: 5th September 1995
                                                   >>  40 // Gabriele Cosmo - Minor change: 08/02/1996
                                                   >>  41 // Gabriele Cosmo - Added DBL_MIN, FLT_MIN, DBL_DIG,
                                                   >>  42 //                        DBL_MAX, FLT_DIG, FLT_MAX  : 12/04/1996
                                                   >>  43 // Gabriele Cosmo - Removed boolean enum definition : 29/11/1996
                                                   >>  44 // Gunter Folger  - Added G4SwapPtr() and G4SwapObj() : 31/07/1997
                                                   >>  45 // Gabriele Cosmo - Adapted signatures of min(), max() to
                                                   >>  46 //                  STL's ones, thanks to E.Tcherniaev : 31/07/1997
                                                   >>  47 // Gabriele Cosmo,
                                                   >>  48 // Evgueni Tcherniaev - Migrated to CLHEP: 04/12/1997 
                                                   >>  49 // =======================================================================
 27                                                    50 
 28 // Author: Gabriele Cosmo, 5 September 1995 -  <<  51 #ifndef templates_h
 29 // ------------------------------------------- <<  52 #define templates_h 1
 30 #ifndef templates_hh                           << 
 31 #define templates_hh 1                         << 
 32                                                    53 
 33 #include <climits>                             << 
 34 #include <limits>                                  54 #include <limits>
                                                   >>  55 #include <climits>
 35                                                    56 
                                                   >>  57 //
 36 // If HIGH_PRECISION is defined to TRUE (ie. !     58 // If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float"
 37 // is typedefed to "double". If it is FALSE (i     59 // is typedefed to "double". If it is FALSE (ie. 0) it is typedefed
 38 // to "float".                                     60 // to "float".
 39 //                                                 61 //
 40 #ifndef HIGH_PRECISION                             62 #ifndef HIGH_PRECISION
 41 #  define HIGH_PRECISION 1                     <<  63 #define HIGH_PRECISION 1
 42 #endif                                             64 #endif
 43                                                    65 
 44 #if HIGH_PRECISION                                 66 #if HIGH_PRECISION
 45 using Float = double;                          <<  67 typedef double Float;
 46 #else                                              68 #else
 47 using Float = float;                           <<  69 typedef float Float;
 48 #endif                                             70 #endif
 49                                                    71 
 50 // Following values have been taken from limit     72 // Following values have been taken from limits.h
 51 // and temporarly defined for portability on H     73 // and temporarly defined for portability on HP-UX.
 52                                                    74 
 53 #ifndef DBL_MIN /* Min decimal value of a doub <<  75 #ifndef DBL_MIN   /* Min decimal value of a double */
 54 #  define DBL_MIN std::numeric_limits<double>: <<  76 #define DBL_MIN   std::numeric_limits<double>::min()  // 2.2250738585072014e-308
 55 #endif                                             77 #endif
 56                                                    78 
 57 #ifndef DBL_DIG /* Digits of precision of a do <<  79 #ifndef DBL_DIG   /* Digits of precision of a double */
 58 #  define DBL_DIG std::numeric_limits<double>: <<  80 #define DBL_DIG   std::numeric_limits<double>::digits10   // 15
 59 #endif                                             81 #endif
 60                                                    82 
 61 #ifndef DBL_MAX /* Max decimal value of a doub <<  83 #ifndef DBL_MAX   /* Max decimal value of a double */
 62 #  define DBL_MAX std::numeric_limits<double>: <<  84 #define DBL_MAX   std::numeric_limits<double>::max()  // 1.7976931348623157e+308
 63 #endif                                             85 #endif
 64                                                    86 
 65 #ifndef DBL_EPSILON                                87 #ifndef DBL_EPSILON
 66 #  define DBL_EPSILON std::numeric_limits<doub <<  88 #define DBL_EPSILON std::numeric_limits<double>::epsilon()
 67 #endif  // 2.2204460492503131e-16              <<  89 #endif                                                // 2.2204460492503131e-16
 68                                                    90 
 69 #ifndef FLT_MIN /* Min decimal value of a floa <<  91 #ifndef FLT_MIN   /* Min decimal value of a float */
 70 #  define FLT_MIN std::numeric_limits<float>:: <<  92 #define FLT_MIN   std::numeric_limits<float>::min()   // 1.17549435e-38F
 71 #endif                                             93 #endif
 72                                                    94 
 73 #ifndef FLT_DIG /* Digits of precision of a fl <<  95 #ifndef FLT_DIG   /* Digits of precision of a float */
 74 #  define FLT_DIG std::numeric_limits<float>:: <<  96 #define FLT_DIG   std::numeric_limits<float>::digits10     // 6
 75 #endif                                             97 #endif
 76                                                    98 
 77 #ifndef FLT_MAX /* Max decimal value of a floa <<  99 #ifndef FLT_MAX   /* Max decimal value of a float */
 78 #  define FLT_MAX std::numeric_limits<float>:: << 100 #define FLT_MAX   std::numeric_limits<float>::max()   // 3.40282347e+38F
 79 #endif                                            101 #endif
 80                                                   102 
 81 #ifndef FLT_EPSILON                               103 #ifndef FLT_EPSILON
 82 #  define FLT_EPSILON std::numeric_limits<floa << 104 #define FLT_EPSILON std::numeric_limits<float>::epsilon()
 83 #endif  // 1.192092896e-07F                    << 105 #endif                                                // 1.192092896e-07F
 84                                                   106 
 85 #ifndef MAXFLOAT /* Max decimal value of a flo << 107 #ifndef MAXFLOAT   /* Max decimal value of a float */
 86 #  define MAXFLOAT std::numeric_limits<float>: << 108 #define MAXFLOAT  std::numeric_limits<float>::max()   // 3.40282347e+38F
 87 #endif                                         << 
 88                                                << 
 89 #ifndef INT_MAX /* Max decimal value of a int  << 
 90 #  define INT_MAX std::numeric_limits<int>::ma << 
 91 #endif                                         << 
 92                                                << 
 93 #ifndef INT_MIN /* Min decimal value of a int  << 
 94 #  define INT_MIN std::numeric_limits<int>::mi << 
 95 #endif                                         << 
 96                                                << 
 97 #ifndef LOG_EKIN_MIN /* Min value of the natur << 
 98 #  define LOG_EKIN_MIN -30                     << 
 99 #endif                                            109 #endif
100                                                   110 
101 //---------------------------------               111 //---------------------------------
102                                                   112 
103 template <class T>                                113 template <class T>
104 inline void G4SwapPtr(T*& a, T*& b)            << 114 inline void G4SwapPtr(T*& a, T*& b) {
105 {                                              << 115   T* tmp= a;
106   T* tmp = a;                                  << 116   a = b;
107   a      = b;                                  << 117   b = tmp;
108   b      = tmp;                                << 
109 }                                                 118 }
110                                                   119 
111 template <class T>                                120 template <class T>
112 inline void G4SwapObj(T* a, T* b)              << 121 inline void G4SwapObj(T* a, T* b) {
113 {                                              << 122   T tmp= *a;
114   T tmp = *a;                                  << 123   *a = *b;
115   *a    = *b;                                  << 124   *b = tmp;
116   *b    = tmp;                                 << 
117 }                                                 125 }
118                                                   126 
119 //-----------------------------                   127 //-----------------------------
120                                                   128 
121 #ifndef G4_SQR_DEFINED                            129 #ifndef G4_SQR_DEFINED
122 #  define G4_SQR_DEFINED                       << 130   #define G4_SQR_DEFINED
123 #  ifdef sqr                                   << 131   #ifdef sqr
124 #    undef sqr                                 << 132     #undef sqr
125 #  endif                                       << 133   #endif
126                                                   134 
127 template <class T>                                135 template <class T>
128 inline T sqr(const T& x)                          136 inline T sqr(const T& x)
129 {                                                 137 {
130   return x * x;                                << 138   return x*x;
131 }                                                 139 }
132 #endif                                            140 #endif
133                                                   141 
134 inline int G4lrint(double ad)                  << 142 #ifdef G4_ABS_DEFINED
                                                   >> 143   #ifdef abs
                                                   >> 144     #undef abs
                                                   >> 145   #endif
                                                   >> 146 template <class T>
                                                   >> 147 inline T std::abs(const T& a)
135 {                                                 148 {
136   return (int)std::lrint(ad);                  << 149   return a < 0 ? -a : a;
137 }                                                 150 }
                                                   >> 151 #endif
138                                                   152 
139 //-----------------------------                << 153 #endif // templates_h
140                                                << 
141 //  Use the following function to get rid of " << 
142 //  Example:                                   << 
143 //                                             << 
144 //      #ifdef SOME_CONDITION                  << 
145 //          void doSomething(int val)          << 
146 //          {                                  << 
147 //              something = val;               << 
148 //          }                                  << 
149 //      #else                                  << 
150 //          void doSomething(int)              << 
151 //          { }                                << 
152 //      #endif                                 << 
153 //                                             << 
154 //  can be simplified to:                      << 
155 //                                             << 
156 //          void doSomething(int val)          << 
157 //          {                                  << 
158 //      #ifdef SOME_CONDITION                  << 
159 //              something = val;               << 
160 //      #else                                  << 
161 //              G4ConsumeParameters(val);      << 
162 //      #endif                                 << 
163 //          }                                  << 
164 //                                             << 
165 //  or:                                        << 
166 //                                             << 
167 //          void doSomething(int val)          << 
168 //          {                                  << 
169 //      #ifdef SOME_CONDITION                  << 
170 //              something = val;               << 
171 //      #endif                                 << 
172 //              // function call does nothing  << 
173 //              G4ConsumeParameters(val);      << 
174 //          }                                  << 
175 //                                             << 
176 template <typename... _Args>                   << 
177 inline void G4ConsumeParameters(_Args&&...)    << 
178 {}                                             << 
179                                                << 
180 #endif  // templates_hh                        << 
181                                                   154