<div dir="ltr">Hi everyone,<div><br></div><div>I have an idea that should allow reducing code duplication in Casting.h while making llvm::isa, llvm::cast, llvm::dyn_cast, etc more generic. Since we added unique pointers support for these template functions (see <span style="color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">ab480f45cd23c08cb9aa3f427aad072df249135f</span>) I propose to g<span style="color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">eneralize their semantics</span><span style="color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"> to deal with any pointer-like type (i.e. dereferenceable and implicitly convertible to bool) so that:</span></div><div><ul class="gmail-remarkup-list" style="margin:12px 0px 12px 30px;padding:0px;border:0px;list-style-position:initial;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><li class="gmail-remarkup-list-item" style="margin:0px;padding:0px;border:0px;line-height:1.7em">for each fancy_pointer<T> t: isa<G>(t) returns true iff current implementation of isa<G>(nonfancy_t) returns true where decltype(nonfancy_t) is T*</li><li class="gmail-remarkup-list-item" style="margin:0px;padding:0px;border:0px;line-height:1.7em">all old cast operations should return a raw pointer of type typename std::pointer_traits<fancy_pointer<T>>::element_type * and do not perform ownership transfer.</li><li class="gmail-remarkup-list-item" style="margin:0px;padding:0px;border:0px;line-height:1.7em">move_[dyn_]cast should do what unique_dyn_cast is currently doing in a more generic manner: it moves to an object of type typename std::pointer_traits<fancy_pointer<T>>::rebind<G></li></ul><p style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">N.B. std::pointer_traits is a conception that I use to explain the behaviour - not necessary the way I plan to implement it.</p><p style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><br></p><p style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">An example implementation of the proposal for llvm::isa : <a href="https://reviews.llvm.org/D42027">https://reviews.llvm.org/D42027</a></p><p style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px"><br></p><p style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">--</p><p style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">Kind regards, Dmitry</p></div></div>