LeechCraft
0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
lazy.h
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#pragma once
10
11
#include <functional>
12
#include "
monadplus.h
"
13
14
namespace
LC
15
{
16
namespace
Util
17
{
18
template
<
typename
T>
19
using
Lazy_t
= std::function<T ()>;
20
21
template
<
typename
T>
22
Lazy_t<T>
MakeLazy
(
const
T& t)
23
{
24
return
[t] {
return
t; };
25
}
26
27
template
<
typename
R,
typename
F>
28
Lazy_t<R>
MakeLazyF
(
const
F& l)
29
{
30
return
l;
31
}
32
33
template
<
typename
T>
34
struct
InstanceMonadPlus
<
Lazy_t
<T>,
std
::enable_if_t<IsMonadPlus<T> ()>>
35
{
36
static
Lazy_t<T>
Mzero
()
37
{
38
return
[] {
return
Util::Mzero<T>
(); };
39
}
40
41
static
Lazy_t<T>
Mplus
(
const
Lazy_t<T>
& t1,
const
Lazy_t<T>
& t2)
42
{
43
return
[=]
44
{
45
const
auto
rt1 = t1 ();
46
return
rt1 !=
Util::Mzero<T>
() ? rt1 : t2 ();
47
};
48
}
49
};
50
}
51
}
monadplus.h
LC::Util::Lazy_t
std::function< T()> Lazy_t
Definition
lazy.h:19
LC::Util::MakeLazy
Lazy_t< T > MakeLazy(const T &t)
Definition
lazy.h:22
LC::Util::MakeLazyF
Lazy_t< R > MakeLazyF(const F &l)
Definition
lazy.h:28
LC::Util::Mzero
MP Mzero()
Definition
monadplus.h:46
LC
Definition
constants.h:15
std
STL namespace.
LC::Util::InstanceMonadPlus< Lazy_t< T >, std::enable_if_t< IsMonadPlus< T >()> >::Mplus
static Lazy_t< T > Mplus(const Lazy_t< T > &t1, const Lazy_t< T > &t2)
Definition
lazy.h:41
LC::Util::InstanceMonadPlus< Lazy_t< T >, std::enable_if_t< IsMonadPlus< T >()> >::Mzero
static Lazy_t< T > Mzero()
Definition
lazy.h:36
LC::Util::InstanceMonadPlus
Definition
monadplus.h:20
src
util
sll
lazy.h
Generated by
1.12.0