MongoDB C++ Driver
mongocxx-3.7.0
|
Class representing a view-or-value variant type for strings. More...
#include <view_or_value.hpp>
Public Member Functions | |
view_or_value ()=default | |
Default constructor, equivalent to using an empty string. | |
view_or_value (const char *str) | |
Construct a string::view_or_value using a null-terminated const char *. More... | |
view_or_value (const std::string &str) | |
Allow construction with an l-value reference to a std::string. More... | |
view_or_value | terminated () const |
Return a string_view_or_value that is guaranteed to hold a null-terminated string. More... | |
const char * | data () const |
Call data() on this view_or_value's string_view. More... | |
Public Member Functions inherited from bsoncxx::view_or_value< stdx::string_view, std::string > | |
view_or_value ()=default | |
Class View must be constructible from an instance of class Value. More... | |
view_or_value (stdx::string_view view) | |
Construct a view_or_value from a View. More... | |
view_or_value (std::string &&value) | |
Constructs a view_or_value from a Value type. More... | |
view_or_value (const view_or_value &other) | |
Construct a view_or_value from a copied view_or_value. | |
view_or_value (view_or_value &&other) noexcept | |
Construct a view_or_value from a moved-in view_or_value. More... | |
view_or_value & | operator= (const view_or_value &other) |
Assign to this view_or_value from a copied view_or_value. | |
view_or_value & | operator= (view_or_value &&other) noexcept |
Assign to this view_or_value from a moved-in view_or_value. More... | |
bool | is_owning () const noexcept |
Return whether or not this view_or_value owns an underlying Value. More... | |
operator stdx::string_view () const | |
This type may be used as a View. More... | |
const stdx::string_view & | view () const |
Get a View for the type. More... | |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const view_or_value &lhs, const char *rhs) |
Comparison operators for comparing string::view_or_value directly with const char *. | |
Related Functions inherited from bsoncxx::view_or_value< stdx::string_view, std::string > | |
bool | operator== (const view_or_value< stdx::string_view, std::string > &lhs, const view_or_value< stdx::string_view, std::string > &rhs) |
Compare view_or_value objects for (in)-equality. | |
bool | operator== (const view_or_value< stdx::string_view, std::string > &lhs, stdx::string_view rhs) |
Mixed (in)-equality operators for view_or_value against View or Value types. | |
Class representing a view-or-value variant type for strings.
This class adds several string-specific methods to the bsoncxx::view_or_value template:
|
inline |
Construct a string::view_or_value using a null-terminated const char *.
The resulting view_or_value will keep a string_view of 'str', so it is important that the passed-in string outlive this object.
str | A null-terminated string |
|
inline |
Allow construction with an l-value reference to a std::string.
The resulting view_or_value will keep a string_view of 'str', so it is important that the passed-in string outlive this object.
Construction calls passing a std::string by r-value reference will use the constructor defined in the parent view_or_value class.
str | A std::string l-value reference. |
const char* bsoncxx::string::view_or_value::data | ( | ) | const |
Call data() on this view_or_value's string_view.
This method is not guaranteed to return a null-terminated string unless it is used in combination with terminated().
view_or_value bsoncxx::string::view_or_value::terminated | ( | ) | const |
Return a string_view_or_value that is guaranteed to hold a null-terminated string.
The lifetime of the returned object must be a subset of this object's lifetime, because the new view_or_value might hold a view into this one.
It is recommended that this method be used before calling .data() on a view_or_value, as that method may return a non-null-terminated string.