zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
optional.hpp
Go to the documentation of this file.
1 #pragma once
5 
6 #include <zk/config.hpp>
7 
8 #include <optional>
9 
10 namespace zk
11 {
12 
15 
16 template <typename T>
17 using optional = std::optional<T>;
18 
19 using nullopt_t = std::nullopt_t;
20 
21 using std::nullopt;
22 
24 template <typename FUnary, typename... T>
25 auto map(FUnary&& transform, const optional<T>&... x) -> optional<decltype(transform(x.value()...))>
26 {
27  if ((x && ...))
28  return transform(x.value()...);
29  else
30  return nullopt;
31 }
32 
33 template <typename T>
34 optional<T> some(T x)
35 {
36  return optional<T>(std::move(x));
37 }
38 
40 
41 }
auto map(FUnary &&transform, const optional< T > &...x) -> optional< decltype(transform(x.value()...))>
Apply transform with the arguments in x iff all of them have a value. Otherwise, nullopt will be retu...
Definition: optional.hpp:25