LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
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::MakeLazy
Lazy_t< T > MakeLazy(const T &t)
Definition: lazy.h:34
LC::Util::Lazy_t
std::function< T()> Lazy_t
Definition: lazy.h:31
LC::Util::Mplus
const struct LC::Util::@1 Mplus
LC::Util::InstanceMonadPlus
Definition: monadplus.h:31
LC
Definition: constants.h:14
LC::Util::MakeLazyF
Lazy_t< R > MakeLazyF(const F &l)
Definition: lazy.h:40
LC::Util::Mzero
MP Mzero()
Definition: monadplus.h:58