aboutsummaryrefslogtreecommitdiff
path: root/example/turing/src/state.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-22 17:14:15 +0100
committerAdrian Kummerlaender2015-02-22 17:14:15 +0100
commit41b63eff7f76e6574ef238f821dad0212a619c2a (patch)
tree291652f853e32c80183fd1178d470c5499eee1c5 /example/turing/src/state.h
parent18fe83991563c0072fabaa60ff161e781a5364c2 (diff)
downloadTypeAsValue-41b63eff7f76e6574ef238f821dad0212a619c2a.tar
TypeAsValue-41b63eff7f76e6574ef238f821dad0212a619c2a.tar.gz
TypeAsValue-41b63eff7f76e6574ef238f821dad0212a619c2a.tar.bz2
TypeAsValue-41b63eff7f76e6574ef238f821dad0212a619c2a.tar.lz
TypeAsValue-41b63eff7f76e6574ef238f821dad0212a619c2a.tar.xz
TypeAsValue-41b63eff7f76e6574ef238f821dad0212a619c2a.tar.zst
TypeAsValue-41b63eff7f76e6574ef238f821dad0212a619c2a.zip
Improved `simulate` function of the Turing machine example
* introduced `state::state_accessor` helper function and moved position logic into `updatePosition` * added `IsEqual` comparator and expressed other basic comparators in terms of itself
Diffstat (limited to 'example/turing/src/state.h')
-rw-r--r--example/turing/src/state.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/example/turing/src/state.h b/example/turing/src/state.h
index f5bd7f2..51fe347 100644
--- a/example/turing/src/state.h
+++ b/example/turing/src/state.h
@@ -9,12 +9,26 @@ namespace machine {
namespace state {
-struct field {
+namespace field {
using ID = tav::Size<0>;
using READ = tav::Size<1>;
using WRITE = tav::Size<2>;
using NEXT = tav::Size<3>;
using MOVE = tav::Size<4>;
+}
+
+// (define (state_accessor state)
+// (lambda (field)
+// (nth field state)))
+template <typename State>
+struct state_accessor {
+ static_assert(
+ tav::IsPair<State>::value,
+ "machine state is invalid"
+ );
+
+ template <typename Field>
+ using get = tav::Nth<Field, State>;
};
// (define (state_predicate id read)
@@ -54,7 +68,9 @@ struct transition {
typename State,
typename Symbol
>
- using state = findState<State, Symbol, States>;
+ using state = state_accessor<
+ findState<State, Symbol, States>
+ >;
};
}