add mention of always using std:: for cmath

This commit is contained in:
Dane Springmeyer 2014-11-12 09:57:52 -08:00
parent 1ed2b29f0a
commit ce081f1730

View file

@ -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. 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 #### Avoid boost::lexical_cast
It's slow both to compile and at runtime. It's slow both to compile and at runtime.