November 24, 2013 Re: Initializing "two-dimensional" compile-time enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uranuz | On Sun, Nov 24, 2013 at 8:09 PM, Uranuz <neuranuz@gmail.com> wrote: > As far as I understand I can't use immutable values as template arguments. Indeed not. They are not defined at compile-time. > //Some template method > void foo(string arg)() > { //Some actions here > > } > > void main() > { > foreach( name, item; pohodEnumValues ) > { foo!(name)(); //I need name at compile time here > } > } > //----------------- > > Because we have only compile time foreach over tuple this is not working. Can someone give an advice, please? I see some possibilities, but they might be a bit overkill. In increasing order of coding effort: 1) use a tuple (as you suggest in another post) 2) use functions to build the code you want (as a string) and then mix it in. Using functions, you can use iterative code as much as you wish. 3) Another, more far-fetched, option is to use a struct. Since your AA is defined at compile-time, I would not create an AA, but a struct, crafting it to mimic your AA. |
November 24, 2013 Re: Initializing "two-dimensional" compile-time enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uranuz | > But I can't undersatnd how to make some kind of compile-time
> variable. If we have advanced metaprogramming features I think possibility
> of defining compile-time variables is needed. Am I right or not?
That's what we all want, but it's more or less impossible. If your variable do not change type, then you can at least build an array and store its successive values in the array. Then you use the last value for the rest of your computation.
Or, as I said in another post, use Compile-Time Function Evaluation: using standard functions, you can be as iterative/imperative as you want.
|
November 25, 2013 Re: Initializing "two-dimensional" compile-time enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | On Sunday, 24 November 2013 at 17:16:21 UTC, Philippe Sigaud
wrote:
> On Sun, Nov 24, 2013 at 5:19 PM, monarch_dodra <monarchdodra@gmail.com> wrote:
>
>> This is cleaner, IMO.
>
> Well, in an ideal world, we wouldn't have to fall back to these contortions.
Even without bugs, it's still convenient way to declare a
variable as enum or const, when 1-liner initialization is simply
not possible.
enum bar = ()
{
T t;
initialize(t);
return t;
}();
|
November 25, 2013 Re: Initializing "two-dimensional" compile-time enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | Good idea, it's something I tend to forget. I always create associated functions when an anony... |
November 25, 2013 Re: Initializing "two-dimensional" compile-time enum | ||||
---|---|---|---|---|
| ||||
On Mon, Nov 25, 2013 at 7:10 PM, Philippe Sigaud <philippe.sigaud@gmail.com> wrote:
> Good idea, it's something I tend to forget. I always create associated functions when an anony...
Arg, damn gmail. ... when an anonymous one would be enough (and would
not clutter the namespace)
|
Copyright © 1999-2021 by the D Language Foundation