Skip to content

Commit 64adc47

Browse files
committed
Add comparable example
1 parent d4ebef2 commit 64adc47

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

examples/xtd.core.examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848

4949
## [Concepts](concepts/README.md)
5050

51-
* [is_stringable](concepts/stringable/README.md) shows how to use how to use [xtd::stringable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1stringable.html) concept.
51+
* [comparable](concepts/comparable/README.md) shows how to use how to use [xtd::comparable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1comparable.html) concept.
52+
* [stringable](concepts/stringable/README.md) shows how to use how to use [xtd::stringable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1stringable.html) concept.
5253

5354
## [Configuration](configuration/README.md)
5455

examples/xtd.core.examples/concepts/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(concepts)
44
find_package(xtd REQUIRED)
55

66
add_projects(
7+
comparable
78
stringable
89
)
910

examples/xtd.core.examples/concepts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[This folder](.) contains guid examples used by [Reference Guide](https://gammasoft71.github.io/xtd/reference_guides/latest/) and more.
44

5+
* [comparable](comparable/README.md) shows how to use how to use [xtd::comparable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1comparable.html) concept.
56
* [stringable](stringable/README.md) shows how to use how to use [xtd::stringable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1stringable.html) concept.
67

78
## Build and run any project
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(comparable)
4+
find_package(xtd REQUIRED)
5+
add_sources(README.md src/comparable.cpp)
6+
target_type(CONSOLE_APPLICATION)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# comparable
2+
3+
Shows how to use [xtd::comparable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1comparable.html) concept.
4+
5+
## Sources
6+
7+
* [src/comparable.cpp](src/comparable.cpp)
8+
* [CMakeLists.txt](CMakeLists.txt)
9+
10+
## Build and run
11+
12+
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:
13+
14+
```cmake
15+
xtdc run
16+
```
17+
18+
## Output
19+
20+
```
21+
max = 42
22+
max = 62.8
23+
min = 1.2.3
24+
min = 00:00:04.1220000
25+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <xtd/xtd>
2+
3+
auto get_max(const comparable auto& a, const comparable auto& b) {return a > b ? a : b;}
4+
auto get_min(const comparable auto& a, const comparable auto& b) {return a < b ? a : b;}
5+
6+
auto main() -> int {
7+
println("max = {}", get_max(42, 21));
8+
println("max = {}", get_max(34.5, 62.8));
9+
println("min = {}", get_min(version {1, 2, 4}, version {1, 2, 3}));
10+
println("min = {}", get_min(4_s + 122_ms, 12_s + 234_ms));
11+
}
12+
13+
// This code produces the following output :
14+
//
15+
// max = 42
16+
// max = 62.8
17+
// min = 1.2.3
18+
// min = 00:00:04.1220000

examples/xtd.core.examples/concepts/stringable/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# stringable
22

3-
Shows how to use [xtd::stringable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1istringable.html) concept.
3+
Shows how to use [xtd::stringable](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1stringable.html) concept.
44

55
## Sources
66

0 commit comments

Comments
 (0)