mongodb/mongo-cxx-driver — pull request #22 by TylerBrock (2014-03-12 16:51:17+00:00)
Title: CXX-80 adapt existing array example from psuedo code

I've adapted the pseudo code example from http://docs.mongodb.org/ecosystem/drivers/cpp-bson-array-examples/

I'm not absolutely positive what the original intent was considering it was non-working code but I think this captures the spirit of the example.

I've put the original here for documentation's sake in case the URL changes.

```cxx
// examples

using namespace mongo;
using namespace bson;

bo an_obj;

/** transform a BSON array into a vector of BSONElements.
we match array # positions with their vector position, and ignore
any fields with non-numeric field names.
*/
vector a = an_obj["x"].Array();

be array = an_obj["x"];
assert( array.isABSONObj() );
assert( array.type() == Array );

// Use BSON_ARRAY macro like BSON macro, but without keys
BSONArray arr = BSON_ARRAY( "hello" << 1 << BSON( "foo" << BSON_ARRAY( "bar" << "baz" << "qux" ) ) );

// BSONArrayBuilder can be used to build arrays without the macro
BSONArrayBuilder b;
b.append(1).append(2).arr();

/** add all elements of the object to the specified vector */
bo myarray = an_obj["x"].Obj();
vector v;
myarray.elems(v);
list L;
myarray.elems(L)

/** add all values of the object to the specified collection. If type mismatches,
exception.
template
void Vals(vector &) const;
template
void Vals(list &) const;
*/

/** add all values of the object to the specified collection. If type mismatches, skip.
template
void vals(vector &) const;
template
void vals(list &) const;
*/
```