-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
11 changed files
with
182 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/build | ||
/.*/ | ||
.*/ | ||
!/.github/ |
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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
#include <cassert> | ||
#include <iostream> | ||
|
||
// NOTE: 这是函数声明 | ||
int add(int, int); | ||
|
||
int main(int argc, char **argv) { | ||
assert(add(123, 456) == 123 + 456); | ||
|
||
auto x = 1, y = 2; | ||
std::cout << x << " + " << y << " = " << add(x, y) << std::endl; | ||
return 0; | ||
} | ||
|
||
// TODO: 补全函数定义 | ||
int add(int a, int b) { | ||
// THINK: `static` 修饰函数有什么效果? | ||
static int add(int a, int b) { | ||
return a + b; | ||
} |
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,94 @@ | ||
add_rules("mode.debug", "mode.release") | ||
set_encodings("utf-8") | ||
|
||
target("exercise00") | ||
set_kind("binary") | ||
add_files("00_hello_world/main.cpp") | ||
|
||
target("exercise01") | ||
set_kind("binary") | ||
add_files("01_variable&add/main.cpp") | ||
|
||
target("exercise02") | ||
set_kind("binary") | ||
add_files("02_function/main.cpp") | ||
|
||
target("exercise03") | ||
set_kind("binary") | ||
add_files("03_argument¶meter/main.cpp") | ||
|
||
target("exercise04") | ||
set_kind("binary") | ||
add_files("04_static/main.cpp") | ||
|
||
target("exercise05") | ||
set_kind("binary") | ||
add_files("05_constexpr/main.cpp") | ||
|
||
target("exercise06") | ||
set_kind("binary") | ||
add_files("06_loop/main.cpp") | ||
|
||
target("exercise07") | ||
set_kind("binary") | ||
add_files("07_struct/main.cpp") | ||
|
||
target("exercise08") | ||
set_kind("binary") | ||
add_files("08_class/main.cpp") | ||
|
||
target("exercise09") | ||
set_kind("binary") | ||
add_files("09_class_method_const/main.cpp") | ||
|
||
target("exercise10") | ||
set_kind("binary") | ||
add_files("10_class_drop/main.cpp") | ||
|
||
target("exercise11") | ||
set_kind("binary") | ||
add_files("11_class_clone/main.cpp") | ||
|
||
target("exercise12") | ||
set_kind("binary") | ||
add_files("12_class_move/main.cpp") | ||
|
||
target("exercise13") | ||
set_kind("binary") | ||
add_files("13_std_array/main.cpp") | ||
|
||
target("exercise14") | ||
set_kind("binary") | ||
add_files("14_std_vector/main.cpp") | ||
|
||
target("exercise15") | ||
set_kind("binary") | ||
add_files("15_std_deque/main.cpp") | ||
|
||
target("exercise16") | ||
set_kind("binary") | ||
add_files("16_std_map/main.cpp") | ||
|
||
target("exercise17") | ||
set_kind("binary") | ||
add_files("17_std_accumulate/main.cpp") | ||
|
||
target("exercise18") | ||
set_kind("binary") | ||
add_files("18_std_transform/main.cpp") | ||
|
||
target("exercise19") | ||
set_kind("binary") | ||
add_files("19_std_fs/main.cpp") | ||
|
||
target("exercise20") | ||
set_kind("binary") | ||
add_files("20_std_thread/main.cpp") | ||
|
||
target("exercise21") | ||
set_kind("binary") | ||
add_files("21_std_mutex/main.cpp") | ||
|
||
target("exercise22") | ||
set_kind("binary") | ||
add_files("22_template/main.cpp") |
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,55 @@ | ||
#include <cstdlib> | ||
#include <filesystem> | ||
#include <iostream> | ||
#include <string> | ||
|
||
#ifndef __XMAKE__ | ||
#define __XMAKE__ "XMAKE is not defined" | ||
#endif | ||
|
||
namespace fs = std::filesystem; | ||
constexpr static auto XMAKE = __XMAKE__; | ||
|
||
int process_run(const char *cmd, const char *proj) { | ||
static auto exercises = fs::absolute(fs::path(XMAKE) / "exercises"); | ||
auto prefix = std::string("xmake ") + cmd + " -P " + exercises.string() + ' ' + proj; | ||
return std::system(prefix.c_str()); | ||
} | ||
|
||
bool test_exercise(int n) { | ||
char str[] = "exerciseXX"; | ||
std::sprintf(str, "exercise%02d", n); | ||
return process_run("", str) == 0 && process_run("run", str) == 0; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
switch (argc) { | ||
case 2: { | ||
int num; | ||
if (1 != std::sscanf(argv[1], "%d", &num)) { | ||
std::cerr << "Invalid exercise number: " << argv[1] << std::endl; | ||
return 1; | ||
}; | ||
if (!test_exercise(num)) { | ||
return 1; | ||
} | ||
break; | ||
} | ||
case 1: { | ||
constexpr auto MAX_EXERCISE = 22; | ||
auto success = 0; | ||
for (auto i = 0; i <= MAX_EXERCISE; ++i) { | ||
if (test_exercise(i)) { | ||
++success; | ||
} | ||
} | ||
std::cout << success << "/" << MAX_EXERCISE + 1 << std::endl; | ||
break; | ||
} | ||
default: | ||
std::cerr << "Usage: xmake run learn <exercice number>" << std::endl; | ||
return 1; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,10 @@ | ||
add_rules("mode.debug", "mode.release") | ||
set_encodings("utf-8") | ||
|
||
target("exercise00") | ||
target("learn") | ||
set_kind("binary") | ||
add_files("exercises/00_hello_world/main.cpp") | ||
|
||
target("exercise01") | ||
set_kind("binary") | ||
add_files("exercises/01_variable&add/main.cpp") | ||
|
||
target("exercise02") | ||
set_kind("binary") | ||
add_files("exercises/02_function/main.cpp") | ||
|
||
target("exercise03") | ||
set_kind("binary") | ||
add_files("exercises/03_argument¶meter/main.cpp") | ||
|
||
target("exercise04") | ||
set_kind("binary") | ||
add_files("exercises/04_static/main.cpp") | ||
|
||
target("exercise05") | ||
set_kind("binary") | ||
add_files("exercises/05_constexpr/main.cpp") | ||
|
||
target("exercise06") | ||
set_kind("binary") | ||
add_files("exercises/06_loop/main.cpp") | ||
|
||
target("exercise07") | ||
set_kind("binary") | ||
add_files("exercises/07_struct/main.cpp") | ||
|
||
target("exercise08") | ||
set_kind("binary") | ||
add_files("exercises/08_class/main.cpp") | ||
|
||
target("exercise09") | ||
set_kind("binary") | ||
add_files("exercises/09_class_method_const/main.cpp") | ||
|
||
target("exercise10") | ||
set_kind("binary") | ||
add_files("exercises/10_class_drop/main.cpp") | ||
|
||
target("exercise11") | ||
set_kind("binary") | ||
add_files("exercises/11_class_copy/main.cpp") | ||
add_defines(string.format("__XMAKE__=\"%s\"", os.scriptdir():gsub("\\", "/"))) | ||
|
||
target("exercise12") | ||
set_kind("binary") | ||
add_files("exercises/12_class_move/main.cpp") | ||
|
||
target("exercise13") | ||
set_kind("binary") | ||
add_files("exercises/13_std_move/main.cpp") | ||
|
||
target("exercise14") | ||
set_kind("binary") | ||
add_files("exercises/14_std_vector/main.cpp") | ||
|
||
target("exercise15") | ||
set_kind("binary") | ||
add_files("exercises/15_std_deque/main.cpp") | ||
|
||
target("exercise16") | ||
set_kind("binary") | ||
add_files("exercises/16_std_map/main.cpp") | ||
|
||
target("exercise17") | ||
set_kind("binary") | ||
add_files("exercises/17_std_accumulate/main.cpp") | ||
|
||
target("exercise18") | ||
set_kind("binary") | ||
add_files("exercises/18_std_transform/main.cpp") | ||
|
||
target("exercise19") | ||
set_kind("binary") | ||
add_files("exercises/19_std_fs/main.cpp") | ||
|
||
target("exercise20") | ||
set_kind("binary") | ||
add_files("exercises/20_std_thread/main.cpp") | ||
|
||
target("exercise21") | ||
set_kind("binary") | ||
add_files("exercises/21_std_mutex/main.cpp") | ||
|
||
target("exercise22") | ||
set_kind("binary") | ||
add_files("exercises/22_template/main.cpp") | ||
set_languages("cxx17") | ||
add_files("learn/main.cpp") |