Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-233

BSONForEach MACRO requires "using namespace::mongo"

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • legacy-0.10.0
    • 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

            Assignee:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Reporter:
            trsystran Thomas Riccardi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: