2

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

jazzandrock
  • 317
  • 2
  • 10

2 Answers2

3

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.

acm
  • 12,183
  • 5
  • 39
  • 68
  • PS: Note that a `view` does *not* extend the lifetime of the underlying `value`. The lifetimes of all `views` derived from a given `value` must be subsets of the lifetime of the owning `value. – acm Oct 01 '18 at 16:23
1

Yes, view is a proxy for value.

jazzandrock
  • 317
  • 2
  • 10