Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
update codestyle & fix C++ ISO 17.6.4.3 Reserved names
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunrisepeak committed Apr 17, 2024
1 parent d2dcd88 commit 05a15db
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 118 deletions.
6 changes: 3 additions & 3 deletions common/common.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __COMMON_HPP__D2DS
#define __COMMON_HPP__D2DS
#ifndef COMMON_HPP_D2DS
#define COMMON_HPP_D2DS

#include <iostream>
#include <string>
Expand Down Expand Up @@ -34,7 +34,7 @@
namespace d2ds {

template <typename DSVType>
static void randomDataGenerator(DSVType &dsv, int rangeL, int rangeR) {
static void random_data_generator(DSVType &dsv, int rangeL, int rangeR) {
// test: random data
// Choose a random mean between 1 and 2 * ARR_SIZE
// https://en.cppreference.com/w/cpp/numeric/random
Expand Down
4 changes: 2 additions & 2 deletions common/dslings_config.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __DSLINGS_CONFIG_HPP__D2DS
#define __DSLINGS_CONFIG_HPP__D2DS
#ifndef DSLINGS_CONFIG_HPP_D2DS
#define DSLINGS_CONFIG_HPP_D2DS

/*
// checker config
Expand Down
4 changes: 2 additions & 2 deletions common/honly_logger.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __LOGGER_HPP__HONLY
#define __LOGGER_HPP__HONLY
#ifndef LOGGER_HPP__HONLY
#define LOGGER_HPP__HONLY

#include <cstdio>

Expand Down
4 changes: 2 additions & 2 deletions exercises/array/Array.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __ARRAY_HPP__D2DS
#define __ARRAY_HPP__D2DS
#ifndef ARRAY_HPP_D2DS
#define ARRAY_HPP_D2DS

namespace d2ds {
//using dstruct::Array;
Expand Down
15 changes: 7 additions & 8 deletions exercises/dslings.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
#ifndef __DSLINGS_HPP__D2DS
#define __DSLINGS_HPP__D2DS
#ifndef DSLINGS_HPP_D2DS
#define DSLINGS_HPP_D2DS

namespace d2ds {
// show your code




/*
class MaxValue {
public:
MaxValue(int val) {
__mMaxVal = val;
mMaxVal_e = val;
}
int get() {
return __mMaxVal;
return mMaxVal_e;
}
void set(int val) {
if (val > __mMaxVal) {
__mMaxVal = val;
if (val > mMaxVal_e) {
mMaxVal_e = val;
}
}
private:
int __mMaxVal;
int mMaxVal_e;
};
*/

Expand Down
4 changes: 2 additions & 2 deletions exercises/other/cpp-base/RangeFor.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __RANGE_BASE_FOR_HPP__D2DS
#define __RANGE_BASE_FOR_HPP__D2DS
#ifndef RANGE_BASE_FOR_HPP_D2DS
#define RANGE_BASE_FOR_HPP_D2DS

#include <common/common.hpp>

Expand Down
4 changes: 2 additions & 2 deletions exercises/other/cpp-base/Template.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __TEMPLATE_HPP__D2DS
#define __TEMPLATE_HPP__D2DS
#ifndef TEMPLATE_HPP_D2DS
#define TEMPLATE_HPP_D2DS

namespace d2ds {
// show your code
Expand Down
18 changes: 9 additions & 9 deletions src/Instroduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main() {

// random test
dstruct::Array<int, 10> data;
d2ds::randomDataGenerator(data, 0, 200);
d2ds::random_data_generator(data, 0, 200);
d2ds::ds_print(data);

int maxVal = 0;
Expand Down Expand Up @@ -146,7 +146,7 @@ MaxVal的应用测试 - 获取最大数组中最大值
```cpp
// random test
dstruct::Array<int, 10> data;
d2ds::randomDataGenerator(data, 0, 200);
d2ds::random_data_generator(data, 0, 200);
d2ds::ds_print(data);
int maxVal = 0;
Expand All @@ -170,10 +170,10 @@ MaxVal的应用测试 - 获取最大数组中最大值
```cpp
class MaxValue {
public:
MaxValue(int val) : __mMaxVal { val } { }
MaxValue(int val) : mMaxVal_e { val } { }

private:
int __mMaxVal;
int mMaxVal_e;
};
```
Expand All @@ -184,11 +184,11 @@ class MaxValue {
public:
//...
int get() {
return __mMaxVal;
return mMaxVal_e;
}
private:
int __mMaxVal;
int mMaxVal_e;
};
```

Expand All @@ -199,13 +199,13 @@ class MaxValue {
public:
//...
void set(int val) {
if (val > __mMaxVal) {
__mMaxVal = val;
if (val > mMaxVal_e) {
mMaxVal_e = val;
}
}

private:
int __mMaxVal;
int mMaxVal_e;
};
```
Expand Down
10 changes: 5 additions & 5 deletions src/other/1_cpp_base.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,22 @@ class Box {
template <typename T>
class Box {
public:
Box() : __mVal{} { }
Box() : mVal_e{} { }
T get_value() const {
return __mVal;
return mVal_e;
}
void set_value(const T &val) {
__mVal = val;
mVal_e = val;
}
private:
T __mVal;
T mVal_e;
};
```

在Box的实现中, 使用`T __mVal;`定义了一个存储用户指定类型值的成员变量。并且在`get_value``set_value`成员函数中也像使用正常的类型一样使用**类型名`T`**。它是一个未确定的类型的标识符, 在编译期编译器将会根据使用者指定的类型来去实例化出对应的版本, 就像上面函数模板一样。总之, 在编写模板代码的时候我们可以把`T`当成一个**未知类型名**, 像正常大多数类型名的用法一样来使用它。
在Box的实现中, 使用`T mVal_e;`定义了一个存储用户指定类型值的成员变量。并且在`get_value``set_value`成员函数中也像使用正常的类型一样使用**类型名`T`**。它是一个未确定的类型的标识符, 在编译期编译器将会根据使用者指定的类型来去实例化出对应的版本, 就像上面函数模板一样。总之, 在编写模板代码的时候我们可以把`T`当成一个**未知类型名**, 像正常大多数类型名的用法一样来使用它。

> 注:
>
Expand Down
Loading

0 comments on commit 05a15db

Please sign in to comment.