Feature request: A namespace for Box2D

Hi,

I would like to suggest encapsulating Box2D in a namespace, such as "b2".
Along with the advantages of encapsulation, it would also make things easier for people using IDEs with code completion.


Thank you for making this wonderful software!
Great suggestion, model76. In fact, we've already included this in the trunk. The next release ought to have all m_variables stores in the Box2D.Common.b2internal namespace.
The ActionScript version uses namespaces, yes. Were you asking about the C++ version?
Yes, I'm being presumptive, sorry. I guess I was thinking of the variable name issue, and Box2D has fixed that already in v2.0.1, so that didn't make sense.
I meant the C++ version, yes. -Sorry for the confusion 🙂
Nono, my fault. I don't really do C++ well enough to answer your (now clarified) question, though.
I wrote the C++ version to work with poor C++ compilers where namespace support can be spotty. Also, in my experience most game programmers don't use C++ namespaces.
Erin Catto wrote:
Also, in my experience most game programmers don't use C++ namespaces.

Really? Too bad for them! Namespaces ROCK! 😀
I certainly wouldn't want to be without them.

Anyway, I see your point about shady compilers, as compatibility rocks even more than namespaces. It would be a shame to leave out exotic platforms, such as mobile phones, drawing pads, refrigerators, and intelligent hairdryers, and what not.

Keep up the good work!
Erin Catto wrote:
I wrote the C++ version to work with poor C++ compilers where namespace support can be spotty. Also, in my experience most game programmers don't use C++ namespaces.


It shouldn't be unreasonable to conditionalize the use of namespaces, although it'd probably make for redundant references (i.e. "b2::b2World").

Internally, there's a "struct Point" that conflicted with Mac OS X headers' Point.

I'd love to see it all in a namespace. Are there really that many compilers in use today for Box2D projects that also don't understand namespaces?
Well, it's relatively easy to wrap it all in a namespace for your own project.

Just make this file:
Code:
namespace box2d {
#include "Box2D.h"
}


Are there really compilers these days that don't do namespaces well? Do people still use them? I think it makes a lot of sense for C++ libraries to live within a namespace.

Original thread: https://box2d.org/forum/viewtopic.php?t=1876