|
68 | 68 |
|
69 | 69 | </head>
|
70 | 70 | <body>
|
71 |
| -<header data-kunai-mdinfo="{"meta": {"cpp": ["cpp11"]}, "sources": [{"id": "aa32f5ca5c003f8f89916cf2dd5148d7ce59f136", "source": "#include <cstdio>\n\n// \u53ef\u5909\u500b\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308a\u3001std::printf()\u95a2\u6570\u306e\u5f15\u6570\u3068\u3057\u3066\u8ee2\u9001\u3059\u308b\n// \u7b2c1\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u5fc5\u9808\u3002\n// \u7b2c1\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u3046\u3057\u308d\u306b\u30ab\u30f3\u30de\u304c\u3042\u308b\u306e\u3067\u3001\u7b2c2\u30d1\u30e9\u30e1\u30fc\u30bf\u3082\u5fc5\u9808\u3002\n# define DEBUG_LOG(fmt, ...) std::printf(fmt, __VA_ARGS__)\n\n// \u53d7\u3051\u53d6\u3063\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5c55\u958b\u3059\u308b\n// 0\u500b\u4ee5\u4e0a\u306e\u3001\u4efb\u610f\u306e\u500b\u6570\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308c\u308b\n# define FORWARD_ARGS(...) __VA_ARGS__\n\nvoid f1(int a, int b, int c)\n{\n std::printf(\"f1 : %d %d %d\\n\", a, b, c);\n}\n\nvoid f2()\n{\n std::printf(\"f2\\n\");\n}\n\nint main()\n{\n DEBUG_LOG(\"%s %d\\n\", \"Hello\", 42);\n\n f1(FORWARD_ARGS(1, 2, 3)); // \u5f15\u65703\u500b\n f2(FORWARD_ARGS()); // \u5f15\u65700\u500b\n}\n"}], "page_id": ["lang", "cpp11", "variadic_macros"]}"> |
| 71 | +<header data-kunai-mdinfo="{"meta": {"cpp": ["cpp11"]}, "sources": [{"id": "99bf8aeced9580e87d526c7f8034e78bf82a9aed", "source": "#include <cstdio>\n\n// \u53ef\u5909\u500b\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308a\u3001std::printf()\u95a2\u6570\u306e\u5f15\u6570\u3068\u3057\u3066\u8ee2\u9001\u3059\u308b\n// \u7b2c1\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u5fc5\u9808\u3002\n// \u7b2c1\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u3046\u3057\u308d\u306b\u30ab\u30f3\u30de\u304c\u3042\u308b\u306e\u3067\u3001\u7b2c2\u30d1\u30e9\u30e1\u30fc\u30bf\u3082\u5fc5\u9808\u3002\n#define DEBUG_LOG(fmt, ...) std::printf(fmt, __VA_ARGS__)\n\n// \u53d7\u3051\u53d6\u3063\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5c55\u958b\u3059\u308b\n// 0\u500b\u4ee5\u4e0a\u306e\u3001\u4efb\u610f\u306e\u500b\u6570\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308c\u308b\n#define FORWARD_ARGS(...) __VA_ARGS__\n\nvoid f1(int a, int b, int c)\n{\n std::printf(\"f1 : %d %d %d\\n\", a, b, c);\n}\n\nvoid f2()\n{\n std::printf(\"f2\\n\");\n}\n\nint main()\n{\n DEBUG_LOG(\"%s %d\\n\", \"Hello\", 42);\n\n f1(FORWARD_ARGS(1, 2, 3)); // \u5f15\u65703\u500b\n f2(FORWARD_ARGS()); // \u5f15\u65700\u500b\n}\n"}], "page_id": ["lang", "cpp11", "variadic_macros"]}"> |
72 | 72 | <nav class="navbar navbar-default" role="navigation">
|
73 | 73 | <div class="container-fluid">
|
74 | 74 | <div class="navbar-header">
|
|
188 | 188 |
|
189 | 189 | <p class="text-right"><small>
|
190 | 190 | 最終更新日時(UTC):
|
191 |
| - <span itemprop="datePublished" content="2025-07-10T01:26:30"> |
192 |
| - 2025年07月10日 01時26分30秒 |
| 191 | + <span itemprop="datePublished" content="2025-07-13T05:39:17"> |
| 192 | + 2025年07月13日 05時39分17秒 |
193 | 193 | </span>
|
194 | 194 | <br/>
|
195 | 195 | <span itemprop="author" itemscope itemtype="http://schema.org/Person">
|
@@ -223,25 +223,26 @@ <h2>概要</h2>
|
223 | 223 | <h2>仕様</h2>
|
224 | 224 | <p>可変引数マクロは、0個以上の任意の引数をマクロに渡すための機能である。</p>
|
225 | 225 | <p>可変引数マクロは、以下の構文を持つ:</p>
|
226 |
| -<p><pre><code># define identifier ( ... ) replacement-list new-line |
227 |
| -# define identifier ( identifier-list , ... ) replacement-list new-line |
228 |
| -</code></pre></p> |
| 226 | +<p><div class="codehilite"><pre><span></span><code><span class="cp">#define <i>identifier</i> ( ... ) <i>replacement-list</i> <i>new-line</i></span> |
| 227 | +<span class="cp">#define <i>identifier</i> ( <i>identifier-list</i> , ... ) <i>replacement-list</i> <i>new-line</i></span> |
| 228 | +</code></pre></div> |
| 229 | +</p> |
229 | 230 | <p>1行目は、パラメータ全てを可変個受け取る場合。2行目は、先頭のいくつかのパラメータを名前付きで受け取り、それ以外に可変個のパラメータを受け取る場合。</p>
|
230 | 231 | <p>可変個のパラメータのあとに、名前付きのパラメータを受け取ることはできない。</p>
|
231 | 232 | <p><code>...</code>が指定されたパラメータには、ユーザーはカンマ区切りで可変個の引数を指定する。</p>
|
232 | 233 | <p>可変引数マクロ内で、受け取った可変個のパラメータを使用するには、<code>__VA_ARGS__</code>識別子を指定する。それを使用することで、<code>__VA_ARGS__</code>を指定した部分が、指定された可変個のパラメータで置き換えられる。</p>
|
233 | 234 | <p>空の可変個パラメータを文字列に変換する場合、対応する文字列は<code>""</code>となる。</p>
|
234 | 235 | <h2>例</h2>
|
235 |
| -<p><div class="yata" id="aa32f5ca5c003f8f89916cf2dd5148d7ce59f136"><div class="codehilite"><pre><span></span><code><span class="cp">#include</span> <span class="cpf"><a href="../../reference/cstdio.html"><cstdio></a></span><span class="cp"></span> |
| 236 | +<p><div class="yata" id="99bf8aeced9580e87d526c7f8034e78bf82a9aed"><div class="codehilite"><pre><span></span><code><span class="cp">#include</span> <span class="cpf"><a href="../../reference/cstdio.html"><cstdio></a></span><span class="cp"></span> |
236 | 237 |
|
237 | 238 | <span class="c1">// 可変個のパラメータを受け取り、<a href="../../reference/cstdio/printf.html">std::printf</a>()関数の引数として転送する</span>
|
238 | 239 | <span class="c1">// 第1パラメータは必須。</span>
|
239 | 240 | <span class="c1">// 第1パラメータのうしろにカンマがあるので、第2パラメータも必須。</span>
|
240 |
| -<span class="cp"># define DEBUG_LOG(fmt, ...) <a href="../../reference/cstdio/printf.html">std::printf</a>(fmt, __VA_ARGS__)</span> |
| 241 | +<span class="cp">#define DEBUG_LOG(fmt, ...) <a href="../../reference/cstdio/printf.html">std::printf</a>(fmt, __VA_ARGS__)</span> |
241 | 242 |
|
242 | 243 | <span class="c1">// 受け取ったパラメータを展開する</span>
|
243 | 244 | <span class="c1">// 0個以上の、任意の個数のパラメータを受け取れる</span>
|
244 |
| -<span class="cp"># define FORWARD_ARGS(...) __VA_ARGS__</span> |
| 245 | +<span class="cp">#define FORWARD_ARGS(...) __VA_ARGS__</span> |
245 | 246 |
|
246 | 247 | <span class="kt">void</span> <span class="nf">f1</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">,</span> <span class="kt">int</span> <span class="n">c</span><span class="p">)</span>
|
247 | 248 | <span class="p">{</span>
|
|
0 commit comments