]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/d/dmd/root/optional.h
d: Merge upstream dmd 3982604c5, druntime bc58b1e9, phobos 12329adb6.
[thirdparty/gcc.git] / gcc / d / dmd / root / optional.h
1 #pragma once
2
3 /**
4 * Optional implementation.
5 *
6 * Copyright: Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
7 * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
8 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/root/optional.h, root/_optional.h)
10 * Documentation: https://dlang.org/phobos/dmd_root_optional.html
11 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/root/optional.h
12 */
13
14 /// Optional type that is either `empty` or contains a value of type `T`
15 template<typename T>
16 struct Optional final
17 {
18 private:
19 /** the value (if present) **/
20 T value;
21
22 /** whether `value` is set **/
23 bool present;
24
25 public:
26 /** Creates an `Optional` with the given value **/
27 Optional(T);
28
29 /** Creates an `Optional` with the given value **/
30 static Optional<T> create(T);
31
32 /** Checks whether this `Optional` contains a value **/
33 bool isPresent() const;
34
35 /** Checks whether this `Optional` does not contain a value **/
36 bool isEmpty() const;
37
38 /** Returns: The value if present **/
39 T get();
40
41 bool hasValue(const T) const;
42 };