Merge pull request #50 from s-ludwig/fix_generic_visitor_error
Avoid instantiating generic visitor with types it cannot handle.
This commit is contained in:
commit
ab3e8c5cf8
|
@ -3,7 +3,7 @@ TaggedAlgebraic
|
|||
|
||||
Implementation of a generic `TaggedUnion` type along with a `TaggedAlgebraic` type that forwards all methods and operators of the contained types using dynamic dispatch.
|
||||
|
||||
[![Build Status](https://travis-ci.org/s-ludwig/taggedalgebraic.svg?branch=master)](https://travis-ci.org/s-ludwig/taggedalgebraic) [![codecov](https://codecov.io/gh/s-ludwig/taggedalgebraic/branch/master/graph/badge.svg)](https://codecov.io/gh/s-ludwig/taggedalgebraic)
|
||||
[![Build Status](https://travis-ci.com/s-ludwig/taggedalgebraic.svg?branch=master)](https://travis-ci.com/s-ludwig/taggedalgebraic) [![codecov](https://codecov.io/gh/s-ludwig/taggedalgebraic/branch/master/graph/badge.svg)](https://codecov.io/gh/s-ludwig/taggedalgebraic)
|
||||
|
||||
API Documentation:
|
||||
- [`taggedalgebraic`](https://vibed.org/api/taggedalgebraic.taggedalgebraic/)
|
||||
|
|
|
@ -217,7 +217,7 @@ private template matchesType(alias fun) {
|
|||
else static if (Params.length == 1 && is(T == Params[0])) enum matchesType = true;
|
||||
else enum matchesType = false;
|
||||
} else static if (!isUnitType!T) {
|
||||
static if (isSomeFunction!(fun!T)) {
|
||||
static if (__traits(compiles, fun!T) && isSomeFunction!(fun!T)) {
|
||||
alias Params = ParameterTypeTuple!(fun!T);
|
||||
static if (Params.length == 1 && is(T == Params[0])) enum matchesType = true;
|
||||
else enum matchesType = false;
|
||||
|
@ -226,6 +226,16 @@ private template matchesType(alias fun) {
|
|||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
class C {}
|
||||
alias mt1 = matchesType!((C c) => true);
|
||||
alias mt2 = matchesType!((c) { static assert(!is(typeof(c) == C)); });
|
||||
static assert(mt1!C);
|
||||
static assert(!mt1!int);
|
||||
static assert(mt2!int);
|
||||
static assert(!mt2!C);
|
||||
}
|
||||
|
||||
private template selectHandler(T, VISITORS...)
|
||||
{
|
||||
import std.traits : ParameterTypeTuple, isSomeFunction;
|
||||
|
|
Loading…
Reference in a new issue