@@ -46,7 +46,7 @@ To be a sequence class must follow the concept:
46
46
47
47
class Sequence
48
48
{
49
- using ValueType = <unspecified>;
49
+ using value_type = <unspecified>;
50
50
51
51
Sequence();
52
52
@@ -61,11 +61,10 @@ class Sequence
61
61
constexpr <unspecified> find(TValue value) const;
62
62
}
63
63
64
- ValueType may have any constraints depending on specific sequences but it also must have operator==.
65
- It is forbidden to use any of existing sequences with several equal values. It will lead to hangs.
66
- Each of existing sequences which can produce such scenario has assert which will fail with a reason
67
- of failure stated.
68
- Example: sequence 1-2-1 will be looped as:
64
+ 'value_type' may have any constraints depending on specific sequences but it also must have
65
+ operator==. It is forbidden to use any of existing sequences with several equal values. It will lead
66
+ to hangs. Each of existing sequences which can produce such scenario has assert which will fail with
67
+ a reason of failure stated. Example: sequence 1-2-1 will be looped as:
69
68
70
69
1-2-1 -> 1-2-1 -> 1-2-1 -> 1-2-1
71
70
| | | |
@@ -185,19 +184,27 @@ auto GenericFind(const TRange& range, const TValue& value)
185
184
template <class TValue , TValue... values>
186
185
struct Sequence
187
186
{
188
- using const_iterator = const TValue*;
189
- using ValueType = TValue;
187
+ using sequence_type = std::array<TValue, sizeof ...(values)>;
188
+ using value_type = typename sequence_type::value_type;
189
+ using iterator = typename sequence_type::iterator;
190
+ using const_iterator = typename sequence_type::const_iterator;
191
+ using reference = typename sequence_type::reference;
192
+ using const_reference = typename sequence_type::const_reference;
193
+ using difference_type = typename sequence_type::difference_type;
190
194
191
195
Sequence () { assert (ValidateValues () && " Values must be unique" ); }
192
196
193
197
constexpr const_iterator begin () const { return data.begin (); }
194
198
constexpr const_iterator end () const { return data.end (); }
195
- constexpr const_iterator find (const TValue& value) const { return data.data () + find_ (value); }
199
+ constexpr const_iterator find (const_reference value) const
200
+ {
201
+ return std::next (data.begin (), find_ (value));
202
+ }
196
203
197
204
private:
198
205
static constexpr std::array<int , sizeof ...(values)> data = {{values...}};
199
206
200
- static constexpr int ValuesCount () { return sizeof ...(values); }
207
+ static constexpr difference_type ValuesCount () { return sizeof ...(values); }
201
208
202
209
static constexpr bool ValidateValues ()
203
210
{
@@ -209,31 +216,31 @@ struct Sequence
209
216
return true ;
210
217
}
211
218
212
- template <int icur, TValue cur, TValue... rest>
219
+ template <difference_type icur, TValue cur, TValue... rest>
213
220
struct Find
214
221
{
215
- int operator ()(const TValue& value) const
222
+ constexpr difference_type operator ()(const TValue& value) const
216
223
{
217
224
if (value == cur)
218
225
return icur;
219
226
return rest_ (value);
220
227
}
221
228
222
- Find<icur + 1 , rest...> rest_ = {};
229
+ Find<icur + 1 , rest...> rest_{};
223
230
};
224
231
225
- template <int icur, TValue cur>
232
+ template <difference_type icur, TValue cur>
226
233
struct Find <icur, cur>
227
234
{
228
- int operator ()(const TValue& value) const
235
+ constexpr difference_type operator ()(const TValue& value) const
229
236
{
230
237
if (value == cur)
231
238
return icur;
232
239
return icur + 1 ;
233
240
}
234
241
};
235
242
236
- Find<0 , values...> find_ = {};
243
+ Find<0 , values...> find_{};
237
244
};
238
245
239
246
template <class TValue >
@@ -280,7 +287,7 @@ template <class TValue, TValue low, TValue high>
280
287
struct Span
281
288
{
282
289
using const_iterator = SpanIterator<int , high>;
283
- using ValueType = TValue;
290
+ using value_type = TValue;
284
291
285
292
constexpr const_iterator begin () const { return {low}; }
286
293
constexpr const_iterator end () const { return {}; }
@@ -326,7 +333,7 @@ template <class TValue, TValue low, TValue high>
326
333
struct TwoPowersSpan
327
334
{
328
335
using const_iterator = TwoPowersSpanIterator<int , high>;
329
- using ValueType = TValue;
336
+ using value_type = TValue;
330
337
331
338
constexpr const_iterator begin () const { return {low}; }
332
339
constexpr const_iterator end () const { return {high + 1 }; }
@@ -349,12 +356,12 @@ struct TwoPowersSpan
349
356
};
350
357
351
358
template <class TFirst , class ... TRest>
352
- struct JoinIterator : public SequenceIteratorBase <typename TFirst::ValueType >
359
+ struct JoinIterator : public SequenceIteratorBase <typename TFirst::value_type >
353
360
{
354
- using ValueType = typename TFirst::ValueType ;
361
+ using value_type = typename TFirst::value_type ;
355
362
356
- JoinIterator () : SequenceIteratorBase<ValueType >(0 ) {}
357
- JoinIterator (ValueType value_) : SequenceIteratorBase<ValueType >(value_), finished(false ) {}
363
+ JoinIterator () : SequenceIteratorBase<value_type >(0 ) {}
364
+ JoinIterator (value_type value_) : SequenceIteratorBase<value_type >(value_), finished(false ) {}
358
365
359
366
JoinIterator& operator ++()
360
367
{
@@ -389,7 +396,7 @@ struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
389
396
template <class TCur , class TNext , class ... TRest_>
390
397
struct Next <TCur, TNext, TRest_...>
391
398
{
392
- bool operator ()(ValueType & value)
399
+ bool operator ()(value_type & value)
393
400
{
394
401
auto it = GenericFind (cur, value);
395
402
@@ -415,7 +422,7 @@ struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
415
422
template <class TSeq >
416
423
struct Next <TSeq>
417
424
{
418
- bool operator ()(ValueType & value)
425
+ bool operator ()(value_type & value)
419
426
{
420
427
auto it = GenericFind (seq, value);
421
428
@@ -436,20 +443,20 @@ struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
436
443
template <class TFirst , class ... TRest>
437
444
struct Join
438
445
{
439
- using ValueType = typename TFirst::ValueType ;
446
+ using value_type = typename TFirst::value_type ;
440
447
using const_iterator = JoinIterator<TFirst, TRest...>;
441
448
442
449
Join () { assert (Validate () && " Values must be unique" ); }
443
450
444
451
constexpr const_iterator begin () const { return {*first.begin ()}; }
445
452
constexpr const_iterator end () const { return {}; }
446
- constexpr const_iterator find (ValueType value) const { return find_ (value); }
453
+ constexpr const_iterator find (value_type value) const { return find_ (value); }
447
454
448
455
private:
449
456
template <class TCur , class ... TRest_>
450
457
struct Find
451
458
{
452
- const_iterator operator ()(ValueType value) const
459
+ const_iterator operator ()(value_type value) const
453
460
{
454
461
auto it = cur (value);
455
462
return it ? it : rest (value);
@@ -463,7 +470,7 @@ struct Join
463
470
template <class TSeq >
464
471
struct Find <TSeq>
465
472
{
466
- const_iterator operator ()(ValueType value) const
473
+ const_iterator operator ()(value_type value) const
467
474
{
468
475
auto it = GenericFind (seq, value);
469
476
@@ -480,7 +487,7 @@ struct Join
480
487
bool Validate () const
481
488
{
482
489
auto cur = begin ();
483
- std::vector<ValueType > values (1 , *cur);
490
+ std::vector<value_type > values (1 , *cur);
484
491
485
492
while (++cur != end ())
486
493
{
@@ -497,11 +504,11 @@ struct Join
497
504
Find<TFirst, TRest...> find_ = {};
498
505
};
499
506
500
- template <class TInner , typename TInner::ValueType mul>
507
+ template <class TInner , typename TInner::value_type mul>
501
508
struct MultipliedIterator
502
509
{
503
510
using InnerIterator = typename TInner::const_iterator;
504
- using ValueType = typename TInner::ValueType ;
511
+ using value_type = typename TInner::value_type ;
505
512
506
513
MultipliedIterator (InnerIterator inner_) : inner(inner_) {}
507
514
@@ -518,7 +525,7 @@ struct MultipliedIterator
518
525
return copy;
519
526
}
520
527
521
- ValueType operator *() const { return mul * *inner; }
528
+ value_type operator *() const { return mul * *inner; }
522
529
bool operator ==(const MultipliedIterator& other) const { return inner == other.inner ; }
523
530
bool operator !=(const MultipliedIterator& other) const { return !(*this == other); }
524
531
@@ -527,15 +534,15 @@ struct MultipliedIterator
527
534
};
528
535
529
536
// / A sequence containing values of another sequence multiplied by a constant.
530
- template <class TInner , typename TInner::ValueType mul>
537
+ template <class TInner , typename TInner::value_type mul>
531
538
struct Multiplied
532
539
{
533
- using ValueType = typename TInner::ValueType ;
540
+ using value_type = typename TInner::value_type ;
534
541
using const_iterator = MultipliedIterator<TInner, mul>;
535
542
536
543
constexpr const_iterator begin () const { return {inner.begin ()}; }
537
544
constexpr const_iterator end () const { return {inner.end ()}; }
538
- constexpr const_iterator find (ValueType value) const
545
+ constexpr const_iterator find (value_type value) const
539
546
{
540
547
return {GenericFind (inner, value / mul)};
541
548
}
@@ -614,7 +621,7 @@ bool SeqNextImpl(rank<1>, const Sequence<TValue, first, values...>&, TValue& val
614
621
}
615
622
616
623
template <class TSequence >
617
- bool SeqNextImpl (rank<0 >, const TSequence& seq, typename TSequence::ValueType & value)
624
+ bool SeqNextImpl (rank<0 >, const TSequence& seq, typename TSequence::value_type & value)
618
625
{
619
626
auto it = GenericFind (seq, value);
620
627
@@ -630,7 +637,7 @@ bool SeqNextImpl(rank<0>, const TSequence& seq, typename TSequence::ValueType& v
630
637
}
631
638
632
639
template <class TSequence >
633
- bool SeqNext (const TSequence& seq, typename TSequence::ValueType & value)
640
+ bool SeqNext (const TSequence& seq, typename TSequence::value_type & value)
634
641
{
635
642
return SeqNextImpl (rank<16 >{}, seq, value);
636
643
}
0 commit comments