From 1c88c3c65d6670fd0067238eaa96a9b62fef2b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 22 Feb 2019 12:22:38 +0100 Subject: [PATCH] Add template constraint to visit/tryVisit. --- source/taggedalgebraic/taggedunion.d | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/taggedalgebraic/taggedunion.d b/source/taggedalgebraic/taggedunion.d index 91b1c42..c01c8c3 100644 --- a/source/taggedalgebraic/taggedunion.d +++ b/source/taggedalgebraic/taggedunion.d @@ -339,7 +339,9 @@ unittest { // test for name clashes .... */ -template visit(VISITORS...) { +template visit(VISITORS...) + if (VISITORS.length > 0) +{ auto visit(TU)(auto ref TU tu) if (isInstanceOf!(TaggedUnion, TU)) { @@ -422,7 +424,9 @@ private U to(U, T)(T val) { Instead of failing to compile, `tryVisit` will throw an `Exception` if none of the handlers is able to handle the value contained in `tu`. */ -template tryVisit(VISITORS...) { +template tryVisit(VISITORS...) + if (VISITORS.length > 0) +{ auto tryVisit(TU)(auto ref TU tu) if (isInstanceOf!(TaggedUnion, TU)) {