scala - Test if implicit exists -
is possible on compile time using macros test if exists implicit current type ?
something
def packone(tpe:c.universe.type,....) = { if(tpe =:= bytetpe ) makeast1 else if (tpe =:= longtpe ) makeast2 else if (tpe =:= c.typeof[java.lang.string]) makeast3 .... else exists implicit convention tpe { q""" // call function implicit pack[t] implicitly[packer[$tpe]].pack(...) """ } else { // make default conversion } }
it should possible use inferimplicitvalue
:
val t = c.internal.typeref(noprefix, typeof[packer[_]].typesymbol, list(tpe)) c.inferimplicitvalue(t) match { case emptytree => … // default conversion case packer => q"packer.pack(…)" }
Comments
Post a Comment