File tree 1 file changed +12
-7
lines changed
1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -418,8 +418,7 @@ class FixedArray
418
418
{
419
419
public:
420
420
FixedArray (size_t size)
421
- : m_strIndexErr(" FixedArray: invalid index" )
422
- , m_size(size)
421
+ : m_size(size)
423
422
, m_entries(new T[size])
424
423
{
425
424
}
@@ -433,31 +432,31 @@ class FixedArray
433
432
const T& operator [](size_t index) const
434
433
{
435
434
if (index >= m_size)
436
- throw std::runtime_error (m_strIndexErr );
435
+ raise_expection ( index );
437
436
438
437
return m_entries[index ];
439
438
}
440
439
441
440
T& operator [](size_t index)
442
441
{
443
442
if (index >= m_size)
444
- throw std::runtime_error (m_strIndexErr );
443
+ raise_expection ( index );
445
444
446
445
return m_entries[index ];
447
446
}
448
447
449
448
const T& operator [](int index) const
450
449
{
451
450
if (index < 0 || static_cast <size_t >(index ) >= m_size)
452
- throw std::runtime_error (m_strIndexErr );
451
+ raise_expection ( index );
453
452
454
453
return m_entries[index ];
455
454
}
456
455
457
456
T& operator [](int index)
458
457
{
459
458
if (index < 0 || static_cast <size_t >(index ) >= m_size)
460
- throw std::runtime_error (m_strIndexErr );
459
+ raise_expection ( index );
461
460
462
461
return m_entries[index ];
463
462
}
@@ -479,8 +478,14 @@ class FixedArray
479
478
FixedArray (const FixedArray<T>& );
480
479
FixedArray<T>& operator =(const FixedArray<T>&);
481
480
481
+ void raise_expection (int i) const
482
+ {
483
+ std::stringstream ss;
484
+ ss << " Index " << i << " out of range" ;
485
+ throw std::runtime_error (ss.str ());
486
+ }
487
+
482
488
private:
483
- const char * m_strIndexErr;
484
489
size_t m_size;
485
490
T* const m_entries;
486
491
};
You can’t perform that action at this time.
0 commit comments