Listing 2: Include file that specifies create interface

 1 // No args: Handle<Data> = Handle<Data>::create();
 2 
 3 static
 4 Handle<Data>
 5 create()
 6 {
 7    return new Counted();
 8 }
 9 
10 // One arg: Handle<Data> dh = Handle<Data>::create(arg1);
11 
12 template<class Arg1>
13 static
14 Handle<Data>
15 create(Arg1& arg1)
16 {
17    return new Counted(arg1);
18 }
19 
20 template<class Arg1>
21 static
22 Handle<Data>
23 create(const Arg1& arg1)
24 {
25    return new Counted(arg1);
26 }
27 
28 // Two args: Handle<Data> dh = 
   // Handle<Data>::create(arg1, arg2);
29 
30 #define TEMPLATE template<class Arg1, class Arg2>
31 #define CREATE(Arg1, Arg2)             \
32    static                              \
33    Handle<Data>                        \
34    create(Arg1& arg1, Arg2& arg2)      \
35    {                                   \
36       return new Counted(arg1, arg2);  \
37    }
38 
39 TEMPLATE CREATE(const Arg1, const Arg2)
40 TEMPLATE CREATE(const Arg1,       Arg2)
41 TEMPLATE CREATE(      Arg1, const Arg2)
42 TEMPLATE CREATE(      Arg1,       Arg2)
43 
44 #undef TEMPLATE
45 #undef CREATE
46 
47 // Three args require 8 functions.
48 
49 #define TEMPLATE template<class Arg1, class Arg2, class Arg3>
50 #define CREATE(Arg1, Arg2, Arg3)              \
51    static                                     \
52    Handle<Data>                               \
53    create(Arg1& arg1, Arg2& arg2, Arg3& arg3) \
54    {                                          \
55       return new Counted(arg1, arg2, arg3);   \
56    }
57 
58 TEMPLATE CREATE(const Arg1, const Arg2, const Arg3)
59 TEMPLATE CREATE(const Arg1, const Arg2,       Arg3)
60 TEMPLATE CREATE(const Arg1,       Arg2, const Arg3)
61 TEMPLATE CREATE(const Arg1,       Arg2,       Arg3)
62 TEMPLATE CREATE(      Arg1, const Arg2, const Arg3)
63 TEMPLATE CREATE(      Arg1, const Arg2,       Arg3)
64 TEMPLATE CREATE(      Arg1,       Arg2, const Arg3)
65 TEMPLATE CREATE(      Arg1,       Arg2,       Arg3)
66 
67 #undef TEMPLATE
68 #undef CREATE
69 
70 // Four  args require 16 functions.
71 // Five  args require 32 functions.
72 // Implement when needed.