Shows how to use xtd::array::as_read_only method.
#include <xtd/xtd>
auto print_index_and_values(const array<string>& my_arr) -> void {
for (auto i = 0_z; i < my_arr.length(); ++i)
console::write_line(" [{0}] : {1}", i, my_arr[i]);
console::write_line();
}
auto print_index_and_values(const ilist<string>& my_list) -> void {
for (auto i = 0_z; i < my_list.count(); ++i)
console::write_line( " [{0}] : {1}", i, my_list[i]);
console::write_line();
}
auto main() -> int {
auto my_arr = array<string> {"The", "quick", "brown", "fox"};
console::write_line("The string array initially contains the following values:");
print_index_and_values(my_arr);
auto my_list = array<>::as_read_only(my_arr);
console::write_line("The read-only ilist contains the following values:");
print_index_and_values(my_list);
try {
my_list[3] = "CAT";
} catch (const not_supported_exception& e) {
console::write_line(
"{} - {}",
e.get_type(),
e.message());
console::write_line();
}
my_arr[2] = "RED";
console::write_line("After changing the third element, the string array contains the following values:");
print_index_and_values( my_arr );
console::write_line("After changing the third element, the read-only ilist contains the following values:");
print_index_and_values(my_list);
}
@ e
The E key.
Definition console_key.hpp:96