-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add xtd::linq::enumerable examples and documentation
- Loading branch information
1 parent
72622ec
commit 8698276
Showing
11 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
examples/xtd.core.examples/linq/enumerable_count/src/enumerable_count.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
examples/xtd.core.examples/linq/enumerable_default_if_empty/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(enumerable_default_if_empty) | ||
find_package(xtd REQUIRED) | ||
add_sources(README.md src/enumerable_default_if_empty.cpp) | ||
target_type(CONSOLE_APPLICATION) |
28 changes: 28 additions & 0 deletions
28
examples/xtd.core.examples/linq/enumerable_default_if_empty/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# enumerable_default_if_empty | ||
|
||
Shows how to use [xtd::linq::enumerable::default_if_empty](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1linq_1_1enumerable.html#a89cb4c7f69e1af47e2d24c5e4e963925) method. | ||
|
||
## Sources | ||
|
||
[src/enumerable_default_if_empty.cpp](src/enumerable_default_if_empty.cpp) | ||
|
||
[CMakeLists.txt](CMakeLists.txt) | ||
|
||
## Build and run | ||
|
||
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following: | ||
|
||
```cmake | ||
xtdc run | ||
``` | ||
|
||
## Output | ||
|
||
``` | ||
pet {name=Barley, age=8} | ||
pet {name=Boots, age=4} | ||
pet {name=Whiskers, age=1} | ||
pet {name=, age=0} | ||
``` |
37 changes: 37 additions & 0 deletions
37
...es/xtd.core.examples/linq/enumerable_default_if_empty/src/enumerable_default_if_empty.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <xtd/xtd> | ||
|
||
using namespace xtd; | ||
|
||
struct pet { | ||
string name; | ||
int age = 0; | ||
|
||
friend bool operator==(const pet& lhs, const pet& rhs) noexcept { | ||
return lhs.name == rhs.name && lhs.age == rhs.age; | ||
} | ||
}; | ||
|
||
auto main() -> int { | ||
auto pets1 = array<pet> { | ||
{.name = "Barley", .age = 8}, | ||
{.name = "Boots", .age = 4}, | ||
{.name = "Whiskers", .age = 1} | ||
}; | ||
for (const auto& [name, age] : pets1.default_if_empty()) | ||
console::write_line("pet {{name={}, age={}}}", name, age); | ||
console::write_line(); | ||
|
||
auto pets2 = array<pet> {}; | ||
for (const auto& [name, age] : pets2.default_if_empty()) | ||
console::write_line("pet {{name={}, age={}}}", name, age); | ||
console::write_line(); | ||
} | ||
|
||
// This code produces the following output : | ||
// | ||
// pet {name=Barley, age=8} | ||
// pet {name=Boots, age=4} | ||
// pet {name=Whiskers, age=1} | ||
// | ||
// pet {name=, age=0} | ||
// |
6 changes: 6 additions & 0 deletions
6
examples/xtd.core.examples/linq/enumerable_default_if_empty2/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(enumerable_default_if_empty2) | ||
find_package(xtd REQUIRED) | ||
add_sources(README.md src/enumerable_default_if_empty2.cpp) | ||
target_type(CONSOLE_APPLICATION) |
28 changes: 28 additions & 0 deletions
28
examples/xtd.core.examples/linq/enumerable_default_if_empty2/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# enumerable_default_if_empty2 | ||
|
||
Shows how to use [xtd::linq::enumerable::default_if_empty](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1linq_1_1enumerable.html#a77cd5c4f6280710bd7422cb5bb6ca0d1) method. | ||
|
||
## Sources | ||
|
||
[src/enumerable_default_if_empty2.cpp](src/enumerable_default_if_empty2.cpp) | ||
|
||
[CMakeLists.txt](CMakeLists.txt) | ||
|
||
## Build and run | ||
|
||
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following: | ||
|
||
```cmake | ||
xtdc run | ||
``` | ||
|
||
## Output | ||
|
||
``` | ||
pet {name=Barley, age=8} | ||
pet {name=Boots, age=4} | ||
pet {name=Whiskers, age=1} | ||
pet {name=Default pet, age=0} | ||
``` |
41 changes: 41 additions & 0 deletions
41
.../xtd.core.examples/linq/enumerable_default_if_empty2/src/enumerable_default_if_empty2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <xtd/xtd> | ||
|
||
using namespace xtd; | ||
|
||
struct pet { | ||
string name; | ||
int age = 0; | ||
|
||
static pet default_pet; | ||
|
||
friend bool operator==(const pet& lhs, const pet& rhs) noexcept { | ||
return lhs.name == rhs.name && lhs.age == rhs.age; | ||
} | ||
}; | ||
|
||
pet pet::default_pet {.name = "Default pet", .age = 0}; | ||
|
||
auto main() -> int { | ||
auto pets1 = array<pet> { | ||
{.name = "Barley", .age = 8}, | ||
{.name = "Boots", .age = 4}, | ||
{.name = "Whiskers", .age = 1} | ||
}; | ||
for (const auto& [name, age] : pets1.default_if_empty(pet::default_pet)) | ||
console::write_line("pet {{name={}, age={}}}", name, age); | ||
console::write_line(); | ||
|
||
auto pets2 = array<pet> {}; | ||
for (const auto& [name, age] : pets2.default_if_empty(pet::default_pet)) | ||
console::write_line("pet {{name={}, age={}}}", name, age); | ||
console::write_line(); | ||
} | ||
|
||
// This code produces the following output : | ||
// | ||
// pet {name=Barley, age=8} | ||
// pet {name=Boots, age=4} | ||
// pet {name=Whiskers, age=1} | ||
// | ||
// pet {name=Default pet, age=0} | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters