bsoncxx: document::view vs document::value

1k Views Asked by At

Please explain the difference between bsoncxx::document::value and bsoncxx::document::view. Is view just a proxy to value class?

2

There are 2 best solutions below

1
acm On BEST ANSWER

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 a view from the value. The view and value here are analogous to the relationship between std::string and std::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.

0
jazzandrock On

Yes, view is a proxy for value.