Skip to content

Commit ab5ae46

Browse files
author
zhuliting
committed
add sha
1 parent add9315 commit ab5ae46

File tree

108 files changed

+1300
-5340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1300
-5340
lines changed

cpp/11/a.out

8 Bytes
Binary file not shown.

cpp/Sort.cpp

+99-85
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,99 @@
1-
#include <iostream>
2-
#include <algorithm>
3-
#include <vector>
4-
#include <functional>
5-
using namespace std;
6-
7-
//for_each 的谓词,为了输出不同的对象, 这里利用了函数对象
8-
template<class T>
9-
class Display: public binary_function<T, T,bool>
10-
{
11-
public:
12-
void operator()(const T& a)
13-
{
14-
cout<<a<<endl;
15-
}
16-
};
17-
18-
19-
class A //待排序的类
20-
{
21-
public:
22-
A(int i): m_i(i){}
23-
int Get()const{return m_i;}
24-
friend ostream& operator<<(ostream& out, const A& a)
25-
{
26-
out<<a.Get();
27-
return out;
28-
}
29-
private:
30-
int m_i;
31-
};
32-
33-
//方法一,使用谓词, 升序排序
34-
bool LessThan(const A& a, const A& b)
35-
{
36-
37-
return a.Get() < b.Get();
38-
39-
}
40-
//方法二, 重载 <,升序排序
41-
inline bool operator< (const A& a, const A& b)
42-
{
43-
return a.Get() < b.Get();
44-
}
45-
46-
// 方法三, 重载>, 降序排序, 配合下面的Greater类
47-
inline bool operator> (const A& a, const A& b)
48-
{
49-
return a.Get() > b.Get();
50-
}
51-
52-
template<class T>
53-
class Greater: public binary_function<T, T,bool>
54-
{
55-
public:
56-
bool operator()(const T& a, const T& b)
57-
{
58-
return a > b;
59-
}
60-
};
61-
62-
int main()
63-
{
64-
vector<A> Avec;
65-
Avec.push_back(A(5));
66-
Avec.push_back(A(10));
67-
Avec.push_back(A(2));
68-
Avec.push_back(A(2));
69-
70-
/*
71-
sort(Avec.begin(), Avec.end(), LessThan);//谓词函数
72-
for_each(Avec.begin(), Avec.end(), Display<A>()); //升序排序
73-
cout << endl;
74-
75-
sort(Avec.begin(), Avec.end()); //默认升序排列类对象对象容器
76-
for_each(Avec.begin(), Avec.end(), Display<A>());//输出升序排列对象容器
77-
cout << endl;
78-
*/
79-
80-
sort(Avec.begin(), Avec.end(),Greater<A>());//降序排列对象
81-
for_each(Avec.begin(), Avec.end(), Display<A>());//输出降序排列对象容器
82-
cout << endl;
83-
84-
return 0;
85-
}
1+
#include <algorithm>
2+
#include <functional>
3+
#include <iostream>
4+
#include <vector>
5+
using namespace std;
6+
7+
//for_each 的谓词,为了输出不同的对象, 这里利用了函数对象
8+
template <class T>
9+
class Display : public binary_function<T, T, bool> {
10+
public:
11+
void operator()(const T& a) { cout << a << endl; }
12+
};
13+
14+
class A //待排序的类
15+
{
16+
public:
17+
A(int i) : m_i(i) {}
18+
int Get() const { return m_i; }
19+
friend ostream& operator<<(ostream& out, const A& a) {
20+
out << a.Get();
21+
return out;
22+
}
23+
24+
private:
25+
int m_i;
26+
};
27+
28+
//方法一,使用谓词, 升序排序
29+
bool LessThan(const A& a, const A& b) { return a.Get() < b.Get(); }
30+
//方法二, 重载 <,升序排序
31+
inline bool operator<(const A& a, const A& b) { return a.Get() < b.Get(); }
32+
33+
// 方法三, 重载>, 降序排序, 配合下面的Greater类
34+
inline bool operator>(const A& a, const A& b) { return a.Get() > b.Get(); }
35+
36+
template <class T>
37+
class Greater : public binary_function<T, T, bool> {
38+
public:
39+
bool operator()(const T& a, const T& b) { return a > b; }
40+
};
41+
42+
int main() {
43+
vector<A> Avec;
44+
Avec.push_back(A(5));
45+
Avec.push_back(A(10));
46+
Avec.push_back(A(2));
47+
Avec.push_back(A(2));
48+
49+
/*
50+
sort(Avec.begin(), Avec.end(), LessThan);//谓词函数
51+
for_each(Avec.begin(), Avec.end(), Display<A>()); //升序排序
52+
cout << endl;
53+
54+
sort(Avec.begin(), Avec.end()); //默认升序排列类对象对象容器
55+
for_each(Avec.begin(), Avec.end(), Display<A>());//输出升序排列对象容器
56+
cout << endl;
57+
*/
58+
59+
sort(Avec.begin(), Avec.end(), Greater<A>()); //降序排列对象
60+
for_each(Avec.begin(), Avec.end(), Display<A>()); //输出降序排列对象容器
61+
cout << endl;
62+
63+
vector<string> str_vec;
64+
str_vec.push_back(string("15055556666"));
65+
str_vec.push_back(string("2"));
66+
str_vec.push_back(string("success"));
67+
sort(str_vec.begin(), str_vec.end());
68+
cout << "-----" << endl;
69+
for (const auto& item : str_vec) cout << item << endl;
70+
71+
uint64_t n = (uint64_t(1) << 32);
72+
n /= 17;
73+
74+
n /= 60;
75+
n /= 60;
76+
77+
n /= 24;
78+
n /= 365;
79+
80+
cout << n << endl;
81+
82+
vector<int> vv = {0, 1, 2, 3, 4, 5, 6, 7, 8};
83+
int idx = 0;
84+
for_each(vv.begin(), vv.end(), [&](const int val)->void { ++idx; });
85+
cout << idx << endl;
86+
87+
vector<int>(10, 1).swap(vv);
88+
for (auto& item : vv)
89+
cout << item << endl;
90+
91+
struct data_transaction_commission_rate_t {
92+
// 10 percent is 1000
93+
uint16_t league_data_market_commission_rate = (10 );
94+
uint16_t free_data_market_commission_rate = (10 );
95+
};
96+
cout << data_transaction_commission_rate_t().league_data_market_commission_rate << endl;
97+
98+
return 0;
99+
}

cpp/a.out

-118 KB
Binary file not shown.

cpp/auto.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ using std::vector;
99
using std::cout;
1010
using std::endl;
1111

12-
struct object_id_type
13-
{
12+
struct object_id_type {
1413
object_id_type(int num, string desc) {
1514
number = num;
1615
description = desc;
@@ -67,27 +66,22 @@ struct CmpByType {
6766
}
6867
};
6968

70-
std::ostream& operator<<(std::ostream& os, const Object &obj) {
69+
std::ostream &operator<<(std::ostream &os, const Object &obj)
70+
{
7171
os << "{" << obj.id << "." + obj.name + ".";
7272
os << obj.type << "}";
7373
return os;
7474
}
7575

7676
typedef boost::function<bool(Object, Object)> Func;
77-
bool cmp_by_id(const Object &l, const Object &r)
78-
{
79-
return l.id < r.id;
80-
}
77+
bool cmp_by_id(const Object &l, const Object &r) { return l.id < r.id; }
8178

8279
bool cmp_by_name(const Object &l, const Object &r)
8380
{
8481
return l.name.compare(r.name) < 0 ? true : false;
8582
}
8683

87-
bool cmp_by_type(const Object &l, const Object &r)
88-
{
89-
return l.type < r.type;
90-
}
84+
bool cmp_by_type(const Object &l, const Object &r) { return l.type < r.type; }
9185

9286
int main()
9387
{

cpp/boost/a.out

-352 KB
Binary file not shown.

cpp/boost/variant.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main()
2525
{
2626
boost::variant<int, string, double, char> my_first_variant("hello world");
2727
cout << my_first_variant << endl;
28-
28+
2929
/*
3030
my_first_variant=24;
3131
my_first_variant=2.52;
@@ -37,7 +37,7 @@ int main()
3737
int* val = boost::get<int>(&my_first_variant);
3838
assert(val && (*val) == 0);
3939
*/
40-
40+
4141
print_visitor v;
4242
boost::apply_visitor(v, my_first_variant);
4343

0 commit comments

Comments
 (0)