Skip to content

Commit 6d9edae

Browse files
committed
Renamed and moved files.
1 parent 842633c commit 6d9edae

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

Demonstration/__func__.cpp renamed to CompilerMacro/__func__.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(void)
6060
{
6161
/* Test __func__ predefined macro */
6262
std::cout << hello() << "\n"
63-
<< world() << std::endl;
63+
<< world() << "\n";
6464
LOG("Function call hello() returns: %s", hello());
6565
LOG("Function call world() returns: %s", world());
6666

@@ -75,4 +75,4 @@ int main(void)
7575

7676
system("pause");
7777
return 0;
78-
}
78+
}

CompilerMacro/macro_expansion.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*****************************************************************//**
2+
* \file macro_expansion.cpp
3+
* \brief Macro expansion in C++
4+
*
5+
* \author Xuhua Huang
6+
* \date November 2022
7+
*********************************************************************/
8+
9+
#include <iostream>
10+
11+
#define M(x, y, z) x*y+z
12+
13+
int main(void)
14+
{
15+
int a = 1, b = 2, c = 3;
16+
int sum = M(a+b, b+c, a+c);
17+
18+
// M(a, b, a) = M(1, 2, 1) = 3
19+
// M(b, c, c) = M(2, 3, 3) = 9
20+
std::cout << "sum = " << sum << "\n";
21+
22+
return 0;
23+
}

Demonstration/demo_constexpr.cpp renamed to Constexpr/demo_constexpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ void demo_constexpr(const int arg) {
6565
return;
6666
}
6767

68-
int main(void) {
68+
auto main(void) -> int {
6969
int temp_const = get_const();
70-
std::cout << "Value of temp_const: " << temp_const << std::endl;
70+
std::cout << "Value of temp_const: " << temp_const << "\n";
7171

7272
demo_constexpr(1);
7373
demo_constexpr(2);
7474

7575
system("pause");
76-
return 0;
77-
}
76+
return EXIT_SUCCESS;
77+
}

TrickyQuestions/macro.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

Demonstration/decltype.cpp renamed to TypeInfo/decltype.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool is_same_type(const T& t, const U& u) {
4949
template<typename T, typename U>
5050
bool is_same_type() {
5151
bool _same_type = false;
52-
// std::cout << "Overload " << __func__ << std::endl;
52+
// std::cout << "Overload " << __func__ << "\n";
5353
if (typeid(T).hash_code() == typeid(U).hash_code()) {
5454
_same_type = true;
5555
}
@@ -67,31 +67,31 @@ int main(void) {
6767
* Returned value can be assigned to an object of std::string.
6868
* operator[] and std::string::at() methods still apply.
6969
*/
70-
std::cout << "White type: " << typeid(w).name() << std::endl; // 5White
71-
std::cout << "Black type: " << typeid(b).name() << std::endl; // 5Black
70+
std::cout << "White type: " << typeid(w).name() << "\n"; // 5White
71+
std::cout << "Black type: " << typeid(b).name() << "\n"; // 5Black
7272

7373
/* Operation with the returned type. */
7474
const std::string class_name = typeid(w).name();
75-
std::cout << "Class name of object " << std::quoted("w") << ": " << class_name << std::endl
76-
<< "Length: " << class_name[0] << std::endl; /* class_name.at(0) */
75+
std::cout << "Class name of object " << std::quoted("w") << ": " << class_name << "\n"
76+
<< "Length: " << class_name[0] << "\n"; /* class_name.at(0) */
7777

7878
/* Explicitly parse the name of the classes and objects. */
7979
std::cout << std::quoted("is_same_type<White, Black>(w, b)") << ": "
80-
<< is_same_type<White, Black>(w, b) << std::endl;
80+
<< is_same_type<White, Black>(w, b) << "\n";
8181

8282
/* Using decltype() to let the compiler dynamically derive the type. */
8383
std::cout << std::quoted("is_same_type<decltype(w), decltype(b)>(w, b)") << ": "
84-
<< is_same_type<decltype(w), decltype(b)>(w, b) << std::endl;
84+
<< is_same_type<decltype(w), decltype(b)>(w, b) << "\n";
8585

8686
/* With overload function. */
8787
std::cout << std::quoted("is_same_type<decltype(w), decltype(b)>()") << ": "
88-
<< is_same_type<decltype(w), decltype(b)>() << std::endl;
88+
<< is_same_type<decltype(w), decltype(b)>() << "\n";
8989

9090
/* With std::is_same<T, U> from <type_traits>. */
9191
White wht; // create another instance of class White
9292
std::cout << std::quoted("std::is_same<decltype(w), decltype(wht)>::value") << ": "
93-
<< std::is_same<decltype(w), decltype(wht)>::value << std::endl;
93+
<< std::is_same<decltype(w), decltype(wht)>::value << "\n";
9494

9595
system("pause");
9696
return 0;
97-
}
97+
}

0 commit comments

Comments
 (0)