teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

appendix

2018/10/30 01:29

投稿

yohhoy
yohhoy

スコア6191

answer CHANGED
@@ -26,4 +26,23 @@
26
26
 
27
27
  Demo: [https://wandbox.org/permlink/xIEdBjy2Jbkyuwpf](https://wandbox.org/permlink/xIEdBjy2Jbkyuwpf)
28
28
 
29
- (あまりに技巧的な記述では可読性・保守性を損ねますから、チームメンバのスキル次第なところはあるでしょうね)
29
+ (あまりに技巧的な記述では可読性・保守性を損ねますから、チームメンバのスキル次第なところはあるでしょうね)
30
+
31
+ ----
32
+
33
+ > ただ、普通の関数としてはダメ。
34
+
35
+ 結合優先度の都合で、明示的な括弧が必要ですね(`foo{}(42)` → `(foo{})(42)`)。マクロを使え下記のような記述もできます。絶対におススメしませんけど。
36
+
37
+ ```C++
38
+ struct foo {
39
+ // generic version
40
+ template <class T>
41
+ T operator()(T a) { return a + a; }
42
+ // specialized version
43
+ int operator()(int a) { return a * 10; }
44
+ };
45
+
46
+ #define foo (foo{})
47
+ ```
48
+ Demo: [https://wandbox.org/permlink/Fq280pkwKeAPJV4c](https://wandbox.org/permlink/Fq280pkwKeAPJV4c)