Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gammasoft71/xtd
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Nov 17, 2024
2 parents e36328f + 2eca143 commit cf5e290
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/xtd.core.examples/keywords/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ add_projects(
interface2
lock
lock_guard_keyword
nameof
startup_keyword
static
static_object
static_object2
typeof
using
)
6 changes: 6 additions & 0 deletions examples/xtd.core.examples/keywords/nameof/CMakeLists.txt
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)
26 changes: 26 additions & 0 deletions examples/xtd.core.examples/keywords/nameof/README.md
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
```
25 changes: 25 additions & 0 deletions examples/xtd.core.examples/keywords/nameof/src/nameof.cpp
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

6 changes: 6 additions & 0 deletions examples/xtd.core.examples/keywords/typeof/CMakeLists.txt
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)
33 changes: 33 additions & 0 deletions examples/xtd.core.examples/keywords/typeof/README.md
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
```
37 changes: 37 additions & 0 deletions examples/xtd.core.examples/keywords/typeof/src/typeof.cpp
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
2 changes: 2 additions & 0 deletions src/xtd.core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ add_sources(
include/xtd/size
include/xtd/size_object.h
include/xtd/size_object
include/xtd/sizeof.h
include/xtd/sizeof
include/xtd/slong.h
include/xtd/slong
include/xtd/slong_object.h
Expand Down
2 changes: 1 addition & 1 deletion src/xtd.core/include/xtd/nameof.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace xtd {
/// class c {
/// public:
/// void f(int i) {
/// log(xtd::string::format("{0}.{1}", typeof_(C), nameof_(f)), "method entry");
/// log(xtd::string::format("{0}::{1}", typeof_<c>(), nameof_(f)), "method entry");
/// }
/// }
/// ```
Expand Down
2 changes: 2 additions & 0 deletions src/xtd.core/include/xtd/sizeof
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "sizeof.h"
18 changes: 18 additions & 0 deletions src/xtd.core/include/xtd/sizeof.h
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__)
}
1 change: 1 addition & 0 deletions src/xtd.core/include/xtd/xtd.core.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
#include "single_object.h"
#include "size.h"
#include "size_object.h"
#include "sizeof.h"
#include "slong.h"
#include "slong_object.h"
#include "sptr.h"
Expand Down

0 comments on commit cf5e290

Please sign in to comment.