Browse code

Add T to Members

Robert Cranston authored on 08/03/2023 23:32:20
Showing 4 changed files

... ...
@@ -399,19 +399,19 @@ either
399 399
 -   `T` itself, if `T` is a [scalar][]
400 400
 
401 401
 then `constexpr auto GLTraits::members<T>()` returns an instance of the
402
-[empty][] `struct GLTraits::Members<typename... Values>` where `Values...` are
403
-the ("member") types above, in the order they occur in `T`.
402
+[empty][] `struct GLTraits::Members<typename T, typename... Values>` where
403
+`Values...` are the ("member") types above, in the order they occur in `T`.
404 404
 
405 405
 An example use case would be along the lines of:
406 406
 
407 407
 ```cpp
408 408
 template<
409
+    typename    T,
409 410
     typename    Value,
410 411
     typename... Values
411 412
 >
412 413
 void vertex_setup(
413
-    GLTraits::Members<Value, Values...>,
414
-    std::size_t stride,
414
+    GLTraits::Members<T, Value, Values...>,
415 415
     std::size_t offset   = 0,
416 416
     GLint       location = 0
417 417
 )
... ...
@@ -419,15 +419,15 @@ void vertex_setup(
419 419
     auto unaligned = offset % alignof(Value);
420 420
     if (unaligned)
421 421
         offset += alignof(Value) - unaligned;
422
-    GLTraits::Value<Value>::vertex_attrib_pointer(location, offset, stride);
422
+    GLTraits::Value<Value>::vertex_attrib_pointer(location, offset, sizeof(T));
423 423
     vertex_setup(
424
-        GLTraits::Members<Values...>{},
425
-        stride,
424
+        GLTraits::Members<T, Values...>{},
426 425
         offset   + sizeof(Value),
427 426
         location + GLTraits::Value<Value>::columns
428 427
     );
429 428
 }
430
-void vertex_setup(GLTraits::Members<>, std::size_t, std::size_t, GLint)
429
+template<typename T>
430
+void vertex_setup(GLTraits::Members<T>, std::size_t, GLint)
431 431
 {}
432 432
 
433 433
 struct Vertex
... ...
@@ -440,7 +440,7 @@ struct Vertex
440 440
     GLubyte    flags;
441 441
     GLdouble   unaligned;
442 442
 };
443
-vertex_setup(GLTraits::members<Vertex>(), sizeof(Vertex));
443
+vertex_setup(GLTraits::members<Vertex>());
444 444
 ```
445 445
 
446 446
 This use case is tested in [`tests/vertex_setup.cpp`][]. To verify that the
... ...
@@ -42,7 +42,7 @@ public:
42 42
 
43 43
     #if __cplusplus >= 201402L
44 44
 
45
-    template<typename... Value>
45
+    template<typename T, typename... Value>
46 46
     struct Members
47 47
     {};
48 48
 
... ...
@@ -153,6 +153,7 @@ private:
153 153
     static constexpr auto members_(Indices<Is...>)
154 154
     {
155 155
         return Members<
156
+            T,
156 157
             typename ValueID<member_infos<T, Is...>().infos[Is].id>::Value...
157 158
         >{};
158 159
     }
... ...
@@ -111,11 +111,12 @@ struct GLTraitsTest : protected GLBase
111 111
 
112 112
     #if __cplusplus >= 201402L
113 113
     template<
114
+        typename    T,
114 115
         typename    Value,
115 116
         typename... Values
116 117
     >
117 118
     void static test_members(
118
-        GLTraits::Members<Value, Values...>,
119
+        GLTraits::Members<T, Value, Values...>,
119 120
         std::size_t offset = 0
120 121
     )
121 122
     {
... ...
@@ -126,7 +127,7 @@ struct GLTraitsTest : protected GLBase
126 127
         using Traits = GLTraits::Value<Value>;
127 128
         static_assert(
128 129
             std::is_empty<GLTraits::Members<
129
-                Value, Values...
130
+                T, Value, Values...
130 131
             >>::value,
131 132
             "GLTraits::Members must be empty"
132 133
         );
... ...
@@ -137,9 +138,10 @@ struct GLTraitsTest : protected GLBase
137 138
                 << std::right << std::setw(2) << std::dec << OFFSET << " " \
138 139
                 << std::right << std::setw(3) << std::dec << END    << "\n";
139 140
         GLTRAITS_TEST_MEMBERS(2, Traits::name, offset, end)
140
-        test_members(GLTraits::Members<Values...>{}, end);
141
+        test_members(GLTraits::Members<T, Values...>{}, end);
141 142
     }
142
-    void static test_members(GLTraits::Members<>, std::size_t)
143
+    template<typename T>
144
+    void static test_members(GLTraits::Members<T>, std::size_t)
143 145
     {}
144 146
     #endif
145 147
 
... ...
@@ -7,12 +7,12 @@
7 7
 
8 8
 
9 9
 template<
10
+    typename    T,
10 11
     typename    Value,
11 12
     typename... Values
12 13
 >
13 14
 void vertex_setup(
14
-    GLTraits::Members<Value, Values...>,
15
-    std::size_t stride,
15
+    GLTraits::Members<T, Value, Values...>,
16 16
     std::size_t offset   = 0,
17 17
     GLint       location = 0
18 18
 )
... ...
@@ -20,15 +20,15 @@ void vertex_setup(
20 20
     auto unaligned = offset % alignof(Value);
21 21
     if (unaligned)
22 22
         offset += alignof(Value) - unaligned;
23
-    GLTraits::Value<Value>::vertex_attrib_pointer(location, offset, stride);
23
+    GLTraits::Value<Value>::vertex_attrib_pointer(location, offset, sizeof(T));
24 24
     vertex_setup(
25
-        GLTraits::Members<Values...>{},
26
-        stride,
25
+        GLTraits::Members<T, Values...>{},
27 26
         offset   + sizeof(Value),
28 27
         location + GLTraits::Value<Value>::columns
29 28
     );
30 29
 }
31
-void vertex_setup(GLTraits::Members<>, std::size_t, std::size_t, GLint)
30
+template<typename T>
31
+void vertex_setup(GLTraits::Members<T>, std::size_t, GLint)
32 32
 {}
33 33
 
34 34
 
... ...
@@ -44,5 +44,5 @@ int main()
44 44
         GLubyte    flags;
45 45
         GLdouble   unaligned;
46 46
     };
47
-    vertex_setup(GLTraits::members<Vertex>(), sizeof(Vertex));
47
+    vertex_setup(GLTraits::members<Vertex>());
48 48
 }