Template help - MultiAccess
monarch_dodra
monarchdodra at gmail.com
Tue Jan 8 12:07:27 PST 2013
On Tuesday, 8 January 2013 at 19:58:20 UTC, Era Scarecrow wrote:
> I'm making a template to handle multiple accesses to the same
> name. In making my compression algorithm (and BitArray) I
> realize how much code is going into just forward referencing to
> things based on certain states.
>
> I have the following head template (there's about 5 total with
> how I see it):
>
>
> template multiAccess(Type, string name, string attributes,
> choice, bool read, bool write, T ...) {
> static assert(T.length % 2 == 0,
> "Must be in pairs, AccessName & matching Value");
> //eponymous enum
> enum multiAccess =
> multiAccessFunctions!(Type, name, attributes, choice,
> read, write, T);
> }
>
>
> I'm calling it with:
> int choice;
> int a = 100;
> int b = 200;
> int c = 300;
>
> writeln(multiAccess!(int, "test", "@safe nothrow pure",
> choice, true, true,
> a, 0,
> b, 1,
> c, 2));
>
> And I'm getting the error of:
>
> Error: template instance multiAccess!(int, "test", "@safe
> nothrow pure", choice, true, true, a, 0, b, 1, c, 2)
> multiAccess!(int, "test", "@safe nothrow pure", choice, true,
> true, a, 0, b, 1, c, 2) does not match template declaration
> multiAccess(Type, string name, string attributes, choice, bool
> read, bool write, T...)
>
> Maybe something obvious but I'm not seeing it.
You appear to want "choice" to represent a value, rather than a
type.
Declare it as "int choice" or "alias choice"
Not that with "int choice", you'll get a compiler error because
it isn't a compile constant. I'm not really sure about how
"alias" works, but that's the source of your problem.
More information about the Digitalmars-d-learn
mailing list