From 41b63eff7f76e6574ef238f821dad0212a619c2a Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 22 Feb 2015 17:14:15 +0100 Subject: 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 --- example/turing/src/state.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'example/turing/src/state.h') 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 +struct state_accessor { + static_assert( + tav::IsPair::value, + "machine state is invalid" + ); + + template + using get = tav::Nth; }; // (define (state_predicate id read) @@ -54,7 +68,9 @@ struct transition { typename State, typename Symbol > - using state = findState; + using state = state_accessor< + findState + >; }; } -- cgit v1.2.3