Template talk:example

Run this code
Since liveworkspace hasn't been accessible for a while, can this template be redone to execute code at Coliru? That site allows file I/O, has clang and gcc and boost etc. For example, my cpp/locale/codecvt example (uses file) http://coliru.stacked-crooked.com/view?id=0b5a9d7f1b90ee53d75f89736c30dde5-f674c1a6d04c632b71a62362c0ccfc51 or someone else's example from Stackoverflow earlier today (uses boost to write to file and then shows it): http://coliru.stacked-crooked.com/view?id=f183a5f4d18ba357db2dda4ce38b1c06-da882c8a8f99862423d4c4ab7f16877a --Cubbi 08:23, 18 August 2013 (PDT)


 * I agree that is worth to look for alternatives to liveworkspace. I played a bit with coliru and think it could be a good replacement. However, I didn't notice anything mentioning API usage or even ways to contact the webmaster. Any chance you know who's behind the website? P12 05:45, 19 August 2013 (PDT)


 * It's http://stackoverflow.com/users/75889/stackedcrooked - I'll try to catch him in chat. --Cubbi 06:14, 19 August 2013 (PDT)


 * I also agree that this would be awesome, and it would be worth reaching out to the person(s) behind Coliru to see if they are interested. For liveworkspace, we ended up using a pretty simple API that just basically just used a compressed and base64-encoded program+options (like which compiler to use) and used the resulting string directly in a URL.  This approach was limited by the informal ~2k URL length limit, but that hopefully isn't much of an issue for our examples. (Alternatively we could POST the payload.) --Nate 07:07, 19 August 2013 (PDT)


 * So apparently there is an API --Cubbi 19:25, 19 August 2013 (PDT)

You can compile a program on Coliru with a simple HTTP POST request:


 * Simple Bash program:

~ $ curl http://coliru.stacked-crooked.com/compile -d '{"cmd": "echo Hello World", "src": ""}' + echo Hello World Hello World


 * Simple C++ program:

~ $ curl http://coliru.stacked-crooked.com/compile -d '{"cmd": "g++ main.cpp && ./a.out", "src": "#include \nint main{   std::cout << \"Hello World!\" << std::endl;}"}'

You can use JavaScript's JSON.stringify function to escape the C++ program text. --StackedCrooked 19:48, 19 August 2013 (PDT)


 * That's great. I'll see if I can get something working with that API. --Nate 04:30, 20 August 2013 (PDT)


 * I think we could do awesome things with this API. Imagine the "run the code" button bringing up an inline editor that allows running the code and seeing the results, all while still seeing the documentation above. P12 08:24, 20 August 2013 (PDT)


 * Coliru currently explicitly enforces same-origin policy, so there's hardly a way users could use coliru without us proxying the requests in some way. P12 04:13, 21 August 2013 (PDT)

When no output is specified, an empty paragraph is generated instead.
If the parameter is not specified, an empty paragraph is generated after the example code — right where the output part of the example would be shown. I think its superfluous.

Here are some examples:

This post-example text is placed right after the output.

This post-example text is separated from the example code by a blank line/paragraph where the output would be shown. — Radix (talk) 16:46, 28 November 2020 (PST)


 * After some experimenting on a replica of the original   wiki-template it became clear that the aforementioned glitch (extra paragraph) is on account of the two extra new-lines (to be deleted!) inside that wiki-template. The "patched" template is here:.

Test results using the updated wiki-template
This post-example text is placed right after the output.

A post-example sample text...

This post-example text to be placed right after the output.

Post-example text...
 * --Space Mission (talk) 10:26, 25 February 2021 (PST)

To Admins: a request to update protected { {example} } template
Dear ADMINS! Could you (slightly) update the protected template   to remove that really annoying superfluous paragraph (one big extra line), that is generated after every Example when no Output is specified (i.e. when the  clause is absent). For comparison, no such superfluous paragraph is generated after the template.

What should be done: the code of the protected wiki-template   to be replaced with the following code (the only difference is that two new lines are removed):

This "new" code works fine for the tested template , as you can see (and test further) on this talk page (see above). After this update (if applied:), the result can be observed on any page where there are more than one (mini-)example, e.g. on cpp/language/lambda (see the example that stays before the phrase "Within the body of a lambda"... ). Thanks in advance.) --Space Mission (talk) 13:16, 31 March 2021 (PDT)
 * ✅. --Space Mission (talk) 09:18, 6 April 2021 (PDT)

Protected edit request: Arguments to insert leading spaces
At Template talk:source, I've just requested the addition of a new parameter, to insert the given number of leading spaces before the displayed code. This is necessary because MediaWiki eats leading and trailing spaces on all arguments specified with a parameter name, such as  or.

Assuming that request is applied, I'd like to then request that Template:example be updated to accept parameters which it would pass to the relevant  calls.
 * (for the code block)
 * (for the example output)

To do that, after Template:source is updated (assuming it is), please change the template code here to: Thanks. -- FeRDNYC (talk) 18:30, 3 July 2021 (PDT)

Protected edit request: Argument to add compiler flags
Could you update the protected template   to allow passing custom flags to the compiler? GCC (and clang?) do not support, and so the example at cpp/numeric/math/rint is very confusingly broken (with rounding set downward, rint(-2.3) -> -2.f instead of -3.f --- surprisingly, given the preceding, lrint(-2.3) -> -3 correctly!). This can be fixed by passing -frounding-math to at least some of the GCC versions when I tested it on Coliru separately. Looking at the wiki template, I don't see a way to wire up even page-hardcoded flags (let alone enabling a UI for the user to experiment).

Thanks! [mailto:william.cushing@gmail.com Will] 172.69.134.153 06:26, 30 May 2023 (PDT)