<div dir="ltr">> But there are two issues. First, cast<> has two template arguments, not one. Second, template instantiation cannot guess what overload of cast should be used in each case. I'm sorry, but after a few attempts of making this code to compile, I have to ask you to elaborate a bit more once again.<br><br>You are right, we can't just pass a template function as a template parameter. However, we could use a lambda:<br><font face="monospace, monospace">    template <typename CastOpTy, typename DeclTy><br>    Optional<DeclTy *> import(CastOpTy CastOp, DeclTy *&ToD, DeclTy *FromD) {<br>      if (auto Res = Importer.Import(FromD)) {<br>        return CastOp(Res);<br>      }<br>      return None;<br>    }<br>    template <typename DeclTy><br>    Optional<DeclTy *> importNullable(DeclTy *&ToD, DeclTy *FromD) {<br>      return import([](Decl* R){ return cast_or_null<DeclTy>(R); }, ToD, FromD);<br>    }</font><br><div><font face="arial, helvetica, sans-serif">This approach still has disadvantages: we have to use a concrete type in the lambda parameter (`Decl`) because polymorphic lambdas are not supported in C++11.</font></div><div><font face="arial, helvetica, sans-serif">So I am not sure if this is really worth it to avoid just some very few lines of repetition.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">> <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Regarding naming: what do you think about importNonNull[Into]() and importNullable[Into]()?</span></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Sounds good to me.</span></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">There is also another thing I am curious about: do we need to use dyn_casts on the return type? I'm not sure we can return a node with type so different from the imported node's type. Currently, there are some dyn_cast[_or_null]s in our code, but, possibly, they can be replaced with just casts, because we usually return nullptr or a pointer of same type as the imported one.</span></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I agree. Immediately after an import I think it is perfectly legitimate to assume that the imported node has the very same type.</span></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Gabor</span></span></font></div></div>