CBuild
C++ build system with scripts written in c++
Loading...
Searching...
No Matches
CBuild
headers
optional.hpp
Go to the documentation of this file.
1
21
#ifndef __OPTIONAL_HPP__
22
#define __OPTIONAL_HPP__
23
// C++ libraries
24
#include "stdexcept"
25
// Code
26
namespace
lib
{
32
template
<
class
T>
class
optional
{
33
private
:
37
T
var
;
41
bool
null
;
42
43
public
:
47
optional
() {
48
this->null =
true
;
49
}
55
optional
(T val) {
56
this->var = val;
57
this->null =
false
;
58
}
64
void
set
(T val) {
65
this->var = val;
66
this->null =
false
;
67
}
71
void
clear
() {
72
this->null =
true
;
73
}
79
T
get
() {
80
if
(this->null ==
false
) {
81
return
this->
var
;
82
}
else
{
83
throw
new
std::runtime_error(
"Datatype is null"
);
84
}
85
}
91
bool
is
() {
92
return
!this->
null
;
93
}
94
};
95
}
// namespace lib
96
#endif
// __OPTIONAL_HPP__
lib::optional
Optional data type.
Definition
optional.hpp:32
lib::optional::null
bool null
Does values is saved.
Definition
optional.hpp:41
lib::optional::var
T var
Intrnal variable.
Definition
optional.hpp:37
lib::optional::optional
optional()
Create new optional datatype.
Definition
optional.hpp:47
lib::optional::clear
void clear()
Clear value.
Definition
optional.hpp:71
lib::optional::get
T get()
Get value.
Definition
optional.hpp:79
lib::optional::set
void set(T val)
Set value.
Definition
optional.hpp:64
lib::optional::optional
optional(T val)
Create new optional datatype.
Definition
optional.hpp:55
lib::optional::is
bool is()
If value is not null.
Definition
optional.hpp:91
lib
Optional datatype.
Definition
map.hpp:29
Generated by
1.10.0