https://github.com/wx257osn2/veiler_opaque_bool
Strong Typedef for bool
https://github.com/wx257osn2/veiler_opaque_bool
cpp20
Last synced: 24 days ago
JSON representation
Strong Typedef for bool
- Host: GitHub
- URL: https://github.com/wx257osn2/veiler_opaque_bool
- Owner: wx257osn2
- License: bsl-1.0
- Created: 2022-03-05T08:58:52.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-05T03:32:14.000Z (almost 3 years ago)
- Last Synced: 2025-03-25T12:11:06.505Z (2 months ago)
- Topics: cpp20
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Veiler.OpaqueBool
This header only library provides strong typedef for `bool` .
This library is inspired by [`siv::YesNo`](https://github.com/Reputeless/YesNo) .It requires C++20 supported compiler.
## What's difference from `siv::YesNo` ?
`siv::YesNo` provides the named constants `Yes` and `No` .
Veiler.OpaqueBool allows to select the pair of named constants from `yes` / `no` , `enable` / `disable` , and `valid` / `invalid` .
And if you want to use other names, you can change them.## Usage
```cpp
#include"veiler/opaque_bool.hpp"using feature = veiler::opaque_bool::enable_disable;
template
struct feeling_base{
static constexpr T good{true};
static constexpr T bad{false};
};using feeling = veiler::opaque_bool::opaque_bool;
constexpr feeling my_feeling(feature cxx20){
return cxx20 ? feeling::good : feeling::bad;
}int main(){
static constexpr auto feeling_if_cxx20_enabled = my_feeling(feature::enable);
static_assert(feeling_if_cxx20_enabled == feeling::good);
static constexpr auto feeling_if_cxx20_disabled = my_feeling(feature::disable);
static_assert(feeling_if_cxx20_disabled == feeling::bad);
}
```## License
Boost Software License Version 1.0