BSONForEach MACRO requires "using namespace::mongo"

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Trivial - P5
    • legacy-0.10.0
    • Affects Version/s: legacy-0.0-26compat-2.6.1
    • Component/s: BSON
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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

              Assignee:
              Andrew Morrow (Inactive)
              Reporter:
              Thomas Riccardi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: