-
Type: Bug
-
Resolution: Done
-
Priority: Trivial - P5
-
Affects Version/s: legacy-0.0-26compat-2.6.1
-
Component/s: BSON
In bson/bsonobjiterator.h included from bson/bson.h, a useful foreach macro is defined:
#define BSONForEach(e, obj) \ BSONObjIterator BOOST_PP_CAT(it_,__LINE__)(obj); \ for ( BSONElement e; \ (BOOST_PP_CAT(it_,__LINE__).more() ? \ (e = BOOST_PP_CAT(it_,__LINE__).next(), true) : \ false) ; \ /*nothing*/ )
However it's not directly usable as it does not prefix BSONObjIterator and BSONElement by "mongo::"
Compilation error (clang 3.3):
error: unknown type name 'BSONObjIterator'; did you mean 'mongo::BSONObjIterator'? BSONForEach(e, oSentence.Obj())
It currently requires a "using namespace mongo;" around it.
Also, this macro is not documented here: https://github.com/mongodb/mongo-cxx-driver/wiki/BSON%20Helper%20Functions