https://github.com/0x0c/value_bag
Put a value into the bag and take it functionally.
https://github.com/0x0c/value_bag
cpp
Last synced: 9 months ago
JSON representation
Put a value into the bag and take it functionally.
- Host: GitHub
- URL: https://github.com/0x0c/value_bag
- Owner: 0x0c
- Created: 2019-03-31T15:57:20.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-02T09:41:50.000Z (about 7 years ago)
- Last Synced: 2025-07-23T18:55:27.437Z (11 months ago)
- Topics: cpp
- Language: C++
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# value_bag
Put a value into the bag and take it functionally.
## Usage
See `main.cpp`.
A result of the sample code is as follows:
```
default peek : 100
default take : 100
default take : 0
default set : 200
default take : 200
default take : 0
----
toggle : value1 = 100, value2 = 200
toggle peek : 100
toggle take : 100
toggle take : 200
toggle take : 100
toggle : the value becomes 00.
toggle take : 100
----
once peek : 100
once take : 100
once take : 0
once set : 200
once take : 0
----
```
Here is an example for Arduino to prevent chattering of a switch.
```
auto d = m2d::default_value_bag(LOW, LOW);
...
int pin = digitalRead(10);
if (pin != d.peek() && pin == HIGH) {
d.set(pin);
}
...
if (d.take() == HIGH) {
// Do something, called once after pin 10 becomes HIGH.
}
```