<div>So, here's my code, as it stands currently:</div><div><br></div><div>import std.stdio;</div><div><br></div><div>static enum Type {</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>request,</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>response</div><div>};</div><div><br></div><div>class Parser(Type t) {</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>static if (t == Type.request) {</div>

<div><span class="Apple-tab-span" style="white-space:pre">              </span>string name = "request";</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>string name = "response";</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">   </span>string message;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>this(string message) {</div>

<div><span class="Apple-tab-span" style="white-space:pre">              </span>this.message = message;</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div>}</div><div><br></div><div>void main() {</div>
<div>
<span class="Apple-tab-span" style="white-space:pre"> </span>immutable Type t = Type.request;</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>Parser!t h = new Parser!t("Hello world");</div>

<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>writefln("%s: %s", <a href="http://h.name">h.name</a>, h.message);</div><div>}</div><div><br></div><div>The general goal is to make a templated class that will only include the parts that each needs. I would like to keep this all as one class template, because there is a lot of shared code, and I would like to keep it as seamless as possible and not have to separate out code into separate functions.</div>

<div><br></div><div>Anyway, my current approach is a little clunky, because it requires an immutable to be created just to tell the compiler what type of parser I need.</div><div><br></div><div>I was thinking about having two classes, Request and Response, and have parser take a normal template (class Parser (T)), but I wanted to restrict it to just those two classes (for now), so I came up with the enum solution.</div>

<div><br></div><div>Is there a better way to do this?</div><div><br></div><div>What I'd ultimately like to do is have some static if surrounding blocks of code that depends on the input to the template.</div>