Fix name collision of min/max with C++ std::min/std::max
authorRoland Schulz <roland@utk.edu>
Fri, 9 Dec 2011 20:22:05 +0000 (15:22 -0500)
committerRoland Schulz <roland@utk.edu>
Sun, 11 Dec 2011 21:14:03 +0000 (16:14 -0500)
min/max is defined as the macro for C compililation and
as std::min/std::max for C++ compilation. New C++ code should not depend
on this so removed macros.h from other headers and added it where
needed. Removed hacks from existing C++ files where they were no longer
necessary.

Fixes issue #806.

Change-Id: I612d00e092ef4979a5a50b4e2d56fb767a04041e

47 files changed:
src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/gmxlib/enxio.c
src/gromacs/gmxlib/pargs.c
src/gromacs/gmxlib/pbc.c
src/gromacs/gmxlib/txtdump.c
src/gromacs/gmxlib/typedefs.c
src/gromacs/gmxpreprocess/add_par.c
src/gromacs/gmxpreprocess/gen_vsite.c
src/gromacs/gmxpreprocess/genhydro.c
src/gromacs/gmxpreprocess/gpp_bond_atomtype.h
src/gromacs/gmxpreprocess/h_db.c
src/gromacs/gmxpreprocess/hackblock.c
src/gromacs/gmxpreprocess/vsite_parm.c
src/gromacs/legacyheaders/gpp_atomtype.h
src/gromacs/legacyheaders/grompp.h
src/gromacs/legacyheaders/macros.h
src/gromacs/legacyheaders/vec.h
src/gromacs/mdlib/constr.c
src/gromacs/mdlib/domdec.c
src/gromacs/mdlib/ewald.c
src/gromacs/mdlib/md_support.c
src/gromacs/mdlib/mdebin.c
src/gromacs/mdlib/pme.c
src/gromacs/mdlib/pull.c
src/gromacs/mdlib/pull_rotation.c
src/gromacs/mdlib/shellfc.c
src/gromacs/selection/compiler.cpp
src/gromacs/selection/params.cpp
src/gromacs/selection/sm_insolidangle.cpp
src/gromacs/selection/tests/selectioncollection.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/distance.cpp
src/programs/grompp/gpp_tomorse.h
src/programs/grompp/tomorse.c
src/programs/mdrun/runner.c
src/programs/mdrun/xutils.c
src/programs/pdb2gmx/hizzie.c
src/programs/pdb2gmx/pdb2gmx.c
src/programs/pdb2gmx/specbond.c
src/tools/g_anadock.c
src/tools/gmx_current.c
src/tools/gmx_density.c
src/tools/gmx_dyndom.c
src/tools/gmx_pme_error.c
src/tools/gmx_spatial.c
src/tools/gmx_tune_pme.c
src/tools/gmx_wham.c

index a378261b1ec37a24987e58613fccc364d9c8a099..4340933e6a57fe0b1285ac99416888cc666b3312 100644 (file)
@@ -52,9 +52,6 @@
 #include <vec.h>
 #include <xvgr.h>
 
-// FIXME: This kind of trickery should not be necessary...
-#undef min
-#undef max
 #include "gromacs/options/globalproperties.h"
 #include "gromacs/options/options.h"
 #include "gromacs/fatalerror/exceptions.h"
index 5c3266840c07f8dce69b3faf3f9f2c01860c4aaf..48553975c9dca943de7e40db02434b1f107a4a24 100644 (file)
@@ -45,6 +45,7 @@
 #include "enxio.h"
 #include "vec.h"
 #include "xdrf.h"
+#include "macros.h"
 
 /* The source code in this file should be thread-safe. 
          Please keep it that way. */
index 4df3a5149496fc2a1d932aa2af3b5a9e0cdcf392..36f1e8861ca27d404a8f8cf2e0d049369181c464 100644 (file)
@@ -48,6 +48,7 @@
 #include "names.h"
 #include "string2.h"
 #include "vec.h"
+#include "macros.h"
 
 /* The source code in this file should be thread-safe. 
       Please keep it that way. */
index af63fc6d047219aaaae81050ad343c75d115b221..44a0d9562f08ec27cad7966179de91cceafc81b0 100644 (file)
@@ -48,6 +48,7 @@
 #include "txtdump.h"
 #include "gmx_fatal.h"
 #include "names.h"
+#include "macros.h"
 
 /* Skip 0 so we have more chance of detecting if we forgot to call set_pbc. */
 enum { epbcdxRECTANGULAR=1, epbcdxTRICLINIC,
index 33c98378c7ab52821bf3a7e1bb53e5acee2d3e2e..b4194e879b5aa8ba58123bb36a350c90bba069ae 100644 (file)
@@ -50,6 +50,7 @@
 #include "txtdump.h"
 #include "string2.h"
 #include "vec.h"
+#include "macros.h"
 
 
 int pr_indent(FILE *fp,int n)
index 15fcbdc8ecb4cf02c7577b1cc101cff6a66ca80c..100dfd6441e8a30b4e11296e1772a72b7831e13a 100644 (file)
@@ -42,6 +42,7 @@
 #include "symtab.h"
 #include "vec.h"
 #include "pbc.h"
+#include "macros.h"
 #include <string.h>
 
 #ifdef GMX_THREADS
index e2811b088ac5c8b3b2fe696588eb60cc5500e76b..3c73a62bcd6bbccf59af60c2eead5e76a1123527 100644 (file)
@@ -41,6 +41,7 @@
 #include "typedefs.h"
 #include "smalloc.h"
 #include "grompp.h"
+#include "macros.h"
 #include "toputil.h"
 #include "hackblock.h"
 #include "string2.h"
index f3fffdd685cd0c02d78710bd03c277d6cdebca02..55fcff5e458d71dbb7435c6875dc64621a795450 100644 (file)
@@ -52,6 +52,7 @@
 #include "futil.h"
 #include "gpp_atomtype.h"
 #include "fflibutil.h"
+#include "macros.h"
 
 #define MAXNAME 32
 #define OPENDIR        '['     /* starting sign for directive          */
index 94997bfcb9db550475691108241fdd9cfb6545f6..a92e545a4cd53aebc410591c39860c124de37876 100644 (file)
@@ -58,6 +58,7 @@
 #include "resall.h"
 #include "pgutil.h"
 #include "network.h"
+#include "macros.h"
 
 static void copy_atom(t_atoms *atoms1,int a1,t_atoms *atoms2,int a2)
 {
index 9902a839c6cace995b90f74b6fdb9796094a643f..1a514ad26813714513761cd2d0f23d57e30b3a06 100644 (file)
@@ -42,7 +42,6 @@
 
 #include <stdio.h>
 #include "typedefs.h"
-#include "macros.h"
 
 typedef struct gpp_bondatomtype *t_bond_atomtype;
 
index 772f04e5744036c608615e3a4ff37dd86426926a..405036947b56d035fd695551f9c37c1bfa67945d 100644 (file)
@@ -47,6 +47,7 @@
 #include "gmxfio.h"
 #include "fflibutil.h"
 #include "gmx_fatal.h"
+#include "macros.h"
 
 /* There are 11 types of adding hydrogens, numbered from
  * 1 thru 11. Each of these has a specific number of
index c7086b9762a494733680ee9808dc9654edbfb9ba..a0d459fae7100833dba6bf034c5e9848fb67e70c 100644 (file)
@@ -42,6 +42,7 @@
 #include "smalloc.h"
 #include "vec.h"
 #include "string2.h"
+#include "macros.h"
 
 /* these MUST correspond to the enum in hackblock.h */
 const char *btsNames[ebtsNR] = { "bonds", "angles", "dihedrals", "impropers", "exclusions", "cmap" };
index d0688eff9012c264760e13454c2f910aefc7f771..339d3e9204aa0e3205c2373d1ec454a5def02f63 100644 (file)
@@ -51,6 +51,7 @@
 #include "gmx_fatal.h"
 #include "string2.h"
 #include "physics.h"
+#include "macros.h"
 
 typedef struct {
   t_iatom a[4];
index d76f6f297ad3f7d1abd150320bf5388af903fd64..85faa3a29a571965872616aa35d69af26f21711f 100644 (file)
@@ -38,7 +38,6 @@
 
 #include <stdio.h>
 #include "typedefs.h"
-#include "macros.h"
 #include "grompp.h"
 
 #ifdef __cplusplus
index 8121f997414e7d7be8b8b539d9d96cfcb6a21957..f45a79fce88a8283871b47191915188b8076b521 100644 (file)
@@ -38,7 +38,6 @@
 
 #include <stdio.h>
 #include "typedefs.h"
-#include "macros.h"
 
 #ifdef __cplusplus
 extern "C" {
index 3c4c23e8608f68f616e69b9da61949450dbfdda7..456d0f2ea2fd59f64e92594f2919d898ad629f38 100644 (file)
@@ -38,9 +38,7 @@
 
 #include "typedefs.h" /* for real definition only */
 
-#ifdef __cplusplus
-extern "C" { 
-#endif
+/* no extern "C" for this header because it only defines Macros */
 
 /* 
  * With the macros below you don't
@@ -61,6 +59,7 @@ extern "C" {
 #define C4     c[4]
 #define C5     c[5]
 
+#ifndef __cplusplus
 #ifndef min
 #define min(a,b) (((a) < (b)) ? (a) : (b) )
 #endif
@@ -70,6 +69,11 @@ extern "C" {
 #ifndef even
 #define even(a) ( ( (a+1) / 2) == (a / 2) )
 #endif
+#else
+#include <algorithm>
+using std::min;
+using std::max;
+#endif
 
 /* This macro calculates the size of a array */
 #define asize(a) (sizeof(a)/sizeof((a)[0]))
@@ -84,10 +88,6 @@ extern const real SIX;
 extern const real TEN;
 extern const real TWELVE;
 
-#ifdef __cplusplus
-}
-#endif
-
 
 #endif /* _macros_h */
 
index 474a45f2065ad3ff8f7d2b43578551a0eaf109a6..79a761955eb3d50388f1c4f1cf352a655d573de1 100644 (file)
 #include "maths.h"
 #include "typedefs.h"
 #include "sysstuff.h"
-#include "macros.h"
 #include "gmx_fatal.h"
 #include "physics.h"
 
index 815076e60f91221c8f6c10fa9fdefe2a84e64eac..9550ba59e332c855e6166757943f92ebebe02e00 100644 (file)
@@ -55,6 +55,7 @@
 #include "splitter.h"
 #include "mtop_util.h"
 #include "gmxfio.h"
+#include "macros.h"
 
 typedef struct gmx_constr {
   int              ncon_tot;     /* The total number of constraints    */
index ec9775d4fcd504624e5bcfa035b8c71865292507..6fa356ea44b754a62447f50db3d048435ba7a1e8 100644 (file)
@@ -50,6 +50,7 @@
 #include "gmxfio.h"
 #include "gmx_ga2la.h"
 #include "gmx_sort.h"
+#include "macros.h"
 
 #ifdef GMX_LIB_MPI
 #include <mpi.h>
index 4390ed663748f12361d455df98549e534b6bfa43..9fc441946b1bf11f8dff1f70377276ab7e38379e 100644 (file)
@@ -46,6 +46,7 @@
 #include "gmx_fatal.h"
 #include "physics.h"
 #include "coulomb.h"
+#include "macros.h"
 
 #define TOL 2e-5
 
index a03a06bb44ad75e852d579f61d4081dc1e5f68bb..3d2428f15a534486265c3b9c46160cbce2a41e41 100644 (file)
@@ -51,6 +51,7 @@
 #include "gmx_wallcycle.h"
 #include "vcm.h"
 #include "nrnb.h"
+#include "macros.h"
 
 /* Is the signal in one simulation independent of other simulations? */
 gmx_bool gs_simlocal[eglsNR] = { TRUE, FALSE, FALSE, TRUE };
index 204a1305c99ad232d72fdb5b0fd42f5e71048913..230fe8076794de36de0e664df9bcc57518cee27e 100644 (file)
@@ -55,6 +55,7 @@
 #include "mtop_util.h"
 #include "xvgr.h"
 #include "gmxfio.h"
+#include "macros.h"
 
 #include "mdebin_bar.h"
 
index add09f67f5c794f8d9c7ac9970d43127fb2be5ad..aa7cf13009b1747a3acf4c829bce46b409e66306 100644 (file)
@@ -87,6 +87,7 @@
 #include "gmx_wallcycle.h"
 #include "gmx_parallel_3dfft.h"
 #include "pdbio.h"
+#include "macros.h"
 
 #if ( !defined(GMX_DOUBLE) && ( defined(GMX_IA32_SSE) || defined(GMX_X86_64_SSE) || defined(GMX_X86_64_SSE2) ) )
 #include "gmx_sse2_single.h"
index 2d4db43a422bd253c731d28a2978402c408e77b7..df8c75415b85b4c65f46c641d56bfde940e16e38 100644 (file)
@@ -60,6 +60,7 @@
 #include "mdrun.h"
 #include "gmx_ga2la.h"
 #include "copyrite.h"
+#include "macros.h"
 
 static void pull_print_x_grp(FILE *out,gmx_bool bRef,ivec dim,t_pullgrp *pgrp) 
 {
index fd548125582c700fe992eedff82e684b325cc99c..1c27d38565c1f2753aefec52a3c3b4237332bd9e 100644 (file)
@@ -58,6 +58,7 @@
 #include "groupcoord.h"
 #include "pull_rotation.h"
 #include "gmx_sort.h"
+#include "macros.h"
 
 
 static char *RotStr = {"Enforced rotation:"};
index 91d11ecd79b8a44e63d3b424cd5e2437c95ca450..6897fc6835212d9088e772b0dff1f797220d4300 100644 (file)
@@ -55,6 +55,7 @@
 #include "shellfc.h"
 #include "mtop_util.h"
 #include "chargegroup.h"
+#include "macros.h"
 
 
 typedef struct {
index 055f47df116c9fe328485cd7bdd8f07500f41522..7673a7f0fdfa2b9ffbd25765ea5cf346e1f9c2e0 100644 (file)
 #include <config.h>
 #endif
 
+#include <algorithm>
+
 #include <math.h>
 #include <stdarg.h>
 
 #include <string2.h>
 #include <vec.h>
 
-// FIXME: Should really be in the beginning, but causes compilation errors
-#include <algorithm>
-
 #include "gromacs/fatalerror/exceptions.h"
 #include "gromacs/selection/indexutil.h"
 #include "gromacs/selection/poscalc.h"
index e7612979b92925170cb3db2b207a4f5930e6c789..7adaa292b35c1dd94856cecd922f5c73ecf9d64c 100644 (file)
@@ -39,6 +39,8 @@
 #include <config.h>
 #endif
 
+#include <algorithm>
+
 #include <smalloc.h>
 #include <string2.h>
 #include <vec.h>
 #include "scanner.h"
 #include "selelem.h"
 
-template <typename T>
-static T min(T a, T b)
-{
-    return (a < b) ? a : b;
-}
-
-template <typename T>
-static T max(T a, T b)
-{
-    return (a > b) ? a : b;
-}
+using std::min;
+using std::max;
 
 /*!
  * \param[in] name   Name of the parameter to search.
index 75402d826104c643959472ae5d64185324d017fc..b5b3b16fbd6e4d4f76e6c5c30f8dade17ffd8135 100644 (file)
 #include <config.h>
 #endif
 
+#include <algorithm>
+
 #include <math.h>
 
 #include <macros.h>
 #include <smalloc.h>
 #include <vec.h>
 
-// FIXME: Should really be in the beginning, but causes compilation errors
-#include <algorithm>
-
 #include "gromacs/fatalerror/exceptions.h"
 #include "gromacs/selection/indexutil.h"
 #include "gromacs/selection/position.h"
index 4a3416efcaf6c40aa705ef3b8719eab4e5e97e30..9af1a35cf04b9ea97f20a6fa8f12dab831b1ddb4 100644 (file)
@@ -44,9 +44,6 @@
 #include "tpxio.h"
 #include "vec.h"
 
-// FIXME: This kind of hackery should not be necessary
-#undef min
-#undef max
 #include "gromacs/fatalerror/exceptions.h"
 #include "gromacs/selection/poscalc.h"
 #include "gromacs/selection/selectioncollection.h"
index e8ea63c10cc525fadc47c5fce0e869c07898f737..3ecd3f771872ec1c17698e01588bc6d95ea698d4 100644 (file)
@@ -44,9 +44,6 @@
 #include <pbc.h>
 #include <vec.h>
 
-// FIXME: This kind of hackery should not be necessary
-#undef min
-#undef max
 #include "gromacs/analysisdata/analysisdata.h"
 #include "gromacs/analysisdata/modules/plot.h"
 #include "gromacs/fatalerror/exceptions.h"
index 78cabf51657dac1ae2c6473d984ce7fbabae2cb8..5ca7ad41509d47a71dc5aed06406caadc2017482 100644 (file)
@@ -44,9 +44,6 @@
 #include <pbc.h>
 #include <vec.h>
 
-// FIXME: This kind of hackery should not be necessary
-#undef min
-#undef max
 #include "gromacs/analysisdata/analysisdata.h"
 #include "gromacs/analysisdata/modules/average.h"
 #include "gromacs/analysisdata/modules/plot.h"
index 54c37a8e489cd264d1756e9d9e9c81ef223460c0..b8f31d8369826c28e15d9c29738b65663c90874f 100644 (file)
@@ -42,7 +42,6 @@
 
 #include <stdio.h>
 #include "typedefs.h"
-#include "macros.h"
 
 extern void convert_harmonics(int nrmols,t_molinfo mols[],gpp_atomtype_t atype);
 
index de7fbf9b6afc4d245f302eb99b95faa06b41cb67..bd25f712a5f5addddd4d6d969225f14ade07a854 100644 (file)
@@ -49,6 +49,7 @@
 #include "gmx_fatal.h"
 #include "gpp_atomtype.h"
 #include "gpp_tomorse.h"
+#include "macros.h"
 
 typedef struct {
   char *ai,*aj;
index 1e3030fbdc189431ccc59d2cb3d02203ec5d339e..77d9104fe52ecd4eae439a054702449095d66a03 100644 (file)
@@ -73,6 +73,7 @@
 #include "tpxio.h"
 #include "txtdump.h"
 #include "membed.h"
+#include "macros.h"
 
 #include "md_openmm.h"
 
index e374c5d263fe3d1b2d753836a77235a409095666..c5ca942fa90db26dc759bc82ab3d27e1cb160449 100644 (file)
@@ -44,6 +44,7 @@
 #include "vec.h"
 #include "genalg.h"
 #include "random.h"
+#include "macros.h"
 
 real mol_dipole(int k0,int k1,rvec x[],real q[])
 {
index fce3a522f403be96b21a3bc3f145fa2d28b15f20..3a27007d7000beddfd32c16f5bd4af968f1be9a8 100644 (file)
@@ -47,6 +47,7 @@
 #include "toputil.h"
 #include "pdb2top.h"
 #include "string2.h"
+#include "macros.h"
 
 static int in_strings(char *key,int nstr,const char **str)
 {
index 9fe12a8541d471b818c809ead5ce704e02c47ab9..d30f5e489d450f3c71d2a0697442caf29f343b94 100644 (file)
@@ -70,6 +70,7 @@
 #include "index.h"
 #include "hizzie.h"
 #include "fflibutil.h"
+#include "macros.h"
 
 
 typedef struct {
index 245be52b318fcb2e5b5bee78630594caf5120b9f..888ae217e5eda691d81a1e4be17983736262b0e9 100644 (file)
@@ -46,6 +46,7 @@
 #include "specbond.h"
 #include "pdb2top.h"
 #include "vec.h"
+#include "macros.h"
 
 gmx_bool yesno(void)
 {
index e7c7861c60004b4a955c6516bf8812a6b7b5047b..556fd9933d969fe8789bea3be8b2433ae08bac87 100644 (file)
@@ -47,7 +47,8 @@
 #include "statutil.h"
 #include "typedefs.h"
 #include "xvgr.h"
-       
+#include "macros.h"
+
 static const char *etitles[] = { "E-docked", "Free Energy" };
 
 typedef struct {
index c0a7f0f724098968e70754f74dc786d45bbe1d8e..aa0add14fd996694255f9f6dda53ff10659e5328 100644 (file)
@@ -54,6 +54,7 @@
 #include "index.h"
 #include "gmx_statistics.h"
 #include "gmx_ana.h"
+#include "macros.h"
 
 #define SQR(x) (pow(x,2.0))
 #define EPSI0 (EPSILON0*E_CHARGE*E_CHARGE*AVOGADRO/(KILO*NANO)) /* EPSILON0 in SI units */
index 466eeff7cabf5360eab2418efdd79ef1f8ca2ce2..4ad87ccbc9844503fbf6a587ec22ab9612f73bd2 100644 (file)
@@ -55,6 +55,7 @@
 #include "tpxio.h"
 #include "physics.h"
 #include "gmx_ana.h"
+#include "macros.h"
 
 typedef struct {
   char *atomname;
index 235a02678e451cfcb7872f592444c018b570b38c..31143864c555cacad74606fb7e225fb629692287 100644 (file)
@@ -47,6 +47,7 @@
 #include "physics.h"
 #include "random.h"
 #include "gmx_ana.h"
+#include "macros.h"
 
 
 static void rot_conf(t_atoms *atoms,rvec x[],rvec v[],real trans,real angle,
index 42763cff53c2759b0b67c6ef695eff2e65a9d94f..9369f3e2dc1690b4ca2af7323cb23123e57015cd 100644 (file)
@@ -48,6 +48,7 @@
 #include "mtop_util.h"
 #include "network.h"
 #include "main.h"
+#include "macros.h"
 
 /* We use the same defines as in mvdata.c here */
 #define  block_bc(cr,   d) gmx_bcast(     sizeof(d),     &(d),(cr))
index 1cb9ffb19a27524d66953e79ac97e460fb5999ed..6e2604cb2f28ff3ae7adc256c23696a67a1458bb 100644 (file)
@@ -50,6 +50,7 @@
 #include "pbc.h"
 #include "rmpbc.h"
 #include "gmx_ana.h"
+#include "macros.h"
 
 
 static const double bohr=0.529177249;  /* conversion factor to compensate for VMD plugin conversion... */
index fe7528170b05221176a0725c3416600bfb62c9d6..4b854cd01f7c8cbc5e67505288d8b20f87828e49 100644 (file)
@@ -56,6 +56,7 @@
 #include "checkpoint.h"
 #include "gmx_ana.h"
 #include "names.h"
+#include "macros.h"
 
 
 
index 68b4b7ef3e08b5d267e64e9ce3c98801bd05b9e2..5e21c221015bbb131446841011eae0208ee422ff 100644 (file)
@@ -49,6 +49,7 @@
 #include "names.h"
 #include "gmx_random.h"
 #include "gmx_ana.h"
+#include "macros.h"
 
 #ifndef HAVE_STRDUP
 #define HAVE_STRDUP