-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue_context.cpp
More file actions
35 lines (28 loc) · 823 Bytes
/
Copy pathvalue_context.cpp
File metadata and controls
35 lines (28 loc) · 823 Bytes
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
/*
* A value context associates a key with a value. Value context should only be
* used to store request-scoped data.
*/
#include <any>
#include <iostream>
#include <memory>
#include <string>
#include <bongo/context.h>
using namespace std::string_literals;
int main() try {
auto f = [](std::shared_ptr<bongo::context::context> ctx, std::string const& k) {
auto v = ctx->value(k);
if (v.has_value()) {
std::cout << k << ": " << std::any_cast<std::string>(v) << "\n";
return;
}
std::cout << "key not found: " << k << "\n";
};
auto k = std::string{"language"};
auto ctx = bongo::context::with_value(bongo::context::background(), k, "Go"s);
f(ctx, k);
f(ctx, std::string{"color"});
return 0;
} catch (std::exception const& e) {
std::cerr << e.what() << "\n";
return 1;
}