From ce081f17302b8a4029e9773aa2a6998e9701f0dc Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 12 Nov 2014 09:57:52 -0800 Subject: [PATCH] add mention of always using std:: for cmath --- docs/contributing.markdown | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/contributing.markdown b/docs/contributing.markdown index 7130880f3..356e23f8e 100644 --- a/docs/contributing.markdown +++ b/docs/contributing.markdown @@ -85,6 +85,21 @@ Mapnik is written in C++, and we try to follow general coding guidelines. If you see bits of code around that do not follow these please don't hesitate to flag the issue or correct it yourself. +#### Prefix cmath functions with std:: + +The avoids ambiguity and potential bugs of using old C library math directly. + +So always do `std::abs()` instead of `abs()`. Here is a script to fix your code in one fell swoop: + + +```sh +DIR=./bindings +for i in {abs,fabs,tan,sin,cos,floor,ceil,atan2,acos,asin}; do + find $DIR -type f -name '*.cpp' -or -name '*.h' -or -name '*.hpp' | xargs perl -i -p -e "s/ $i\(/ std::$i\(/g;" + find $DIR -type f -name '*.cpp' -or -name '*.h' -or -name '*.hpp' | xargs perl -i -p -e "s/\($i\(/\(std::$i\(/g;" +done +``` + #### Avoid boost::lexical_cast It's slow both to compile and at runtime.