1 /*
2  *             Copyright Andrej Mitrovic 2014.
3  *  Distributed under the Boost Software License, Version 1.0.
4  *     (See accompanying file LICENSE_1_0.txt or copy at
5  *           http://www.boost.org/LICENSE_1_0.txt)
6  */
7 module imgui.util;
8 
9 /**
10     Note: This unfortunately doesn't work with more complex structures
11     due to a DMD bug with an infinite loop problem. This isn't reported yet.
12 */
13 
14 import std.range;
15 import std.stdio;
16 
17 auto ref fieldRange(S, T)(auto ref T sym)
18 {
19     static if (is(T == struct) && !is(T == S))
20         return fieldRange!S(sym.tupleof);
21     else
22         return only(sym);
23 }
24 
25 auto ref fieldRange(S, T...)(auto ref T syms) if (T.length > 1)
26 {
27     return chain(fieldRange!S(syms[0]),
28                  fieldRange!S(syms[1 .. $]));
29 }
30 
31 auto addrFieldRange(S, T)(ref T sym)
32 {
33     static if (is(T == struct) && !is(T == S))
34         return addrFieldRange!S(sym.tupleof);
35     else
36         return only(&sym);
37 }
38 
39 auto addrFieldRange(S, T...)(ref T syms) if (T.length > 1)
40 {
41     return chain(addrFieldRange!S(syms[0]),
42                  addrFieldRange!S(syms[1 .. $]));
43 }
44 
45 auto refFieldRange(S, T)(ref T sym)
46 {
47     alias Type = typeof(sym.fieldRange!S.front);
48 
49     static ref Type getRef(Type* elem) { return *elem; }
50 
51     return sym.addrFieldRange!S.map!getRef;
52 }