From d5ea77e49e30ad751678f90123f891344642a36c Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 12 Apr 2017 21:55:26 +0200 Subject: Introduce native boolean type --- src/stack.d | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/stack.d') diff --git a/src/stack.d b/src/stack.d index 6805873..2fb602b 100644 --- a/src/stack.d +++ b/src/stack.d @@ -6,7 +6,7 @@ import std.container : SList; static import src.definition; -alias Token = Algebraic!(int, string); +alias Token = Algebraic!(int, bool, string); alias Stack = SList; Stack!Token stack; @@ -26,18 +26,14 @@ Token pop(ref Stack!Token stack) { } void push(ref Stack!Token stack, Token token) { - if ( !token.visit!( - (int x ) => src.definition.handle(x), - (string word) => src.definition.handle(word) - ) ) { + if ( !src.definition.handle(token) ) { stack.insertFront(token); } } -void push(ref Stack!Token stack, int value) { - stack.push(Token(value)); -} - -void push(ref Stack!Token stack, string word) { - stack.push(Token(word)); +template push(T) +if ( is(T == int) || is(T == bool) || is (T == string) ) { + void push(ref Stack!Token stack, T value) { + stack.push(Token(value)); + } } -- cgit v1.2.3