mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-28 07:59:02 +01:00
SERVER-17640 Add explict BSONElement::operator bool()
Makes it easier to check for a field's existence and use it in a single scan: if (auto elem = myObj["foo"]) { // Use elem } else { // default behavior }
This commit is contained in:
parent
a15dbb65ca
commit
7854198178
@ -114,6 +114,19 @@ namespace mongo {
|
||||
*/
|
||||
bool ok() const { return !eoo(); }
|
||||
|
||||
/**
|
||||
* True if this element has a value (ie not EOO).
|
||||
*
|
||||
* Makes it easier to check for a field's existence and use it:
|
||||
* if (auto elem = myObj["foo"]) {
|
||||
* // Use elem
|
||||
* }
|
||||
* else {
|
||||
* // default behavior
|
||||
* }
|
||||
*/
|
||||
explicit operator bool() const { return ok(); }
|
||||
|
||||
std::string toString( bool includeFieldName = true, bool full=false) const;
|
||||
void toString(StringBuilder& s, bool includeFieldName = true, bool full=false, int depth=0) const;
|
||||
std::string jsonString( JsonStringFormat format, bool includeFieldNames = true, int pretty = 0 ) const;
|
||||
|
Loading…
Reference in New Issue
Block a user