-
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.
Merge branch 'master' of https://github.com/gammasoft71/xtd
- Loading branch information
Showing
12 changed files
with
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(nameof) | ||
find_package(xtd REQUIRED) | ||
add_sources(README.md src/nameof.cpp) | ||
target_type(CONSOLE_APPLICATION) |
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,26 @@ | ||
# nameof | ||
|
||
Shows how to use [nameof_](https://gammasoft71.github.io/xtd/reference_guides/latest/group__keywords.html#gabe3976c5f529fab9b255e38ced18b281) keyword. | ||
|
||
## Sources | ||
|
||
[src/nameof.cpp](src/nameof.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 | ||
|
||
``` | ||
print_names | ||
value_t | ||
the_answer_to_life_the_universe_and_everything is 42 | ||
(124 + 26) / 2 = 75 | ||
``` |
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,25 @@ | ||
#include <xtd/console> | ||
#include <xtd/nameof> | ||
|
||
using namespace xtd; | ||
|
||
template<typename value_t> | ||
void print_names(value_t value) { | ||
auto the_answer_to_life_the_universe_and_everything = value; | ||
console::write_line("{}", nameof_(print_names)); | ||
console::write_line("{}", nameof_(value_t)); | ||
console::write_line("{} is {}", nameof_(the_answer_to_life_the_universe_and_everything), the_answer_to_life_the_universe_and_everything); | ||
console::write_line("{} = {}", nameof_((124 + 26) / 2), (124 + 26) / 2); | ||
} | ||
|
||
auto main() -> int { | ||
print_names(42); | ||
} | ||
|
||
// This code produces the following output : | ||
// | ||
// print_names | ||
// value_t | ||
// the_answer_to_life_the_universe_and_everything is 42 | ||
// (124 + 26) / 2 = 75 | ||
|
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(typeof) | ||
find_package(xtd REQUIRED) | ||
add_sources(README.md src/typeof.cpp) | ||
target_type(CONSOLE_APPLICATION) |
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,33 @@ | ||
# typeof | ||
|
||
Shows how to use [typeof_](https://gammasoft71.github.io/xtd/reference_guides/latest/group__keywords.html#gafa2ffd9b4a6568b57ab2731bec095d99) keyword. | ||
|
||
## Sources | ||
|
||
[src/typeof.cpp](src/typeof.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 | ||
|
||
``` | ||
int | ||
pair<int, double> | ||
xtd::collections::generic::list<int, std::allocator<int>> | ||
xtd::date_time | ||
time_span | ||
int | ||
pair<int, double> | ||
xtd::collections::generic::list<int, std::allocator<int>> | ||
xtd::date_time | ||
time_span | ||
``` |
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/collections/generic/list> | ||
#include <xtd/diagnostics/stopwatch> | ||
#include <xtd/console> | ||
#include <xtd/date_time> | ||
#include <xtd/typeof> | ||
|
||
using namespace xtd; | ||
using namespace xtd::collections::generic; | ||
using namespace xtd::diagnostics; | ||
|
||
auto main() -> int { | ||
console::write_line(typeof_<int>()); | ||
console::write_line(typeof_<std::pair<int, double>>().name()); | ||
console::write_line(typeof_<list<int>>()); | ||
console::write_line(typeof_<date_time>().full_name()); | ||
console::write_line(typeof_<time_span>().name()); | ||
console::write_line(); | ||
console::write_line(typeof_((124 + 26) / 2)); | ||
console::write_line(typeof_(std::make_pair(42, .42)).name()); | ||
console::write_line(typeof_(list {1, 2, 3, 4, 5})); | ||
console::write_line(typeof_(date_time::now()).full_name()); | ||
console::write_line(typeof_(stopwatch::start_new().elapsed()).name()); | ||
} | ||
|
||
// This code produces the following output : | ||
// | ||
// int | ||
// pair<int, double> | ||
// xtd::collections::generic::list<int, std::allocator<int>> | ||
// xtd::date_time | ||
// time_span | ||
// | ||
// int | ||
// pair<int, double> | ||
// xtd::collections::generic::list<int, std::allocator<int>> | ||
// xtd::date_time | ||
// time_span |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
#include "sizeof.h" |
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,18 @@ | ||
/// @file | ||
/// @brief Contains #sizeof_ keyword. | ||
/// @copyright Copyright (c) 2024 Gammasoft. All rights reserved. | ||
#pragma once | ||
/// @brief The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more. | ||
namespace xtd { | ||
/// @brief Used to obtain the size in bytes of the object representation of type or expression. | ||
/// @par Namespace | ||
/// xtd | ||
/// @par Library | ||
/// xtd.core | ||
/// @ingroup xtd_core keywords | ||
/// @par Examples | ||
/// Some C++ examples: | ||
/// @include sizeof.cpp | ||
#define sizeof_(...) \ | ||
sizeof(__VA_ARGS__) | ||
} |
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