Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
みんな代替トークン使とる。使てへんのお前だけ。 / alternative tokens
Search
Miutsuru kariya
January 29, 2020
Programming
2.1k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
みんな代替トークン使とる。使てへんのお前だけ。 / alternative tokens
C++MIX #7 の発表資料です。
Miutsuru kariya
January 29, 2020
More Decks by Miutsuru kariya
See All by Miutsuru kariya
みんな大好き!using ディレクティブ! / using directive
kariyamitsuru
1
1.6k
C++17の新機能 落穂拾い / new features of C++17 - gleaner
kariyamitsuru
0
1.5k
C++17の新機能 optional編 / new features of C++17 - optional
kariyamitsuru
1
3.1k
C++17の新機能 アロケータ編 / new features of C++17 - allocator
kariyamitsuru
0
4k
C++17の新機能 連想コンテナ編 / new features of C++17 - associative containers
kariyamitsuru
1
1.2k
C++17の新機能 言語編 / new features of C++17 - language
kariyamitsuru
0
490
C++14 の新機能 ライブラリ編 / new features of C++14 - Library
kariyamitsuru
0
790
Other Decks in Programming
See All in Programming
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
100
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
130
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
180
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
200
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
460
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
250
Heart of Swift Concurrency
koher
0
630
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
190
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
App Intentsのビルドプロセスを支える技術
kntkymt
0
360
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
0
270
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
710
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
490
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
650
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
A Soul's Torment
seathinner
7
3.6k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
The Cult of Friendly URLs
andyhume
79
7k
Transcript
みんな代替トークン使とる。 使てへんのお前だけ。 2020/1/29 鳥頭かりやマン 1
初心者向けネタ発表です。 「そんなんみんな知っとるが」など、その 筋の方からのツッコミは無しの方向でお 願いします… 2
代替トークンとは? 3
代替トークンとは? 「代替」の「トークン」 まんま… なお、よく「ダイグラフ」と 呼ばれたりもするが… 4
代替トークンとは? 代替 本来 代替 本来 代替 本来 <% { and
&& xor ^ %> } bitand & xor_eq ^= <: [ and_eq &= not ! :> ] or || not_eq != %: # bitor | compl ~ %:%: ## or_eq |= 5 見ての通り、必ずしも「ダイ」(2文字)ではなく、 キーワード型の物も結構ある。 これらの名前も予約語なので、例えば and や or と言った関数名や変数名は使えない。 ダ イ グ ラ フ で は な い 。 代 替 ト ー ク ン と 呼 べ 。
代替トークンとは? 代替 本来 代替 本来 代替 本来 <% { and
&& xor ^ %> } bitand & xor_eq ^= <: [ and_eq &= not ! :> ] or || not_eq != %: # bitor | compl ~ %:%: ## or_eq |= 6 なお、「トークン」と名前がついている通り、コンパイラが ソースをトークン化する際に処理されるので、文字列中 や他の識別子中では代替トークンとはみなされない。 まぁ当たり前っちゃあ当たり前なんだけど…
使用例 7
使用例 使用前 #include <iostream> int main() { int a[] =
{ 114, 514, }; for (int i = 0; i < 2; ++i) { std::cout << a[i] << ", "; } std::cout << '\n'; } 8
使用例 使用後 %:include <iostream> int main() <% int a<::> =
<% 114, 514, %>; for (int i = 0; i < 2; ++i) <% std::cout << a<:i:> << ", "; %> std::cout << '\n'; %> 9
使用例 使用後 %:include <iostream> int main() <% int a<::> =
<% 114, 514, %>; for (int i = 0; i < 2; ++i) <% std::cout << a<:i:> << ", "; %> std::cout << '\n'; %> 10 読みやすい! (異論は認める)
使用例 …これ、使う気がしない… 11
使用例 …これ、使う気がしない… と思いましたね? 12
使用例 使用前 template <class InputIterator, class Predicate> bool all_of(InputIterator first,
InputIterator last, Predicate pred) { for (; first != last; ++first) if (!pred(*first)) return false; return true; } 13 否定演算子が 見づらい!
使用例 使用後 template <class InputIterator, class Predicate> bool all_of(InputIterator first,
InputIterator last, Predicate pred) { for (; first != last; ++first) if (not pred(*first)) return false; return true; } 14 否定演算子が 見やすい! (異論は認めない)
使用例 どうですか? 使いたくなってきませんか? 15
ビット反転演算子が 見づらい! 使用例 使用前 const result_type Yp = (x[i] &
~mask) | (x[j] & mask); const size_t k = (i + m) % n; x[i] = x[k] ^ rshift<1>(Yp) ^ (a * (Yp & 1)); result_type z = x[i] ^ (rshift<u>(x[i]) & d); i = j; z ^= lshift<s>(z) & b; z ^= lshift<t>(z) & c; return z ^ rshift<l>(z); 16
ビット反転演算子が 見やすい! (異論は認める) 使用例 使用後 const result_type Yp = (x[i]
& compl mask) | (x[j] & mask); const size_t k = (i + m) % n; x[i] = x[k] ^ rshift<1>(Yp) ^ (a * (Yp & 1)); result_type z = x[i] ^ (rshift<u>(x[i]) & d); i = j; z ^= lshift<s>(z) & b; z ^= lshift<t>(z) & c; return z ^ rshift<l>(z); 17
使用例 使用後(過激派) const result_type Yp = (x<:i:> bitand compl mask)
bitor (x<:j:> bitand mask); const size_t k = (i + m) % n; X<:i:> = x<:k:> xor rshift<1>(Yp) xor (a * (Yp bitand 1)); result_type z = x<:i:> xor (rshift<u>(x<:i:>) bitand d); i = j; z xor_eq lshift<s>(z) bitand b; z xor_eq lshift<t>(z) bitand c; return z xor rshift<l>(z); 18
何もかもが 見やすい! (異論は認める) 使用例 使用後(過激派) const result_type Yp = (x<:i:>
bitand compl mask) bitor (x<:j:> bitand mask); const size_t k = (i + m) % n; X<:i:> = x<:k:> xor rshift<1>(Yp) xor (a * (Yp bitand 1)); result_type z = x<:i:> xor (rshift<u>(x<:i:>) bitand d); i = j; z xor_eq lshift<s>(z) bitand b; z xor_eq lshift<t>(z) bitand c; return z xor rshift<l>(z); 19
使用例 使用前 template <class InputIterator1, class InputIterator2, class BinaryPredicate> pair<InputIterator1,
InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred) { for (; first1 != last1 && first2 != last2; ++first1, ++first2) if (!pred(*first1, *first2)) break; return pair<InputIterator1, InputIterator2>(first1, first2); } 20
使用例 使用後 template <class InputIterator1, class InputIterator2, class BinaryPredicate> pair<InputIterator1,
InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred) { for (; first1 != last1 and first2 != last2; ++first1, ++first2) if (not pred(*first1, *first2)) break; return pair<InputIterator1, InputIterator2>(first1, first2); } 21
使用例 ところで皆さん、 代替トークンの字面に 惑わされてはいませんか? 22
使用例 使用前 struct S { S() = default; S(const S&)
= default; S(S&&) = default; ~S() = default; }; 23 まっ、まさか…
使用例 使用後 struct S <% S() = default; S(const S
bitand) = default; S(S and) = default; compl S() = default; %>; 24 まっ、まさか… そのまさかだ、フハ ハハハハハハハ!
使用例 使用後 struct S <% S() = default; S(const S
bitand) = default; S(S and) = default; compl S() = default; %>; 25 まっ、まさか… そのまさかだ、フハ ハハハハハハハ! スゴい! 参照もデストラクタも 見やすい!
まっ、まさか… そのまさかだ、フハ ハハハハハハハ! 使用例 使用後 struct S <% S() =
default; S(const S bitand) = default; S(S and) = default; compl S() = default; %>; 26 スゴい! 参照もデストラクタも 見やすい! ダメ!ゼッタイ!
結論 27
結論 代替トークン普及の会からのお知らせ みんな積極的に 代替トークンを使おう! せめて忘れないであげてください!!! 28
蛇足① ちなみに、C++17で廃止されてしまったトライグラフは、トー クン化どころかプリプロセス前に処理されていたので、文字 列内とかでも問答無用で変換対象になっていた。 29 代替 本来 代替 本来 代替
本来 ??= # ??( [ ??< { ??/ \ ??) ] ??> } ??’ ^ ??! | ??- ~
蛇足① 使用前(再掲) #include <iostream> int main() { int a[] =
{ 114, 514, }; for (int i = 0; i < 2; ++i) { std::cout << a[i] << ", "; } std::cout << '\n'; } 30
蛇足① 使用後(トライグラフ) ??=include <iostream> int main() ??< int a??(??) =
??< 114, 514, ??>; for (int i = 0; i < 2; ++i) ??< std::cout << a??(i??) << ", "; ??> std::cout << '\n'; ??> 31
蛇足① 使用後(トライグラフ) ??=include <iostream> int main() ??< int a??(??) =
??< 114, 514, ??>; for (int i = 0; i < 2; ++i) ??< std::cout << a??(i??) << ", "; ??> std::cout << '\n'; ??> 実際某青いI社のメインフレームで見たときは正直キモかった…(個人の感想です) 32 読みづらい! (異論は認める)
蛇足➁ C++のトークン化は、通常最長のトークンを切り出すことに なっている。 例) external ⇒ “extern”と“al”と言う2つのトークンではなく、 “external”と言う単一のトークン a+++++b ⇒
“a” “++” “+” “++” “b” ではなく、“a” “++” “++” “+” “b” と言うトークン列 33
蛇足➁ しかし、代替トークンに関連した以下のような例外がある。 “<::”の後ろに続く文字が“>”でも“:”でもなかった場合、 “<”と“::”と言う2つのトークンになる。 “<:” ⇒ “{” “<::” ⇒ “<”
と “::” “<::>” ⇒ “{” と “}” “<:::” ⇒ “{” と “::” まぁ普通この規則に引っかかることはおそらく一生のうち1度も無いとは思う… 34
蛇足➂ C言語では、キーワード型の代替トークンは言語仕様ではな く、ヘッダで提供されている。 35 代替 本来 代替 本来 代替 本来
<% { and && xor ^ %> } bitand & xor_eq ^= <: [ and_eq &= not ! :> ] or || not_eq != %: # bitor | compl ~ %:%: ## or_eq |= 言語仕様で提供 ヘッダiso646.hで提供
みんな代替トークン使とる。 使てへんのお前だけ。 36 完 終 制作・著作 ━━━━━ ⓃⒽⓀ