1919
2020#include < algorithm>
2121#include < cstddef>
22+ #include < stdexcept>
2223#include < string>
2324#include < vector>
2425
@@ -232,12 +233,13 @@ class SparseVectorMap
232233
233234 @return reference to the requested item.
234235
236+ @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
235237 */
236238 classT& operator [](keyT id)
237239 {
238240 int index = binary_search_find (id);
239241 if ( index == -1 ) {
240- // Need to error out
242+ throw std::out_of_range ( " SparseVectorMap: trying to access element that does not exist " );
241243 }
242244 return data[index];
243245 }
@@ -252,12 +254,13 @@ class SparseVectorMap
252254
253255 @return const reference to the requested item.
254256
257+ @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
255258 */
256259 const classT& operator [](keyT id) const
257260 {
258261 int index = binary_search_find (id);
259262 if ( index == -1 ) {
260- // Need to error out
263+ throw std::out_of_range ( " SparseVectorMap: trying to access element that does not exist " );
261264 }
262265 return data[index];
263266 }
@@ -498,12 +501,13 @@ class SparseVectorMap<keyT, classT*>
498501
499502 @return reference to the requested item.
500503
504+ @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
501505 */
502506 classT* operator [](keyT id)
503507 {
504508 int index = binary_search_find (id);
505509 if ( index == -1 ) {
506- // Need to error out
510+ throw std::out_of_range ( " SparseVectorMap: trying to access element that does not exist " );
507511 }
508512 return data[index];
509513 }
@@ -518,12 +522,13 @@ class SparseVectorMap<keyT, classT*>
518522
519523 @return const reference to the requested item.
520524
525+ @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
521526 */
522527 const classT* operator [](keyT id) const
523528 {
524529 int index = binary_search_find (id);
525530 if ( index == -1 ) {
526- // Need to error out
531+ throw std::out_of_range ( " SparseVectorMap: trying to access element that does not exist " );
527532 }
528533 return data[index];
529534 }
@@ -781,12 +786,13 @@ class SparseVectorMap<keyT, keyT>
781786
782787 @return reference to the requested item.
783788
789+ @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
784790 */
785791 keyT& operator [](keyT id)
786792 {
787793 int index = binary_search_find (id);
788794 if ( index == -1 ) {
789- // Need to error out
795+ throw std::out_of_range ( " SparseVectorMap: trying to access element that does not exist " );
790796 }
791797 return data[index];
792798 }
@@ -801,12 +807,13 @@ class SparseVectorMap<keyT, keyT>
801807
802808 @return const reference to the requested item.
803809
810+ @exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
804811 */
805812 const keyT& operator [](keyT id) const
806813 {
807814 int index = binary_search_find (id);
808815 if ( index == -1 ) {
809- // Need to error out
816+ throw std::out_of_range ( " SparseVectorMap: trying to access element that does not exist " );
810817 }
811818 return data[index];
812819 }
0 commit comments