Add backwards compatiblity for isFunction

This commit is contained in:
Mike Bierlee 2016-12-26 18:31:39 +01:00
parent 925c3f4119
commit cc0ea0d9e4
3 changed files with 34 additions and 4 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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,
* $(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 Andrei Alexandrescu 2008-, Jonathan M Davis 2011-., 2014-2016 Mike Bierlee
* 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;
}
}