2 /******************************************************************************
4 * DESCRIPTION: promises
5 * COPYRIGHT : (C) 2007 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
17 template<class T
> class promise_rep
;
18 template<class T
> class promise
;
19 template<class T
> tm_ostream
& operator << (tm_ostream
& out
, promise
<T
> cmd
);
20 template<class T
> bool is_nil (promise
<T
> l
);
23 class promise_rep
: public abstract_struct
{
25 inline promise_rep () {}
26 inline virtual ~promise_rep () {}
27 inline virtual tm_ostream
& print (tm_ostream
& out
);
28 virtual T
eval () = 0;
34 ABSTRACT_NULL_TEMPLATE(promise
,T
);
35 inline T
operator () ();
36 friend tm_ostream
& operator << LESSGTR (tm_ostream
& out
, promise
<T
> cmd
);
38 ABSTRACT_NULL_TEMPLATE_CODE(promise
,class,T
);
40 #define TMPL template<class T>
41 TMPL
inline tm_ostream
& promise_rep
<T
>::print (tm_ostream
& out
) {
42 return out
<< "promise"; }
43 TMPL
inline T promise
<T
>::operator () () {
44 return rep
->eval (); }
45 TMPL
inline bool operator == (promise
<T
> mw1
, promise
<T
> mw2
) {
46 return mw1
.rep
== mw2
.rep
; }
47 TMPL
inline tm_ostream
& operator << (tm_ostream
& out
, promise
<T
> cmd
) {
48 if (is_nil (cmd
)) return out
<< "(null)"; else return cmd
->print(out
); }
51 #endif // defined PROMISE_H