Seastar
High performance C++ framework for concurrent servers
bool_class.hh
1 /*
2  * This file is open source software, licensed to you under the terms
3  * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4  * distributed with this work for additional information regarding copyright
5  * ownership. You may not use this file except in compliance with the License.
6  *
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14  * KIND, either express or implied. See the License for the
15  * specific language governing permissions and limitations
16  * under the License.
17  */
18 /*
19  * Copyright (C) 2016 ScyllaDB.
20  */
21 
22 #pragma once
23 
24 #include <ostream>
25 
26 namespace seastar {
27 
30 
56 template<typename Tag>
57 class bool_class {
58  bool _value;
59 public:
60  static const bool_class yes;
61  static const bool_class no;
62 
64  constexpr bool_class() noexcept : _value(false) { }
65 
67  constexpr explicit bool_class(bool v) noexcept : _value(v) { }
68 
70  explicit operator bool() const noexcept { return _value; }
71 
73  friend bool_class operator||(bool_class x, bool_class y) noexcept {
74  return bool_class(x._value || y._value);
75  }
76 
78  friend bool_class operator&&(bool_class x, bool_class y) noexcept {
79  return bool_class(x._value && y._value);
80  }
81 
83  friend bool_class operator!(bool_class x) noexcept {
84  return bool_class(!x._value);
85  }
86 
88  friend bool operator==(bool_class x, bool_class y) noexcept {
89  return x._value == y._value;
90  }
91 
93  friend bool operator!=(bool_class x, bool_class y) noexcept {
94  return x._value != y._value;
95  }
96 
98  friend std::ostream& operator<<(std::ostream& os, bool_class v) {
99  return os << (v._value ? "true" : "false");
100  }
101 };
102 
103 template<typename Tag>
104 const bool_class<Tag> bool_class<Tag>::yes { true };
105 template<typename Tag>
106 const bool_class<Tag> bool_class<Tag>::no { false };
107 
109 
110 }
Type-safe boolean.
Definition: bool_class.hh:57
friend bool_class operator&&(bool_class x, bool_class y) noexcept
Logical AND.
Definition: bool_class.hh:78
constexpr bool_class() noexcept
Constructs a bool_class object initialised to false.
Definition: bool_class.hh:64
friend bool_class operator!(bool_class x) noexcept
Logical NOT.
Definition: bool_class.hh:83
friend bool_class operator||(bool_class x, bool_class y) noexcept
Logical OR.
Definition: bool_class.hh:73
friend bool operator==(bool_class x, bool_class y) noexcept
Equal-to operator.
Definition: bool_class.hh:88
friend bool operator!=(bool_class x, bool_class y) noexcept
Not-equal-to operator.
Definition: bool_class.hh:93
friend std::ostream & operator<<(std::ostream &os, bool_class v)
Prints bool_class value to an output stream.
Definition: bool_class.hh:98
constexpr bool_class(bool v) noexcept
Constructs a bool_class object initialised to v.
Definition: bool_class.hh:67
Seastar API namespace.
Definition: abort_on_ebadf.hh:24