subject

Arrays are very dangerous data types for many reasons, one of which is that they don't have an at method like vectors that raises an exception if an improper index is used. write a function named "safe_at" that takes an array and an index and returns a reference to the element (at that index) in the array. the array can be of any type, and the index is a size_t. if the index is greater or equal to the size of the array, raise a std: : out_of_range exception.

input:

#include
int arr_1[] {1, 7, 9, 3, 67};
assert_eq(safe_at(arr_1, 0), 1);
assert_eq(safe_at(arr_1, 4), 67);
assert_throw(safe_at(arr_1, 5), std: : out_of_range);
assert_throw(safe_at(arr_1, -1), std: : out_of_range);
assert_eq(safe_at(arr_1, 2), 9);

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:30
How do you make a lenny face? plz, brailiest to who can answer first.
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
Match the items with their respective descriptions.
Answers: 1
question
Computers and Technology, 23.06.2019 14:00
In which job role will you be creating e-papers, newsletters and preiodicals
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
Jamie has to enter the names, employee id’s, and income of a group of employees into a worksheet. which option will jamie use to describe the data
Answers: 3
You know the right answer?
Arrays are very dangerous data types for many reasons, one of which is that they don't have an at me...
Questions
question
Mathematics, 16.10.2020 16:01
question
Mathematics, 16.10.2020 16:01
question
Mathematics, 16.10.2020 16:01
question
Mathematics, 16.10.2020 16:01
question
English, 16.10.2020 16:01
question
Mathematics, 16.10.2020 16:01