www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - scope function parameters

reply dsimcha <dsimcha yahoo.com> writes:
I'm looking to clean up some annoying corner cases in some libraries I wrote
by making delegates that are function parameters and are logically scope be
declared as such.  However, the parameters are templated and can be any
callable object (function pointer, delegate, or class or struct that overloads
opCall).  The following works right now, even when C is not a delegate:

ReturnType doStuff(C)(scope C callable) {
    // Function body
}

Will scope qualifiers on classes, structs and function pointers continue to be
simply allowed and ignored so that scope can be used when C is a delegate in
the case above?  Can this behavior be relied on long-term?
Aug 11 2010
parent reply Jonathan M Davis <jmdavisprog gmail.com> writes:
On Wednesday, August 11, 2010 11:21:53 dsimcha wrote:
 I'm looking to clean up some annoying corner cases in some libraries I
 wrote by making delegates that are function parameters and are logically
 scope be declared as such.  However, the parameters are templated and can
 be any callable object (function pointer, delegate, or class or struct
 that overloads opCall).  The following works right now, even when C is not
 a delegate:
 
 ReturnType doStuff(C)(scope C callable) {
     // Function body
 }
 
 Will scope qualifiers on classes, structs and function pointers continue to
 be simply allowed and ignored so that scope can be used when C is a
 delegate in the case above?  Can this behavior be relied on long-term?
Aren't scope qualifiers supposed to be going away entirely? - Jonathan M Davis
Aug 11 2010
parent dsimcha <dsimcha yahoo.com> writes:
== Quote from Jonathan M Davis (jmdavisprog gmail.com)'s article
 On Wednesday, August 11, 2010 11:21:53 dsimcha wrote:
 I'm looking to clean up some annoying corner cases in some libraries I
 wrote by making delegates that are function parameters and are logically
 scope be declared as such.  However, the parameters are templated and can
 be any callable object (function pointer, delegate, or class or struct
 that overloads opCall).  The following works right now, even when C is not
 a delegate:

 ReturnType doStuff(C)(scope C callable) {
     // Function body
 }

 Will scope qualifiers on classes, structs and function pointers continue to
 be simply allowed and ignored so that scope can be used when C is a
 delegate in the case above?  Can this behavior be relied on long-term?
Aren't scope qualifiers supposed to be going away entirely? - Jonathan M Davis
AFAIK just scope (i.e. stack-allocated without library level magic) classes, not scope delegates.
Aug 11 2010