Note that there are some explanatory texts on larger screens.

plurals
  1. POOverloading external function for use in a separate module
    primarykey
    data
    text
    <p>I want to do <a href="http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394" rel="nofollow">this</a> (supported by <a href="http://www.drdobbs.com/cpp/how-non-member-functions-improve-encapsu/184401197" rel="nofollow">this</a>), but I'm hitting a tiny issue (watered down for your less-headachy-non-displeasure).</p> <p>Let's say I'm a library writer, and I have these functions in a D file:</p> <pre><code>module mod_a; import std.stdio; void run(T)(T v) { writeln("Jigglypuff!"); } void runrun(T)(T v) { run(v); } </code></pre> <p>And I have client code in another module in which I attempt to overload <code>run</code> and call <code>runrun</code>:</p> <pre><code>import mod_a; void run(T:double)(T v) { writeln("Wigglytuff!"); } void main() { runrun(1.0); } </code></pre> <p>This code results in 'Jigglypuff!' being printed rather than 'Wigglytuff!', which makes sense, because the definition of <code>runrun</code> can only see the <s>unevolved</s> unspecialized form available to it in its module. I (and client code), however, would like to be seeing a 'Wigglytuff' rather than a 'Jigglypuff'.</p> <p>In C++ I'd throw a <code>namespace mod_a { ... }</code> around the specialization of run to show that the client code's run should be examined alongside my library code when trying to determine what the definition of <code>runrun</code> calls, welcoming the can of worms that came along with such behavior.</p> <p>Is there an idiomatic D-way to organize this such that the function <code>run</code> may be <em>intentionally</em> hijacked? Specifically, I'd like to mimic the way C++'s global functions behave with ad-hoc specializations.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload