1 /*******************************************************************************
2 
3     Copyright:
4         Copyright (c) 2017 dunnhumby Germany GmbH.
5         All rights reserved.
6 
7     License:
8         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
9         Alternatively, this file may be distributed under the terms of the Tango
10         3-Clause BSD License (see LICENSE_BSD.txt for details).
11 
12 *******************************************************************************/
13 
14 module ocean.meta.types.ReduceType_test;
15 
16 import ocean.meta.types.Qualifiers;
17 import ocean.meta.types.Typedef;
18 import ocean.meta.traits.Basic;
19 import ocean.meta.types.ReduceType;
20 
21 struct ExampleReducer
22 {
23     alias int Result;
24     enum seed = 0;
25 
26     Result accumulate ( Result accum, Result next )
27     {
28         return accum + next;
29     }
30 
31     Result visit ( T ) ( )
32     {
33         if (isIntegerType!(T))
34             return 1;
35         else
36             return 0;
37     }
38 }
39 
40 unittest
41 {
42     static assert (ReduceType!(int, ExampleReducer) == 1);
43     static assert (ReduceType!(int[int], ExampleReducer) == 2);
44 }
45 
46 
47 struct CountSubTypes
48 {
49     alias int Result;
50     enum seed = 0;
51 
52     Result accumulate ( Result accum, Result next )
53     {
54         return accum + next;
55     }
56 
57     Result visit ( T ) ( )
58     {
59         return 1;
60     }
61 }
62 
63 unittest
64 {
65     static struct Sample
66     {
67         static struct Nested
68         {
69             mixin(Typedef!(int, "SomeInt"));
70             SomeInt field;
71         }
72 
73         Nested[3][] arr;
74     }
75 
76     // root struct + dynamic array field + static array element + nested struct
77     // element + nested struct field (typedef) + int
78     static assert (ReduceType!(Sample, CountSubTypes) == 6);
79 }