Please explain the difference between bsoncxx::document::value
and bsoncxx::document::view
. Is view
just a proxy to value
class?
bsoncxx: document::view vs document::value
1k Views Asked by jazzandrock At
2
Please explain the difference between bsoncxx::document::value
and bsoncxx::document::view
. Is view
just a proxy to value
class?
In the bsoncxx library,
values
represent ownership of an immutable resource, but not the ability to inspect the owned resource. To inspect the owned resource, you obtain aview
from thevalue
. Theview
andvalue
here are analogous to the relationship betweenstd::string
andstd::string_view
. By separating the aspects of ownership from inspection, we can have a cheap type used for APIs that only need to look at data, and a more expensive API for when we need to make copies or take over ownership of resources.