~singpolyma/biboumi

ref: 655bc344d47bc79e500a351c2953f6b5003f40ec biboumi/src/utils/optional_bool.hpp -rw-r--r-- 597 bytes
655bc344 — louiz’ Add a missing ostream include 2 years ago
                                                                                
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
#pragma once

#include <ostream>
#include <string>

struct OptionalBool
{
  OptionalBool() = default;

  explicit OptionalBool(bool value):
  is_set(true), value(value) {}

  void set_value(bool value)
  {
    this->is_set = true;
    this->value = value;
  }

  void unset()
  {
    this->is_set = false;
  }

  std::string to_string() const
  {
    if (this->is_set == false)
      return "unset";
    else if (this->value)
      return "true";
    else
      return "false";
  }

  bool is_set{false};
  bool value{false};
};

std::ostream& operator<<(std::ostream& os, const OptionalBool& o);