-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionalOptionalLift.h
55 lines (47 loc) · 1.41 KB
/
functionalOptionalLift.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Copyright 2018 Krzysztof Karbowiak
*/
#ifndef FUNCTIONAL_OPTIONAL_LIFT_H__DDK
#define FUNCTIONAL_OPTIONAL_LIFT_H__DDK
#include <boost/optional.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
namespace functional
{
template<typename T, typename U>
boost::function<boost::optional<T> (boost::optional<U>)> lift(boost::function<T (U)> f);
}
namespace functional
{
namespace detail
{
template<typename T, typename U>
boost::optional<T> lift_helper(boost::function<T (U)> f, boost::optional<U> arg);
}
}
namespace functional
{
////////////////////////////////////////////////////////////////////////////////
template<typename T, typename U>
inline boost::function<boost::optional<T> (boost::optional<U>)> lift(boost::function<T (U)> f)
{
return boost::bind(&detail::lift_helper<T, U>, f, _1);
}
////////////////////////////////////////////////////////////////////////////////
}
namespace functional
{
namespace detail
{
////////////////////////////////////////////////////////////////////////////////
template<typename T, typename U>
inline boost::optional<T> lift_helper(boost::function<T (U)> f, boost::optional<U> arg)
{
return arg
? boost::optional<T>(f(*arg))
: boost::optional<T>();
}
////////////////////////////////////////////////////////////////////////////////
}
}
#endif /* FUNCTIONAL_OPTIONAL_LIFT_H__DDK */