Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MeetingC++ Quiz
Search
James
November 23, 2016
Programming
3.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
MeetingC++ Quiz
James
November 23, 2016
More Decks by James
See All by James
Conan C/C++ package manager
memsharded
1
1k
Other Decks in Programming
See All in Programming
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.8k
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
さぁV100、メモリをお食べ・・・
nilpe
0
150
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
220
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
7.8k
AIで効率化できた業務・日常
ochtum
0
140
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
390
Performance Engineering for Everyone
elenatanasoiu
0
210
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
190
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
12
6.4k
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Into the Great Unknown - MozCon
thekraken
41
2.6k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
210
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Building Applications with DynamoDB
mza
96
7.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Practical Orchestrator
shlominoach
191
11k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
180
My Coaching Mixtape
mlcsv
0
150
Mind Mapping
helmedeiros
PRO
1
260
Transcript
1 template <typename T> void P(const T & x) {
std::cout << x; } void foo(const void*) { P("v"); } void foo(const std::string&) { P("s"); } int main() { unsigned int i; for (i = 3; i>0; i--) P(i); for (; i<4; i++) P(i); if (i > -1) P("z"); foo("Conan!"); }
2 template <typename T> void P(const T & x) {
std::cout << x; } // wish VS accepted auto, sigh void foo(const std::string& str, std::function<void(char)> mylambda) { for (auto ch : str) mylambda(ch); } int main() { int num = 1; std::string str("ab"); foo(str, [&](char ch) {P(num++); P(ch);}); foo(str, [=](char ch) mutable {P(num++); P(ch);}); P(num); }
3 template <typename T> void P(const T & x) {
std::cout << x; } template <typename T> void P(int t, const T & x) { std::cout << t << x; } template<typename T, typename ...Args> void P(T t, Args ...args) { P(args...); P(t); } int main() { P(1, "dog", 2, "cat"); }
4 template <typename T> void P(const T & x) {
std::cout << x; } class Foo { public: Foo(int _a) : a(_a) { P(a++); } Foo(Foo& c) : a(c.a) { P(a++); } Foo(Foo&& c) : a(c.a) { P(a++);c.a = 9; } void bar() { P(a); } private: int a; }; int main() { Foo a(1); Foo b(a); Foo c(std::move(b)); Foo d = static_cast<Foo&&>(c); a.bar(); b.bar(); c.bar(); d.bar(); }
5 template <typename T> void P(const T & x) {std::cout
<< x;} int main() { std::vector<int> v{ 1, 2, 3, 4 }; std::iota(v.begin(), v.end(), 2); v.emplace_back(std::accumulate(v.begin(), v.end(), 1)); std::partial_sum(v.begin(), v.end(), v.begin()); for (auto value : v) P(value); }
6 template <typename T> void P(const T & x) {std::cout
<< x;} template <typename T> struct Foo { Foo(T _a, T _b) : a(_a), b(_b) { P(a++); P(b++); } ~Foo() { P(b); P(a); } T a; T b; }; int main() { auto foo2 = std::make_shared<Foo<int>>(1, 2); auto foo1 = std::make_unique<Foo<int>>(5, 6); auto foo3 = std::move(foo1); auto foo4 = std::move(foo2); P(foo3->a); P(foo4->b); }
7 struct Barrier { std::mutex _mutex; std::condition_variable _cv; std::size_t _count;
explicit Barrier(std::size_t count):_count{ count } { } void wait() { std::cout << "1" << std::flush; std::unique_lock<std::mutex> lock{ _mutex }; if (--_count == 0) _cv.notify_all(); else _cv.wait(lock, [this] { return _count == 0; }); std::cout << "2" << std::flush; } }; int main() { Barrier b(4); std::vector<std::thread> v; for (int i = 0;i<3;i++) v.push_back(std::thread([&]() {b.wait();})); std::cout << "z" << std::flush; v.push_back(std::thread([&]() {b.wait();})); for (auto& t : v) t.join(); }
8 #define DECLARE_FOO(class_name)\ struct class_name{ T t1; T t2; \
class_name(T v1, T v2): t1(v1), t2(v2) {} #define DECLARE_BAR(bar, r) void bar(){std::cout<<r;} template <typename T> DECLARE_FOO(Foo) DECLARE_BAR(bar, t1) DECLARE_BAR(baz, t2) }; int main() { std::random_device r; std::default_random_engine e1(r()); std::uniform_int_distribution<int> uniform_dist(1, 50); std::map<int, int> hist; for (int n = 0; n < 50; ++n) hist[uniform_dist(e1)]++; auto a = std::accumulate(std::begin(hist), std::end(hist), 0, [](auto a, auto b) {return a + b.second;}); Foo<int> f(a, a + 1); f.bar(); f.baz(); }
9 struct Foo { int foo; Foo(int foo) : foo(foo)
{} Foo(char foo) : foo(foo + 1) {} Foo(std::string foo) : foo(42) {} Foo() : Foo(0) {} Foo(float foo) : Foo("conan!") {} }; template <typename T> void P(const std::array<T, 3>& list) { for (auto& e : list) std::cout << e.foo + 1; } template <typename T> void P(const std::initializer_list<T>& list) { for (auto& e : list) std::cout << e.foo; } int main() { auto foos = { Foo(1), Foo((char)2), Foo("MeetingC++") }; auto t = std::make_tuple(Foo(), Foo(3.5f)); P(foos); P({ std::get<0>(t), std::get<1>(t) }); }
constexpr auto foo = 1 + 2 / 3 +
1.0; constexpr auto bar(float foo) { return foo * 2 - 3 / 2; } constexpr auto baz = bar(foo - 2); int main() { std::string s; baz > foo ? s += "cat" : s += "pum"; if (sizeof(int) == 4) s += " de"; s += "orc"; for (int i = 0;i<327964;i++) std::random_shuffle(s.begin(), s.end()); std::cout << s; } 10
ANSWERS
1 template <typename T> void P(const T & x) {
std::cout << x; } void foo(const void*) { P("v"); } void foo(const std::string&) { P("s"); } int main() { unsigned int i; for (i = 3; i>0; i--) P(i); for (; i<4; i++) P(i); if (i > -1) P("z"); foo("Conan!"); } 3210123v
2 template <typename T> void P(const T & x) {
std::cout << x; } // wish VS accepted auto, sigh void foo(const std::string& str, std::function<void(char)> mylambda) { for (auto ch : str) mylambda(ch); } int main() { int num = 1; std::string str("ab"); foo(str, [&](char ch) {P(num++); P(ch);}); foo(str, [=](char ch) mutable {P(num++); P(ch);}); P(num); } 1a2b3a4b3
3 template <typename T> void P(const T & x) {
std::cout << x; } template <typename T> void P(int t, const T & x) { std::cout << t << x; } template<typename T, typename ...Args> void P(T t, Args ...args) { P(args...); P(t); } int main() { P(1, "dog", 2, "cat"); } 2catdog1
4 template <typename T> void P(const T & x) {
std::cout << x; } class Foo { public: Foo(int _a) : a(_a) { P(a++); } Foo(Foo& c) : a(c.a) { P(a++); } Foo(Foo&& c) : a(c.a) { P(a++);c.a = 9; } void bar() { P(a); } private: int a; }; int main() { Foo a(1); Foo b(a); Foo c(std::move(b)); Foo d = static_cast<Foo&&>(c); a.bar(); b.bar(); c.bar(); d.bar(); } 12342995
5 template <typename T> void P(const T & x) {std::cout
<< x;} int main() { std::vector<int> v{ 1, 2, 3, 4 }; std::iota(v.begin(), v.end(), 2); v.emplace_back(std::accumulate(v.begin(), v.end(), 1)); std::partial_sum(v.begin(), v.end(), v.begin()); for (auto value : v) P(value); } 2591429
6 template <typename T> void P(const T & x) {std::cout
<< x;} template <typename T> struct Foo { Foo(T _a, T _b) : a(_a), b(_b) { P(a++); P(b++); } ~Foo() { P(b); P(a); } T a; T b; }; int main() { auto foo2 = std::make_shared<Foo<int>>(1, 2); auto foo1 = std::make_unique<Foo<int>>(5, 6); auto foo3 = std::move(foo1); auto foo4 = std::move(foo2); P(foo3->a); P(foo4->b); } 1256633276
7 struct Barrier { std::mutex _mutex; std::condition_variable _cv; std::size_t _count;
explicit Barrier(std::size_t count):_count{ count } { } void wait() { std::cout << "1" << std::flush; std::unique_lock<std::mutex> lock{ _mutex }; if (--_count == 0) _cv.notify_all(); else _cv.wait(lock, [this] { return _count == 0; }); std::cout << "2" << std::flush; } }; int main() { Barrier b(4); std::vector<std::thread> v; for (int i = 0;i<3;i++) v.push_back(std::thread([&]() {b.wait();})); std::cout << "z" << std::flush; v.push_back(std::thread([&]() {b.wait();})); for (auto& t : v) t.join(); } 111z12222
8 #define DECLARE_FOO(class_name)\ struct class_name{ T t1; T t2; \
class_name(T v1, T v2): t1(v1), t2(v2) {} #define DECLARE_BAR(bar, r) void bar(){std::cout<<r;} template <typename T> DECLARE_FOO(Foo) DECLARE_BAR(bar, t1) DECLARE_BAR(baz, t2) }; int main() { std::random_device r; std::default_random_engine e1(r()); std::uniform_int_distribution<int> uniform_dist(1, 50); std::map<int, int> hist; for (int n = 0; n < 50; ++n) hist[uniform_dist(e1)]++; auto a = std::accumulate(std::begin(hist), std::end(hist), 0, [](auto a, auto b) {return a + b.second;}); Foo<int> f(a, a + 1); f.bar(); f.baz(); } 5051
9 struct Foo { int foo; Foo(int foo) : foo(foo)
{} Foo(char foo) : foo(foo + 1) {} Foo(std::string foo) : foo(42) {} Foo() : Foo(0) {} Foo(float foo) : Foo("conan!") {} }; template <typename T> void P(const std::array<T, 3>& list) { for (auto& e : list) std::cout << e.foo + 1; } template <typename T> void P(const std::initializer_list<T>& list) { for (auto& e : list) std::cout << e.foo; } int main() { auto foos = { Foo(1), Foo((char)2), Foo("MeetingC++") }; auto t = std::make_tuple(Foo(), Foo(3.5f)); P(foos); P({ std::get<0>(t), std::get<1>(t) }); } 1342042
constexpr auto foo = 1 + 2 / 3 +
1.0; constexpr auto bar(float foo) { return foo * 2 - 3 / 2; } constexpr auto baz = bar(foo - 2); int main() { std::string s; baz > foo ? s += "cat" : s += "pum"; if (sizeof(int) == 4) s += " de"; s += "orc"; for (int i = 0;i<327964;i++) std::random_shuffle(s.begin(), s.end()); std::cout << s; } 10 core dump