www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - No UFCS with nested functions?

reply Tobias Pankrath <tobias pankrath.net> writes:
Why does the following not work? It works, if I move the 'prop' 
out of 'foo'.

---
struct S {
	ubyte[12] bar;
}

bool foo (ref S s)
{
    static bool prop(const(ubyte)[] f) {
       return f.length > 1;
    }
	return s.bar[].prop;
}
---

Thanks!
Nov 04 2019
next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Nov 04, 2019 at 07:51:26PM +0000, Tobias Pankrath via
Digitalmars-d-learn wrote:
 Why does the following not work? It works, if I move the 'prop' out of
 'foo'.
UFCS is only supported for module-level functions, as far as I know.
 ---
 struct S {
 	ubyte[12] bar;
 }
 
 bool foo (ref S s)
 {
    static bool prop(const(ubyte)[] f) {
       return f.length > 1;
    }
 	return s.bar[].prop;
 }
 ---
[...] T -- I am not young enough to know everything. -- Oscar Wilde
Nov 04 2019
parent reply ixid <adamsibson gmail.com> writes:
On Monday, 4 November 2019 at 20:46:41 UTC, H. S. Teoh wrote:
 On Mon, Nov 04, 2019 at 07:51:26PM +0000, Tobias Pankrath via 
 Digitalmars-d-learn wrote:
 Why does the following not work? It works, if I move the 
 'prop' out of 'foo'.
UFCS is only supported for module-level functions, as far as I know.
 ---
 struct S {
 	ubyte[12] bar;
 }
 
 bool foo (ref S s)
 {
    static bool prop(const(ubyte)[] f) {
       return f.length > 1;
    }
 	return s.bar[].prop;
 }
 ---
[...] T
Is this a necessary limitation? It feels inconsistent and clunky.
Nov 05 2019
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, November 5, 2019 9:16:27 AM MST ixid via Digitalmars-d-learn 
wrote:
 On Monday, 4 November 2019 at 20:46:41 UTC, H. S. Teoh wrote:
 On Mon, Nov 04, 2019 at 07:51:26PM +0000, Tobias Pankrath via

 Digitalmars-d-learn wrote:
 Why does the following not work? It works, if I move the
 'prop' out of 'foo'.
UFCS is only supported for module-level functions, as far as I know.
 ---
 struct S {

    ubyte[12] bar;

 }

 bool foo (ref S s)
 {

    static bool prop(const(ubyte)[] f) {

       return f.length > 1;

    }

    return s.bar[].prop;

 }
 ---
[...] T
Is this a necessary limitation? It feels inconsistent and clunky.
It's explained at the end of this section of the documentation: https://dlang.org/spec/function.html#pseudo-member - Jonathan M Davis
Nov 05 2019
prev sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 4 November 2019 at 19:51:26 UTC, Tobias Pankrath wrote:
 Why does the following not work? It works, if I move the 'prop' 
 out of 'foo'.

 ---
 struct S {
 	ubyte[12] bar;
 }

 bool foo (ref S s)
 {
    static bool prop(const(ubyte)[] f) {
       return f.length > 1;
    }
 	return s.bar[].prop;
 }
 ---

 Thanks!
https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ struct S { ubyte[12] bar; } alias I(alias f) = f; bool foo (ref S s) { static bool prop(const(ubyte)[] f) { return f.length > 1; } return s.bar[].I!prop; }
Nov 04 2019
parent Paul Backus <snarwin gmail.com> writes:
On Tuesday, 5 November 2019 at 00:34:33 UTC, Nicholas Wilson 
wrote:
 https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/

 struct S {
 	ubyte[12] bar;
 }

 alias I(alias f) = f;

 bool foo (ref S s)
 {
    static bool prop(const(ubyte)[] f) {
       return f.length > 1;
    }
 	return s.bar[].I!prop;
 }
It's in Phobos: import std.meta: Alias; return s.bar[].Alias!prop
Nov 04 2019