Permalink
Browse files

added `gval` (enforces lazy evaluation)

  • Loading branch information...
1 parent b361e0e commit 7373aef27f23cee57e8bdb77c166c2a3721602fb @Neverlord Neverlord committed Apr 3, 2013
Showing with 21 additions and 0 deletions.
  1. +21 −0 cppa/guard_expr.hpp
View
21 cppa/guard_expr.hpp
@@ -338,6 +338,14 @@ struct guard_placeholder {
};
+template<typename T>
+struct ge_value {
+ T value;
+};
+
+template<typename T>
+ge_value<T> gval(T val) { return {std::move(val)}; }
+
// result type computation
template<typename T, class Tuple>
@@ -352,6 +360,9 @@ struct ge_unbound<std::reference_wrapper<T>, Tuple> { typedef T type; };
template<typename T, class Tuple>
struct ge_unbound<std::reference_wrapper<const T>, Tuple> { typedef T type; };
+template<typename T, class Tuple>
+struct ge_unbound<ge_value<T>, Tuple> { typedef T type; };
+
// unbound type of placeholder
template<int X, typename... Ts>
struct ge_unbound<guard_placeholder<X>, detail::tdata<Ts...> > {
@@ -386,6 +397,11 @@ struct is_ge_type<guard_expr<OP, First, Second> > {
static constexpr bool value = true;
};
+template<typename T>
+struct is_ge_type<ge_value<T>> {
+ static constexpr bool value = true;
+};
+
template<operator_id OP, typename T1, typename T2>
guard_expr<OP, typename detail::strip_and_convert<T1>::type,
typename detail::strip_and_convert<T2>::type>
@@ -516,6 +532,11 @@ inline const T& ge_resolve(const Tuple&, const util::rebindable_reference<const
return value.get();
}
+template<class Tuple, typename T>
+inline const T& ge_resolve(const Tuple&, const ge_value<T>& wrapped_value) {
+ return wrapped_value.value;
+}
+
template<class Tuple, int X>
inline auto ge_resolve(const Tuple& tup, guard_placeholder<X>)
-> decltype(get<X>(tup).get()) {

0 comments on commit 7373aef

Please sign in to comment.