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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
3
410
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
590
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
業務時間外もAIに働いてもらう話
colorful12
3
10k
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
430
ALB ログから Trace を気合で繋げる技術
fohte
7
880
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
2
260
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
140
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
200
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
Webの地図
yosuke_furukawa
PRO
4
3.8k
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Building Adaptive Systems
keathley
44
3.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
380
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
930
Documentation Writing (for coders)
carmenintech
77
5.5k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Automating Front-end Workflow
addyosmani
1369
210k
What's in a price? How to price your products and services
michaelherold
247
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
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 完 終 制作・著作 ━━━━━ ⓃⒽⓀ