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