From cc0ea0d9e4e8d37e17d8671492375474cbdc8925 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Mon, 26 Dec 2016 18:31:39 +0100 Subject: [PATCH] Add backwards compatiblity for isFunction --- source/poodinis/autowire.d | 1 + source/poodinis/container.d | 1 + source/poodinis/polyfill.d | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index 617677e..b33b935 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -21,6 +21,7 @@ import poodinis.container; import poodinis.registration; import poodinis.factory; import poodinis.valueinjection; +import poodinis.polyfill; import std.exception; import std.stdio; diff --git a/source/poodinis/container.d b/source/poodinis/container.d index 1892ed5..01771f2 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -18,6 +18,7 @@ import poodinis.autowire; import poodinis.context; import poodinis.factory; import poodinis.valueinjection; +import poodinis.polyfill; import std.string; import std.algorithm; diff --git a/source/poodinis/polyfill.d b/source/poodinis/polyfill.d index 0bc454e..5d875b2 100644 --- a/source/poodinis/polyfill.d +++ b/source/poodinis/polyfill.d @@ -4,20 +4,29 @@ * * Should not implement functionalitiy which is gone from the latest Phobos. * - * Implementations copied/re-implemented from std.exception + * Implementations copied/re-implemented from std.exception and std.traits; * * The baseline compatibility is D/Phobos 2.068.2 * * Authors: $(HTTP erdani.org, Andrei Alexandrescu), - * Jonathan M Davis, - * Mike Bierlee (m.bierlee@lostmoment.com) - * Copyright: Copyright Andrei Alexandrescu 2008-, Jonathan M Davis 2011-., 2014-2016 Mike Bierlee + * Jonathan M Davis, + * $(HTTP digitalmars.com, Walter Bright), + * Tomasz Stachowiak ($(D isExpressions)), + * $(HTTP erdani.org, Andrei Alexandrescu), + * Shin Fujishiro, + * $(HTTP octarineparrot.com, Robert Clipsham), + * $(HTTP klickverbot.at, David Nadlinger), + * Kenji Hara, + * Shoichi Kato, + * Mike Bierlee (m.bierlee@lostmoment.com) + * Copyright: Copyright Digital Mars 2005 - 2009., Copyright Andrei Alexandrescu 2008-, Jonathan M Davis 2011-., 2014-2016 Mike Bierlee * License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0) */ module poodinis.polyfill; import std.exception; +import std.traits; static if (!__traits(compiles, basicExceptionCtors)) { mixin template basicExceptionCtors() @@ -33,3 +42,22 @@ static if (!__traits(compiles, basicExceptionCtors)) { } } } + +static if (!__traits(compiles, isFunction)) { + template isFunction(X...) if (X.length == 1) + { + static if (is(typeof(&X[0]) U : U*) && is(U == function) || + is(typeof(&X[0]) U == delegate)) + { + // x is a (nested) function symbol. + enum isFunction = true; + } + else static if (is(X[0] T)) + { + // x is a type. Take the type of it and examine. + enum isFunction = is(T == function); + } + else + enum isFunction = false; + } +}