@@ -132,27 +132,30 @@ struct is_expression<T &, void>
132
132
{};
133
133
134
134
template < typename T >
135
- struct expr_column
135
+ struct column_name
136
136
{
137
- expr_column ()
137
+ column_name ()
138
138
: m_colnum( std::numeric_limits<decltype (m_colnum)>::max )
139
139
{
140
140
}
141
141
142
- bool bind_column ( const std::string& name, size_t num )
142
+ void set_column_name ( size_t col, std::string name )
143
143
{
144
- if ( m_name == name ) {
145
- m_colnum = num;
146
- return true ;
144
+ if ( name == m_name ) {
145
+ m_colnum = col;
147
146
}
148
- return false ;
149
147
}
150
148
151
149
template < typename ... Ts >
152
150
const T& get_value ( const frame_iterator< Ts... >& fi ) const
153
151
{
154
- T& val = fi.template get <m_colnum>();
155
- return val;
152
+ return fi.get ( m_colnum );
153
+ }
154
+
155
+ template < typename ... Ts >
156
+ T& get_value ( frame_iterator< Ts... >& fi ) const
157
+ {
158
+ return fi.get ( m_colnum );
156
159
}
157
160
158
161
std::string m_name;
@@ -167,13 +170,18 @@ struct terminal
167
170
168
171
terminal ( T _t ) : t( _t ) {}
169
172
170
- bool bind_column ( const std::string&, size_t )
173
+ void set_column_name ( size_t , std::string )
174
+ {
175
+ }
176
+
177
+ template < typename ... Ts >
178
+ const T& get_value ( const frame_iterator<Ts...>& )
171
179
{
172
- return false ;
180
+ return t ;
173
181
}
174
182
175
183
template < typename ... Ts >
176
- const T& get_value ( const frame_iterator< Ts... >& ) const
184
+ T& get_value ( const frame_iterator<Ts...>& )
177
185
{
178
186
return t;
179
187
}
@@ -182,16 +190,16 @@ struct terminal
182
190
};
183
191
184
192
template < typename T >
185
- struct terminal < expr_column <T> >
193
+ struct terminal < column_name <T> >
186
194
{
187
195
using is_expr = void ;
188
196
using return_type = T;
189
197
190
- terminal ( expr_column <T> _t ) : t( _t ) {}
198
+ terminal ( column_name <T> _t ) : t( _t ) {}
191
199
192
- bool bind_column ( const std::string& name, size_t num )
200
+ void set_column_name ( size_t colind, std::string colname )
193
201
{
194
- return t. bind_column ( name, num );
202
+ t. set_column_name ( colind, colname );
195
203
}
196
204
197
205
template < typename ... Ts >
@@ -200,29 +208,40 @@ struct terminal< expr_column<T> >
200
208
return t.get_value ( fi );
201
209
}
202
210
203
- expr_column<T> t;
211
+ template < typename ... Ts >
212
+ T& get_value ( frame_iterator< Ts... >& fi )
213
+ {
214
+ return t.get_value ( fi );
215
+ }
216
+
217
+ column_name<T> t;
204
218
};
205
219
206
- template < template <typename , typename > typename Op, typename L, typename R >
220
+ template < template <typename , typename > class Op , typename L, typename R >
207
221
struct binary_expr
208
222
{
209
223
using is_expr = void ;
210
224
using op = Op<typename L::return_type, typename R::return_type>;
211
225
using return_type = typename op::return_type;
212
- static_assert ( is_expression<L>::value );
213
- static_assert ( is_expression<R>::value );
226
+ static_assert ( is_expression<L>::value , " binary expression left must be expression " );
227
+ static_assert ( is_expression<R>::value , " binary expression right must be expression " );
214
228
215
229
binary_expr ( L _l, R _r ) : l( _l ), r( _r ) {}
216
230
217
- bool bind_column ( const std::string& name, size_t num )
231
+ void set_column_name ( size_t colind, std::string colname )
218
232
{
219
- auto lb = l.bind_column ( name, num );
220
- auto rb = r.bind_column ( name, num );
221
- return lb || rb;
233
+ l.set_column_name ( colind, colname );
234
+ r.set_column_name ( colind, colname );
222
235
}
223
236
224
237
template < typename ... Ts >
225
- return_type get_value ( const frame_iterator< Ts... >& fi ) const
238
+ const return_type& get_value ( const frame_iterator< Ts... >& fi ) const
239
+ {
240
+ return op::exec ( l.get_value ( fi ), r.get_value ( fi ) );
241
+ }
242
+
243
+ template < typename ... Ts >
244
+ return_type& get_value ( frame_iterator< Ts... >& fi )
226
245
{
227
246
return op::exec ( l.get_value ( fi ), r.get_value ( fi ) );
228
247
}
@@ -234,23 +253,29 @@ struct binary_expr
234
253
// Op is a member type in expr_op
235
254
// T must be either terminal<>, unary_expr<>, or binary_expr<> (no
236
255
// unwrapped types - that's why make_unary_expr exists)
237
- template < template <typename > typename Op, typename T >
256
+ template < template <typename > class Op , typename T >
238
257
struct unary_expr
239
258
{
240
259
using is_expr = void ;
241
260
using op = Op<typename T::return_type>;
242
261
using return_type = typename op::return_type;
243
- static_assert ( is_expression<T>::value );
262
+ static_assert ( is_expression<T>::value , " unary expression must contain expression " );
244
263
245
264
unary_expr ( T _t ) : t( _t ) {}
246
265
247
- bool bind_column ( const std::string& name, size_t num )
266
+ void set_column_name ( size_t colind, std::string colname )
248
267
{
249
- return t. bind_expr_column ( name, num );
268
+ t. set_column_name ( colind, colname );
250
269
}
251
270
252
271
template < typename ... Ts >
253
- return_type get_value ( const frame_iterator< Ts... >& fi ) const
272
+ const return_type& get_value ( const frame_iterator< Ts... >& fi ) const
273
+ {
274
+ return op::exec ( t.get_value ( fi ) );
275
+ }
276
+
277
+ template < typename ... Ts >
278
+ return_type& get_value ( frame_iterator< Ts... >& fi )
254
279
{
255
280
return op::exec ( t.get_value ( fi ) );
256
281
}
@@ -283,7 +308,7 @@ struct maybe_wrap<terminal<T>>
283
308
}
284
309
};
285
310
286
- template <template <typename > typename Op, typename T>
311
+ template <template <typename > class Op , typename T>
287
312
struct maybe_wrap <unary_expr<Op, T>>
288
313
{
289
314
maybe_wrap () = delete ;
@@ -294,7 +319,7 @@ struct maybe_wrap<unary_expr<Op, T>>
294
319
}
295
320
};
296
321
297
- template <template <typename , typename > typename Op, typename L, typename R>
322
+ template <template <typename , typename > class Op , typename L, typename R>
298
323
struct maybe_wrap <binary_expr<Op, L, R>>
299
324
{
300
325
maybe_wrap () = delete ;
@@ -305,7 +330,7 @@ struct maybe_wrap<binary_expr<Op, L, R>>
305
330
}
306
331
};
307
332
308
- template < template <typename > typename Op, typename T >
333
+ template < template <typename > class Op , typename T >
309
334
struct make_unary_expr
310
335
{
311
336
make_unary_expr () = delete ;
@@ -318,7 +343,7 @@ struct make_unary_expr
318
343
}
319
344
};
320
345
321
- template < template <typename , typename > typename Op, typename L, typename R >
346
+ template < template <typename , typename > class Op , typename L, typename R >
322
347
struct make_binary_expr
323
348
{
324
349
make_binary_expr () = delete ;
@@ -332,11 +357,11 @@ struct make_binary_expr
332
357
};
333
358
334
359
template < typename T >
335
- terminal<expr_column <T>> col ( const char * colname )
360
+ terminal<column_name <T>> col ( const char * colname )
336
361
{
337
- expr_column <T> c;
362
+ column_name <T> c;
338
363
c.name = colname;
339
- return maybe_wrap<expr_column <T>>::wrap ( c );
364
+ return maybe_wrap<column_name <T>>::wrap ( c );
340
365
}
341
366
342
367
template < typename L, typename R >
@@ -429,10 +454,11 @@ typename std::enable_if<is_expression<T>::value, typename make_unary_expr<expr_o
429
454
return make_unary_expr<expr_op::NOT, T>::create ( t );
430
455
}
431
456
432
- // terminal<expr_column_name> col( std::string colname )
433
- // {
434
- // return terminal<expr_column_name>{ expr_column_name{ colname } };
435
- // }
457
+ template < typename T >
458
+ terminal< column_name<T> > col ( const std::string & colname )
459
+ {
460
+ return terminal< column_name<T> >{ column_name<T>{ colname } };
461
+ }
436
462
437
463
438
464
} // namespace mf
0 commit comments