#include <xtd/xtd>
auto main() -> int {
auto items = list {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
}
auto println(FILE *file) -> void
Writes the current line terminator to the file output stream using the specified format information.
Definition println.hpp:15
Represents a type that can be used to index a collection either from the beginning or the end.
Definition index.hpp:38
static constexpr auto from_end(xtd::integer auto value)
Creates an xtd::ndex from the end of a collection at a specified index position.
Definition index.hpp:181
static constexpr auto from_start(xtd::integer auto value)
Creates an xtd::ndex from the start of a collection at a specified index position.
Definition index.hpp:186
The following example demonstrates how to use index literal operator. #include <xtd/xtd>
auto main() -> int {
auto items = list {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
println(R
"(items["0"_i] = {})", items["0"_i]);
println(
"items(1_i) = {}", items(1_i));
println(R
"(items[u8"(2"_i] = {})", items[u8"2"_i]);
println(
"items(3_i) = {}", items(3_i));
println(
"items[4_i] = {}", items[4_i]);
println(
"items(5_i) = {}", items(5_i));
println(
"items[6_i] = {}", items[6_i]);
println(
"items(7_i) = {}", items(7_i));
println(
"items[8_i] = {}", items[8_i]);
println(R
"(items(u"9"_i) = {})", items(u"9"_i));
println(R
"(items["~1"_i] = {})", items["~1"_i]);
println(
"items(~2_i) = {}", items(~2_i));
println(R
"(items[U"~3"_i] = {})", items[U"~3"_i]);
println(
"items(~4_i) = {}", items(~4_i));
println(
"items[~5_i] = {}", items[~5_i]);
println(
"items(~6_i) = {}", items(~6_i));
println(
"items[~7_i] = {}", items[~7_i]);
println(
"items(~8_i) = {}", items(~8_i));
println(
"items[~9_i] = {}", items[~9_i]);
println(R
"(items(L"~10"_i) = {})", items(L"~10"_i));
}
The following example shows how to create your own collection with #include <xtd/xtd>
struct persona {
string name;
int age;
};
class persona_collection {
public:
persona_collection() = default;
persona_collection(std::initializer_list<persona> items) : items_ {items} {}
auto to_string() const noexcept ->
string {
return string::format(
"[{}]", string::join(
", ", items_));}
auto operator [](usize index) -> persona& {return items_[index];}
auto operator [](usize index) const -> const persona& {return items_[index];}
auto operator [](xtd::index index) -> persona& {return operator [](index.get_offset(items_.count()));}
auto operator [](xtd::index index) const -> const persona& {return operator [](index.get_offset(items_.count()));}
private:
list<persona> items_;
};
auto main() -> int {
auto items = persona_collection {{.name = "Oliver Queen", .age = 24}, {.name = "Laurel Lance", .age = 23}, {.name = "John \"Dig\" Diggle", .age = 27}, {.name = "Thea Queen", .age = 20}, {.name = "Felicity Smoak", .age = 22}};
println(
"items[0_i] = {}", items[0_i]);
println(
"items[2] = {}", items[2]);
println(
"items[~1_i] = {}", items[~1_i]);
println(
"items[1_i] = {}", items[1_i]);
items[1_i].age = 24;
println(
"items[1_i] (updated) = {}", items[1_i]);
}
auto to_string() const noexcept -> xtd::string override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:354
auto to_string() const noexcept -> xtd::string override
Returns the string representation of the current Range object.