Skip to content

[pull] master from parallel101:master #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 15/03/b2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <cstdio>
#include <string>

using namespace std;

int main() {
string s1 = "hello";
string s2 = "world";
string s3 = s1 + s2;
printf("%s\n", s3.c_str());
}
9 changes: 6 additions & 3 deletions 15/04/a.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {
int n = 42;
auto s = to_string(n) + " yuan"s;
cout << s << endl;
//string s = (stringstream() << setprecision(100) << 3.1415f).str();
//stringstream("3.1415926535") >> f;
int n = 10011;
cout << setprecision(4) << (n * 0.01) << endl;
}
3 changes: 2 additions & 1 deletion 15/06/f3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ vector<string> split(string s) {
}

int main() {
string s = "hello world pyb teacher good job"s;
string s = "hello world\tpyb teacher\ngood job"s;
vector<string> v = split(s);
for (auto const &vi: v) {
cout << vi << endl;
}
cout << sizeof(string) << endl;
}
16 changes: 16 additions & 0 deletions 15/09/c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <string>
#include <string_view>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <locale>

using namespace std;


int main() {
string s = "你好";
wstring ws = L"你好";
cout << s.size() << endl;
cout << ws.size() << endl;
}
Binary file modified 15/slides.pptx
Binary file not shown.
Binary file added 16/slides.pptx
Binary file not shown.
12 changes: 12 additions & 0 deletions specmacro/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include <string>
#include "scienum.h"

enum Color {
RED, GREEN, BLUE, YELLOW,
};

int main() {
std::cout << scienum::get_enum_name(YELLOW) << std::endl;
std::cout << scienum::enum_from_name<Color>("YELLOW") << std::endl;
}
94 changes: 94 additions & 0 deletions specmacro/scienum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#pragma once

#include <string>

namespace scienum {

namespace details {

template <class T, T N>
const char *get_enum_name_static() {
#if defined(_MSC_VER)
return __FUNCSIG__;
#else
return __PRETTY_FUNCTION__;
#endif
}

template <bool Cond>
struct my_enable_if {
};

template <>
struct my_enable_if<true> {
typedef void type;
};

template <int Beg, int End, class F>
typename my_enable_if<Beg == End>::type static_for(F const &func) {
}

template <int Beg, int End, class F>
typename my_enable_if<Beg != End>::type static_for(F const &func) {
func.template call<Beg>();
static_for<Beg + 1, End>(func);
}

template <class T>
struct get_enum_name_functor {
int n;
std::string &s;

get_enum_name_functor(int n, std::string &s) : n(n), s(s) {}

template <int I>
void call() const {
if (n == I) s = details::get_enum_name_static<T, (T)I>();
}
};

}

template <class T, T Beg, T End>
std::string get_enum_name(T n) {
std::string s;
details::static_for<Beg, End + 1>(details::get_enum_name_functor<T>(n, s));
if (s.empty())
return "";
#if defined(_MSC_VER)
size_t pos = s.find(',');
pos += 1;
size_t pos2 = s.find('>', pos);
#else
size_t pos = s.find("N = ");
pos += 4;
size_t pos2 = s.find_first_of(";]", pos);
#endif
s = s.substr(pos, pos2 - pos);
size_t pos3 = s.find("::");
if (pos3 != s.npos)
s = s.substr(pos3 + 2);
return s;
}

template <class T>
std::string get_enum_name(T n) {
return get_enum_name<T, (T)0, (T)256>(n);
}

template <class T, T Beg, T End>
T enum_from_name(std::string const &s) {
for (int i = (int)Beg; i < (int)End; i++) {
if (s == get_enum_name((T)i)) {
return (T)i;
}
}
throw;
}

template <class T>
T enum_from_name(std::string const &s) {
return enum_from_name<T, (T)0, (T)256>(s);
}

}
2 changes: 1 addition & 1 deletion tools/concat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ for x in $*; do
ffmpeg -i $x -vcodec copy -acodec copy -vbsf h264_mp4toannexb /tmp/t_$x.ts
done
cat /tmp/t_*.ts > /tmp/a_a.ts
ffmpeg -i /tmp/a_a.ts -acodec copy -vcodec copy -absf aac_adtstoasc /tmp/out.mp4
ffmpeg -y -i /tmp/a_a.ts -acodec copy -vcodec copy -absf aac_adtstoasc /tmp/out.mp4
rm -f /tmp/a_a.ts /tmp/t_*.ts