Skip to content

Commit 35b0dea

Browse files
committed
addscienum
1 parent 341a012 commit 35b0dea

File tree

9 files changed

+124
-5
lines changed

9 files changed

+124
-5
lines changed

15/03/b2.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <cstdio>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
int main() {
7+
string s1 = "hello";
8+
string s2 = "world";
9+
string s3 = s1 + s2;
10+
printf("%s\n", s3.c_str());
11+
}

15/04/a.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include <string>
22
#include <iostream>
3+
#include <sstream>
4+
#include <iomanip>
35

46
using namespace std;
57

68
int main() {
7-
int n = 42;
8-
auto s = to_string(n) + " yuan"s;
9-
cout << s << endl;
9+
//string s = (stringstream() << setprecision(100) << 3.1415f).str();
10+
//stringstream("3.1415926535") >> f;
11+
int n = 10011;
12+
cout << setprecision(4) << (n * 0.01) << endl;
1013
}

15/06/f3.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ vector<string> split(string s) {
2020
}
2121

2222
int main() {
23-
string s = "hello world pyb teacher good job"s;
23+
string s = "hello world\tpyb teacher\ngood job"s;
2424
vector<string> v = split(s);
2525
for (auto const &vi: v) {
2626
cout << vi << endl;
2727
}
28+
cout << sizeof(string) << endl;
2829
}

15/09/c.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <string>
2+
#include <string_view>
3+
#include <stdexcept>
4+
#include <iostream>
5+
#include <iomanip>
6+
#include <locale>
7+
8+
using namespace std;
9+
10+
11+
int main() {
12+
string s = "你好";
13+
wstring ws = L"你好";
14+
cout << s.size() << endl;
15+
cout << ws.size() << endl;
16+
}

15/slides.pptx

219 Bytes
Binary file not shown.

16/slides.pptx

1.22 MB
Binary file not shown.

specmacro/a.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
#include <string>
3+
#include "scienum.h"
4+
5+
enum Color {
6+
RED = 1, GREEN = 2, BLUE = 3, YELLOW = 4,
7+
};
8+
9+
int main() {
10+
std::cout << scienum::get_enum_name(YELLOW) << std::endl;
11+
std::cout << scienum::enum_from_name<Color>("YELLOW") << std::endl;
12+
}

specmacro/scienum.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace scienum {
6+
7+
namespace details {
8+
9+
template <class T, T N>
10+
const char *get_enum_name_static() {
11+
#if defined(_MSC_VER)
12+
return __FUNCSIG__;
13+
#else
14+
return __PRETTY_FUNCTION__;
15+
#endif
16+
}
17+
18+
template <bool Cond>
19+
struct my_enable_if {
20+
};
21+
22+
template <>
23+
struct my_enable_if<true> {
24+
typedef int type;
25+
};
26+
27+
template <int Beg, int End, class F, typename my_enable_if<Beg == End>::type = 0>
28+
void static_for(F const &func) {
29+
}
30+
31+
template <int Beg, int End, class F, typename my_enable_if<Beg != End>::type = 0>
32+
void static_for(F const &func) {
33+
struct int_constant {
34+
enum { value = Beg };
35+
};
36+
func(int_constant());
37+
static_for<Beg + 1, End>(func);
38+
}
39+
40+
}
41+
42+
template <int Beg = 0, int End = 256, class T>
43+
std::string get_enum_name(T n) {
44+
std::string s;
45+
details::static_for<Beg, End + 1>([&] (auto i) {
46+
if (n == (T)i.value) s = details::get_enum_name_static<T, (T)i.value>();
47+
});
48+
if (s.empty())
49+
return std::to_string((int)n);
50+
#if defined(_MSC_VER)
51+
auto pos = s.find(',');
52+
pos += 1;
53+
auto pos2 = s.find('>', pos);
54+
#else
55+
auto pos = s.find("N = ");
56+
pos += 4;
57+
auto pos2 = s.find_first_of(";]", pos);
58+
#endif
59+
s = s.substr(pos, pos2 - pos);
60+
auto pos3 = s.find("::");
61+
if (pos3 != s.npos)
62+
s = s.substr(pos3 + 2);
63+
return s;
64+
}
65+
66+
template <class T, int Beg = 0, int End = 256>
67+
T enum_from_name(std::string const &s) {
68+
for (int i = Beg; i < End; i++) {
69+
if (s == get_enum_name((T)i)) {
70+
return (T)i;
71+
}
72+
}
73+
throw;
74+
}
75+
76+
}

tools/concat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ for x in $*; do
55
ffmpeg -i $x -vcodec copy -acodec copy -vbsf h264_mp4toannexb /tmp/t_$x.ts
66
done
77
cat /tmp/t_*.ts > /tmp/a_a.ts
8-
ffmpeg -i /tmp/a_a.ts -acodec copy -vcodec copy -absf aac_adtstoasc /tmp/out.mp4
8+
ffmpeg -y -i /tmp/a_a.ts -acodec copy -vcodec copy -absf aac_adtstoasc /tmp/out.mp4
99
rm -f /tmp/a_a.ts /tmp/t_*.ts

0 commit comments

Comments
 (0)