libkazv
maybe.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of libkazv.
3  * SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
4  * SPDX-License-Identifier: AGPL-3.0-or-later
5  */
6 
7 #pragma once
8 #include "libkazv-config.hpp"
9 
10 #include <string>
11 #include <optional>
12 
13 namespace Kazv
14 {
15  class NotBut
16  {
17  std::string m_reason;
18  public:
19  explicit NotBut(std::string r) : m_reason(r) {}
20  std::string reason() const { return m_reason; }
21  };
22 
23  template<class T>
24  class Maybe : public std::optional<T>
25  {
26  std::string m_reason;
27  using BaseT = std::optional<T>;
28  public:
29  Maybe(T x) : BaseT(std::move(x)) {}
30  Maybe(NotBut r) : BaseT(), m_reason(r.reason()) {}
31 
32  std::string reason() const { return m_reason; }
33  };
34 
36 }
Definition: maybe.hpp:25
Maybe(NotBut r)
Definition: maybe.hpp:30
std::string reason() const
Definition: maybe.hpp:32
Maybe(T x)
Definition: maybe.hpp:29
Definition: maybe.hpp:16
NotBut(std::string r)
Definition: maybe.hpp:19
std::string reason() const
Definition: maybe.hpp:20
Definition: location.hpp:10
Definition: clientutil.hpp:217