xtd
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
index.cpp
Shows how to use
xtd::index
struct.
#include <xtd/xtd>
auto
main() ->
int
{
auto
items = list {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
xtd::println
(
"items[xtd::index::from_start(0)] = {}"
, items[
xtd::index::from_start
(0)]);
xtd::println
(
"items(xtd::index {{1, false}}) = {}"
, items(
xtd::index
{1,
false
}));
xtd::println
(
"items[xtd::index {{2}}] = {}"
, items[
xtd::index
{2}]);
xtd::println
(
"items(xtd::index {{~3, true}}) = {}"
, items(
xtd::index
{~3,
true
}));
xtd::println
(
"items[xtd::index {{4}}] = {}"
, items[
xtd::index
{4}]);
xtd::println
(
"items(xtd::index {{5}}) = {}"
, items(
xtd::index
{5}));
xtd::println
(
"items[xtd::index {{6}}] = {}"
, items[
xtd::index
{6}]);
xtd::println
(
"items(xtd::index {{7}}) = {}"
, items(
xtd::index
{7}));
xtd::println
(
"items[xtd::index {{8}}] = {}"
, items[
xtd::index
{8}]);
xtd::println
(
"items(xtd::index::from_start(9)) = {}"
, items(
xtd::index::from_start
(9)));
xtd::println
();
xtd::println
(
"items[xtd::index::from_end(1)] = {}"
, items[
xtd::index::from_end
(1)]);
xtd::println
(
"items(xtd::index {{2}}, true)) = {}"
, items(
xtd::index
{2,
true
}));
xtd::println
(
"items[xtd::index {{~3}}] = {}"
, items[
xtd::index
{~3}]);
xtd::println
(
"items(xtd::index {{~4, false}}) = {}"
, items(
xtd::index
{~4,
false
}));
xtd::println
(
"items[xtd::index {{~5}}] = {}"
, items[
xtd::index
{~5}]);
xtd::println
(
"items(xtd::index {{~6}}) = {}"
, items(
xtd::index
{~6}));
xtd::println
(
"items[xtd::index {{~7}}] = {}"
, items[
xtd::index
{~7}]);
xtd::println
(
"items(xtd::index {{~8}}) = {}"
, items(
xtd::index
{~8}));
xtd::println
(
"items[xtd::index {{~9}}] = {}"
, items[
xtd::index
{~9}]);
xtd::println
(
"items(xtd::index::from_end(10)) = {}"
, items(
xtd::index::from_end
(10)));
}
// This code produces the following output :
//
// items[xtd::index::from_start(0)] = 1
// items(xtd::index {1, false}) = 2
// items[xtd::index {2}] = 3
// items(xtd::index {~3, true}) = 4
// items[xtd::index {4}] = 5
// items(xtd::index {5}) = 6
// items[xtd::index {6}] = 7
// items(xtd::index {7}) = 8
// items[xtd::index {8}] = 9
// items(xtd::index::from_start(9)) = 10
//
// items[xtd::index::from_end(1)] = 10
// items(xtd::index {2, true}) = 9
// items[xtd::index {~3}] = 8
// items(xtd::index {~4, false}) = 7
// items[xtd::index {~5}] = 6
// items(xtd::index {~6}) = 5
// items[xtd::index {~7}] = 4
// items(xtd::index {~8}) = 3
// items[xtd::index {~9}] = 2
// items(xtd::index::from_end(10)) = 1
xtd::println
auto println(FILE *file) -> void
Writes the current line terminator to the file output stream using the specified format information.
Definition
println.hpp:15
xtd::index
Represents a type that can be used to index a collection either from the beginning or the end.
Definition
index.hpp:38
xtd::index::from_end
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
xtd::index::from_start
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
Generated on
for xtd by
Gammasoft
. All rights reserved.