-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from XuhuaHuang/develop
Develop
- Loading branch information
Showing
50 changed files
with
404 additions
and
148 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(HelloWorld LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
add_executable(HelloWorld "Miscellaneous/hello_world.cpp" "LICENSE.md" "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
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,23 @@ | ||
/*****************************************************************//** | ||
* \file macro_expansion.cpp | ||
* \brief Macro expansion in C++ | ||
* | ||
* \author Xuhua Huang | ||
* \date November 2022 | ||
*********************************************************************/ | ||
|
||
#include <iostream> | ||
|
||
#define M(x, y, z) x*y+z | ||
|
||
int main(void) | ||
{ | ||
int a = 1, b = 2, c = 3; | ||
int sum = M(a+b, b+c, a+c); | ||
|
||
// M(a, b, a) = M(1, 2, 1) = 3 | ||
// M(b, c, c) = M(2, 3, 3) = 9 | ||
std::cout << "sum = " << sum << "\n"; | ||
|
||
return 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
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
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
File renamed without changes.
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,35 @@ | ||
/*****************************************************************//** | ||
* \file OperationFactory.hpp | ||
* \brief Operation factory function definition | ||
* Factory and command design pattern | ||
* | ||
* To compile: | ||
* $ g++ .\OperationFactory.hpp | ||
* | ||
* \author Xuhua Huang | ||
* \date November 2022 | ||
*********************************************************************/ | ||
|
||
#ifndef OPERATIONFACTORY_HPP | ||
#define OPERATIONFACTORY_HPP | ||
|
||
#ifndef _IOSTREAM_ | ||
#include <iostream> | ||
#endif | ||
|
||
#ifndef _FUNCTIONAL_ | ||
#include <functional> | ||
#endif | ||
|
||
enum class Op { ADD, MUL }; | ||
|
||
std::function<int(int, int)> OperationFactory(Op op) { | ||
switch(op) { | ||
case Op::ADD: | ||
return [](int a, int b) { return a + b; }; | ||
case Op::MUL: | ||
return std::multiplies<int>(); | ||
} | ||
} | ||
|
||
#endif |
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 @@ | ||
/*****************************************************************//** | ||
* \file generic_add.cpp | ||
* \brief | ||
* | ||
* \author Xuhua Huang | ||
* \date November 2022 | ||
*********************************************************************/ | ||
|
||
#include <iostream> | ||
#include <stdlib.h> | ||
|
||
/** | ||
* Lambda is an anonymous struct with the overloaded operator(). | ||
* Consider the following example | ||
*/ | ||
struct _anonymous_struct_add { | ||
template<typename T, typename U> | ||
constexpr auto operator() (T a, U b) const { return a + b; } | ||
// use it like this: constexpt const _anonymous_struct_add add = _anonymous_struct_add{}; | ||
}; | ||
|
||
auto main(void) -> int { | ||
constexpr auto add = []<typename T>(T a, T b) -> T { | ||
return a + b; | ||
}; | ||
constexpr auto add5 = [add](auto x) -> auto { | ||
return add(x, 5); | ||
}; | ||
|
||
std::cout << add5(2) << "\n"; // 7 | ||
|
||
return EXIT_SUCCESS; | ||
} |
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
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
Oops, something went wrong.