]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/optional/doc/19_type_requirements.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / optional / doc / 19_type_requirements.qbk
1 
2 [section Type requirements]
3
4 The very minimum requirement of `optional<T>` is that `T` is a complete type and that it has a publicly accessible destructor. `T` doesn't even need to be constructible. You can use a very minimum interface:
5
6 optional<T> o; // uninitialized
7 assert(o == none); // check if initialized
8 assert(!o); //
9 o.value(); // always throws
10
11 But this is practically useless. In order for `optional<T>` to be able to do anything useful and offer all the spectrum of ways of accessing the contained value, `T` needs to have at least one accessible constructor. In that case you need to initialize the optional object with function `emplace()`, or if your compiler does not support it, resort to [link boost_optional.tutorial.in_place_factories In-Place Factories]:
12
13 optional<T> o;
14 o.emplace("T", "ctor", "params");
15
16 If `T` is __MOVE_CONSTRUCTIBLE__, `optional<T>` is also __MOVE_CONSTRUCTIBLE__ and can be easily initialized from an rvalue of type `T` and be passed by value:
17
18 optional<T> o = make_T();
19 optional<T> p = optional<T>();
20
21 If `T` is __COPY_CONSTRUCTIBLE__, `optional<T>` is also __COPY_CONSTRUCTIBLE__ and can be easily initialized from an lvalue of type `T`:
22
23 T v = make_T();
24 optional<T> o = v;
25 optional<T> p = o;
26
27 If `T` is not `MoveAssignable`, it is still possible to reset the value of `optional<T>` using function `emplace()`:
28
29 optional<const T> o = make_T();
30 o.emplace(make_another_T());
31
32 If `T` is `Moveable` (both __MOVE_CONSTRUCTIBLE__ and `MoveAssignable`) then `optional<T>` is also `Moveable` and additionally can be constructed and assigned from an rvalue of type `T`.
33
34 Similarly, if `T` is `Copyable` (both __COPY_CONSTRUCTIBLE__ and `CopyAssignable`) then `optional<T>` is also `Copyable` and additionally can be constructed and assigned from an lvalue of type `T`.
35
36 `T` ['is not] required to be __SGI_DEFAULT_CONSTRUCTIBLE__.
37
38 [endsect]