Difference between revisions of "Talk:Main Page/suggestions"
(Reply to offer to copy edits) |
(→RFC: another implementation of Gadget-StandardRevision: new section) |
||
Line 399: | Line 399: | ||
in the "See Also" section would have been very helpful. | in the "See Also" section would have been very helpful. | ||
[[Special:Contributions/217.158.111.130|217.158.111.130]] 06:14, 1 March 2019 (PST) | [[Special:Contributions/217.158.111.130|217.158.111.130]] 06:14, 1 March 2019 (PST) | ||
+ | |||
+ | == RFC: another implementation of Gadget-StandardRevision == | ||
+ | |||
+ | |||
+ | {{cot|source code}} | ||
+ | <source lang=jquery> | ||
+ | (function() { | ||
+ | 'use strict'; | ||
+ | var styles = document.createElement('style'); | ||
+ | styles.textContent = '[hidden] { display: none !important; }'; | ||
+ | styles.textContent += '.stdrev-rev-hide > tbody > tr > td { border: none !important; padding: 0 !important; }' | ||
+ | styles.textContent += '.stdrev-rev-hide > tbody > tr > td:nth-child(2) { display: none; }' | ||
+ | styles.textContent += '.stdrev-rev-hide { border: none; }' | ||
+ | styles.textContent += '.stdrev-rev-hide > span > .t-mark-rev { display: none; }' | ||
+ | document.head.append(styles); | ||
+ | |||
+ | var rev = mw.config.get('wgTitle').indexOf('c/') === 0 ? | ||
+ | [ 'C89', 'C99', 'C11' ] : | ||
+ | [ 'C++98', 'C++03', 'C++11', 'C++14', 'C++17', 'C++20' ]; | ||
+ | |||
+ | var select = $('<div class="vectorMenu"></div>').appendTo('#cpp-head-tools-right'); | ||
+ | select.append('<h5><span>Std rev</span></h5>'); | ||
+ | var list = $('<ul>').appendTo($('<div class="menu">').appendTo(select)); | ||
+ | $.each(['DIFF'].concat(rev), function(i, v) { | ||
+ | list.append('<li><a href="#'+v+'">'+v+'</a></li>'); | ||
+ | }); | ||
+ | list.on('click', 'a', function(e) { | ||
+ | list.find('a').css('font-weight', 'normal'); | ||
+ | $(this).css('font-weight', 'bold'); | ||
+ | curr_rev = e.target.innerText; | ||
+ | on_rev_changed(); | ||
+ | }); | ||
+ | |||
+ | var curr_rev = 'DIFF'; | ||
+ | |||
+ | // Returns true if an element should be shown in the current revision, that is, either curr_rev is | ||
+ | // DIFF (i.e. show all), or curr_rev is within the range [since, until). The range [since, until) | ||
+ | // is inspected from the classes of `el`. | ||
+ | // `el` may be the same element as the one to be shown if it has the needed classes, or it may be a | ||
+ | // revision marker or a collection thereof (e.g. one expanded from {{mark since foo}}, or from the | ||
+ | // {{mark since foo}}{{mark until bar}} combo). | ||
+ | // `el` may be either a HTML element or a jQuery object. | ||
+ | // Note that this correctly handle the case when `el` represents an empty set of elements (in which | ||
+ | // case the element is always shown). | ||
+ | function should_be_shown(el) { | ||
+ | if (curr_rev === 'DIFF') return true; | ||
+ | var curr_revid = rev.indexOf(curr_rev); | ||
+ | var since = 0, until = rev.length; | ||
+ | $.each(rev, function(i) { | ||
+ | var ssince = 't-since-'+rev[i].toLowerCase().replace(/\+/g, 'x'); | ||
+ | var suntil = 't-until-'+rev[i].toLowerCase().replace(/\+/g, 'x'); | ||
+ | if ($(el).hasClass(ssince)) since = i; | ||
+ | if ($(el).hasClass(suntil)) until = i; | ||
+ | }); | ||
+ | return since <= curr_revid && curr_revid < until; | ||
+ | } | ||
+ | |||
+ | // Called when user changes the selected revision. Inside this function, curr_rev is already set to | ||
+ | // the value after the change. | ||
+ | function on_rev_changed() { | ||
+ | handle_dcl(); | ||
+ | renumber_dcl(); | ||
+ | handle_dsc(); | ||
+ | handle_nv(); | ||
+ | handle_rev(); | ||
+ | handle_headings(); | ||
+ | handle_list_items(); | ||
+ | $('.t-rev-begin, .t-rev-inl').toggleClass('stdrev-rev-hide', curr_rev !== 'DIFF'); | ||
+ | $('.t-mark-rev').each(function() { | ||
+ | this.hidden = curr_rev !== 'DIFF'; | ||
+ | if ($(this.nextSibling).is('br')) | ||
+ | this.nextSibling.hidden = curr_rev !== 'DIFF'; | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | // Returns true if the jQuery object `el` contains at least one element, and all contained elements | ||
+ | // are hidden; otherwise returns false. | ||
+ | // This is used to hide a 'parent' or 'heading' element when all its contents are hidden. | ||
+ | function all_hidden(el) { return $(el).length > 0 && !$(el).is(':not([hidden])'); } | ||
+ | |||
+ | // Hide or show the elements expanded from the {{dcl ...}} template family. See documentation at | ||
+ | // https://en.cppreference.com/w/Template:dcl/doc . | ||
+ | // The dcl items (expanded from {{dcl | ... }}) may either appear alone or as children of versioned | ||
+ | // declaration list (expanded from {{dcl rev begin | ... }}). In the latter case, the revision may | ||
+ | // be supplied by the dcl items or by the dcl-rev (in the latter case the dcl-rev has class | ||
+ | // t-dcl-rev-notes). | ||
+ | // For the use of renumber_dcl(), each dcl-rev is marked as hidden if all its children dcl items | ||
+ | // are hidden, and vice versa. | ||
+ | function handle_dcl() { | ||
+ | $('.t-dcl').each(function() { | ||
+ | this.hidden = !should_be_shown(this); | ||
+ | }); | ||
+ | $('.t-dcl-rev').each(function() { | ||
+ | if ($(this).is('.t-dcl-rev-notes')) { | ||
+ | var hidden = !should_be_shown(this); | ||
+ | this.hidden = hidden; | ||
+ | $(this).find('.t-dcl').each(function() { | ||
+ | this.hidden = hidden; | ||
+ | }); | ||
+ | } else { | ||
+ | this.hidden = all_hidden($(this).find('.t-dcl')); | ||
+ | } | ||
+ | }); | ||
+ | $('.t-dcl-begin .t-dsc-header').each(function() { | ||
+ | var marker = $(this).find('> td > div > .t-mark-rev'); | ||
+ | var lastheader = $(this).nextUntil(':not(.t-dsc-header)').addBack(); | ||
+ | var elts = lastheader.nextUntil('.t-dsc-header').filter('.t-dcl, .t-dcl-rev'); | ||
+ | this.hidden = all_hidden(elts) || !should_be_shown(marker); | ||
+ | }); | ||
+ | $('.t-dcl-h').each(function() { | ||
+ | this.hidden = all_hidden($(this).nextUntil(':not(.t-dcl, .t-dcl-rev)')); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | // Ensure that each visible dcl item in a dcl list is contiguously numbered, and rewrite mentions | ||
+ | // to these numbers to use the modified numbering. | ||
+ | // If a list item (e.g. those expanded from @m@) contains no number after the rewrite (i.e. it's | ||
+ | // inapplicable in current revision), it is hidden. | ||
+ | // Note that the use of '~ * .t-li, ~ * .t-v' effectively establishes a kind of scoping: only | ||
+ | // numbers that appear after the dcl list and are more nested in the DOM hierarchy are affected | ||
+ | // by the renumbering. | ||
+ | // Requires that handle_dcl() has been called. | ||
+ | function renumber_dcl() { | ||
+ | $('.t-dcl-begin').each(function() { | ||
+ | var numbering_map = []; | ||
+ | var i = 0; | ||
+ | $(this).find('.t-dcl, .t-dcl-rev').each(function() { | ||
+ | var num_cell; | ||
+ | if ($(this).is('.t-dcl')) | ||
+ | num_cell = $(this).children('td:nth-child(2)'); | ||
+ | else | ||
+ | num_cell = $(this).find('> tr.t-dcl-rev-aux > td:nth-child(2)'); | ||
+ | var number_text = /\s*\((\d+)\)\s*/.exec(num_cell.text()); | ||
+ | if (!num_cell.attr('data-orig-num') && number_text) | ||
+ | num_cell.attr('data-orig-num', number_text[1]); | ||
+ | var original_num = num_cell.attr('data-orig-num'); | ||
+ | if (original_num) { | ||
+ | if (! numbering_map[original_num]) | ||
+ | numbering_map[original_num] = $(this).is('[hidden]') ? null : ++i; | ||
+ | num_cell.text('('+numbering_map[original_num]+')'); | ||
+ | } | ||
+ | }); | ||
+ | $(this).find('~ * .t-li, ~ * .t-v').each(function() { | ||
+ | if (! $(this).attr('data-orig-v')) | ||
+ | $(this).attr('data-orig-v', $(this).text().replace(/[()]/g, '')); | ||
+ | var original_numbers = []; | ||
+ | $.each($(this).attr('data-orig-v').split(','), function(i, v) { | ||
+ | var match = /(\d+)(?:-(\d+))?/.exec(v); | ||
+ | if (match[2]) | ||
+ | for (var i = +match[1]; +i <= +match[2]; ++i) | ||
+ | original_numbers.push(i); | ||
+ | else | ||
+ | original_numbers.push(match[1]); | ||
+ | }); | ||
+ | var numbers = $.map(original_numbers, function(x) { | ||
+ | return numbering_map[x]; | ||
+ | }); | ||
+ | var s = []; | ||
+ | for (var i = 0; i < numbers.length; ++i) { | ||
+ | if (numbers[i+1] - numbers[i] === 1 && numbers[i+2] - numbers[i+1] === 1) { | ||
+ | var begin = numbers[i]; | ||
+ | while (numbers[i+1] - numbers[i] === 1) | ||
+ | ++i; | ||
+ | s.push(begin+'-'+numbers[i]); | ||
+ | } else { | ||
+ | s.push(numbers[i]); | ||
+ | } | ||
+ | } | ||
+ | if ($(this).is('.t-li')) { | ||
+ | this.parentElement.hidden = numbers.length === 0; | ||
+ | $(this).text(s.join(',')+')'); | ||
+ | } else | ||
+ | $(this).text('('+s.join(',')+')'); | ||
+ | }); | ||
+ | }); | ||
+ | } | ||
+ | // Hide or show the elements expanded from the {{dsc ...}} template family. See documentation at | ||
+ | // https://en.cppreference.com/w/Template:dcl/doc . | ||
+ | // The revision markers are in the first cell of each dsc item. In the general case, the visibility | ||
+ | // of a dsc item is control by a single revision marker. But if a specialized template is used, | ||
+ | // and the amount of entity names in the first cell matches the lines of the revision markers, | ||
+ | // then each line controls the visibility of a single entity name, and the dsc item is hidden only | ||
+ | // if all the entity names are hidden. | ||
+ | // If all the dsc items are hidden, then the corresponding headings are hidden as well. | ||
+ | function handle_dsc() { | ||
+ | $('.t-dsc').each(function() { | ||
+ | var member = $(this).find('.t-dsc-member-div'); | ||
+ | if (member[0]) { | ||
+ | var lines = member.find('> div:nth-child(2) > .t-lines').children(); | ||
+ | var mems = member.find('> div:first-child .t-lines').children(); | ||
+ | if (lines.length !== mems.length) | ||
+ | this.hidden = !should_be_shown(lines.children('.t-mark-rev')); | ||
+ | else { | ||
+ | lines.each(function(i) { | ||
+ | var marker = $(this).children('.t-mark-rev'); | ||
+ | mems[i].hidden = !should_be_shown(marker); | ||
+ | marker.hidden = !should_be_shown(marker); | ||
+ | }); | ||
+ | this.hidden = all_hidden(mems); | ||
+ | } | ||
+ | } else { | ||
+ | var marker = $(this).find('> td:first-child > .t-mark-rev'); | ||
+ | this.hidden = !should_be_shown(marker); | ||
+ | } | ||
+ | }); | ||
+ | $('.t-dsc .t-dsc-header').each(function() { | ||
+ | var marker = $(this).find('> td > div > .t-mark-rev'); | ||
+ | var lastheader = $(this).nextUntil(':not(.t-dsc-header)').addBack(); | ||
+ | this.hidden = all_hidden(lastheader.nextUntil(':not(.t-dsc)')) || !should_be_shown(marker); | ||
+ | }); | ||
+ | var heading_selector = ['tr:has(> td > h5)', 'tr:has(> td > h3)']; | ||
+ | $.each(heading_selector, function(i, selector) { | ||
+ | $(selector).each(function() { | ||
+ | var section = $(this).nextUntil(heading_selector.slice(i).join(',')); | ||
+ | this.hidden = all_hidden(section.filter('.t-dsc')); | ||
+ | }); | ||
+ | }); | ||
+ | $('.t-dsc-begin').each(function() { | ||
+ | this.hidden = all_hidden($(this).find('.t-dsc')); | ||
+ | }); | ||
+ | } | ||
+ | // Hide or show the navbar elements expanded from the {{nv ...}} template family. See documentation | ||
+ | // at https://en.cppreference.com/w/Template:nv/doc . | ||
+ | // A line of revision marker only controls a single entity name, even if it's expanded from | ||
+ | // {{nv ln | ... }} that contains multiple lines. | ||
+ | // If a heading contains a revision marker, that revision marker controls the visibility of the | ||
+ | // heading and its corresponding contents; otherwise the heading is hidden when it is followed by | ||
+ | // content elements, and all of them are hidden. | ||
+ | function handle_nv() { | ||
+ | $('.t-nv').each(function() { | ||
+ | var marker = $(this).find('> td > .t-mark-rev'); | ||
+ | this.hidden = !should_be_shown(marker); | ||
+ | }); | ||
+ | $('.t-nv-ln-table').each(function() { | ||
+ | var lines = $(this).find('> div:nth-child(2) > .t-lines').children(); | ||
+ | var mems = $(this).find('> div:first-child .t-lines').children(); | ||
+ | lines.each(function(i) { | ||
+ | var marker = $(this).children('.t-mark-rev'); | ||
+ | if (mems[i]) mems[i].hidden = !should_be_shown(marker); | ||
+ | marker.hidden = !should_be_shown(marker); | ||
+ | }); | ||
+ | this.hidden = all_hidden(mems); | ||
+ | }); | ||
+ | var heading_selector = ['.t-nv-h2', '.t-nv-h1']; | ||
+ | $.each(heading_selector, function(i, selector) { | ||
+ | $(selector).each(function() { | ||
+ | var section = $(this).nextUntil(heading_selector.slice(i).join(',')); | ||
+ | var marker = $(this).find('> td > .t-mark-rev'); | ||
+ | if (marker[0]) { | ||
+ | section.each(function() { | ||
+ | this.hidden = this.hidden || !should_be_shown(marker); | ||
+ | }); | ||
+ | this.hidden = !should_be_shown(marker); | ||
+ | } | ||
+ | this.hidden = all_hidden(section.find('.t-nv-ln-table')); | ||
+ | }); | ||
+ | }); | ||
+ | } | ||
+ | // Hide or show the elements expanded from the {{rev ...}} template family. See documentation at | ||
+ | // https://en.cppreference.com/w/Template:dcl/doc . | ||
+ | // Borders are handled by class stdrev-rev-hide. | ||
+ | function handle_rev() { | ||
+ | $('.t-rev, .t-rev-inl').each(function() { | ||
+ | this.hidden = !should_be_shown(this); | ||
+ | }); | ||
+ | } | ||
+ | // Hide or show headings. | ||
+ | // If the heading contains a revision marker, that revision marker controls the visibility of it | ||
+ | // and its corresponding contents; otherwise, a heuristic is made: if the contents contain a dsc | ||
+ | // list, and its revision-related contents are hidden, then the heading and all contents are hidden | ||
+ | // as well. | ||
+ | // The heuristic requires that handle_dsc() and handle_rev() have been called. | ||
+ | function handle_headings() { | ||
+ | var heading_selector = ['h5', 'h4', 'h3', 'h2']; | ||
+ | $.each(heading_selector, function(i, selector) { | ||
+ | $(selector).each(function() { | ||
+ | var section = $(this).nextUntil(heading_selector.slice(i).join(',')); | ||
+ | var marker = $(this).find('> span > .t-mark-rev'); | ||
+ | if (marker[0]) { | ||
+ | section.each(function() { | ||
+ | this.hidden = this.hidden || !should_be_shown(marker); | ||
+ | }); | ||
+ | this.hidden = !should_be_shown(marker); | ||
+ | } | ||
+ | if (section.is('.t-dsc-begin') && !section.is(':not(p, .t-rev-begin, .t-dsc-begin)')) { | ||
+ | var revisioned_content = section.find('.t-dsc, .t-rev, .t-rev-inl'); | ||
+ | section.each(function() { | ||
+ | this.hidden = this.hidden || all_hidden(revisioned_content); | ||
+ | }); | ||
+ | this.hidden = all_hidden(revisioned_content); | ||
+ | } | ||
+ | }); | ||
+ | }); | ||
+ | } | ||
+ | // Hide or show <li> elements based on the contained revision markers. | ||
+ | function handle_list_items() { | ||
+ | $('li').each(function() { | ||
+ | var marker = $(this).children('.t-mark-rev'); | ||
+ | this.hidden = !should_be_shown(marker); | ||
+ | }); | ||
+ | } | ||
+ | })(); | ||
+ | </source> | ||
+ | {{cob}} | ||
+ | |||
+ | Features include: | ||
+ | |||
+ | # hide section based on revision markers in the heading | ||
+ | # hide <li> based on its contained revision markers | ||
+ | # hide "Defined in header ..." when the corresponding entities are hidden | ||
+ | # implement renumbering inside {{tl|v}} | ||
+ | # ''much'' shorter than P12's implementation! (~300LOC vs ~1800LOC) | ||
+ | |||
+ | Does it make sense to include this as an "official" gadget? | ||
+ | |||
+ | --[[Special:Contributions/223.3.167.101|223.3.167.101]] 10:25, 3 March 2019 (PST) |
Revision as of 10:25, 3 March 2019
This page collects edit suggestions from new and logged-out users when editing is temporarily disabled due to vandalism. Click the "+" at the top to leave a message. Please make sure to include a link to the page you are referencing.
error in description
If the requested substring extends past the end of the string, or if count == npos, the returned substring is [pos, size()).
is only correct if pos==0, it is indeed [pos, size()-pos)
2A02:8109:8AC0:44F0:8D26:D9BA:67A0:17DA 00:23, 12 February 2019 (PST)
- The example in that page (which is cpp/string/basic_string/substr, to provide context), demonstrates this sentence: a.substr(a.size()-3, 50) returns "hij", which is [pos, size()) or [17,20) in that case. --Cubbi (talk) 07:20, 12 February 2019 (PST)
Poor example in front_inserter
Example in: cpp/iterator/front inserter is poor because it fills three slots at the front of dequeue with -1, which fails to illustrate the order.
Suggest reusing example from front_insert_iterator which clearly shows the elements are inserted reversed (i.e. each insert is at the front, before the last one inserted).
john skaller 49.181.255.99 21:45, 13 February 2019 (PST)
errors about concept in template_parameters page
hi man ,
I have read the template_parameters in cppreference , and I found there are two kinds of errors in [[1]]
1) missing "bool" before "concept" 2) missing ellipsis before T in template<C4 T> void f5(); // OK: T is a type template-parameter
I use the below codes to complies in [2]
#include <iostream> #include <string> template<typename T> bool concept C1 = true; template<template<typename> class X> bool concept C2 = true; template<int N> bool concept C3 = true; template<typename... Ts> bool concept C4 = true; template<char... Cs> bool concept C5 = true; template<C1 T> void f1(){} // OK: T is a type template-parameter template<C2 X> void f2(){} // OK: X is a template with one type-parameter template<C3 N> void f3(); // OK: N has type int template<C4... Ts> void f4(); // OK: Ts is a template parameter pack of types template<C4... T> void f5(); // OK: T is a type template-parameter template<C5... Cs> void f6(); // OK: Cs is a template parameter pack of chars template<C1 T = int> struct S1; // OK template<typename T> struct S0; template<C2 X = S0> struct S3; // OK template<C3 N = 0> struct S2; // OK //template<C1 T = 0> struct S4; // error: default argument is not a type template <typename> struct Dummy{}; int main() { f1<int>(); f2<S0>(); }
and the compile command is g++ -std=c++2a -O2 -Wall -fconcepts -pedantic -pthread main.cpp && ./a.out
then I have no get errors any more , I am not sure the cppreference error or compiler bugs , could you please check it double , thank you very much.
--http://www.lisuwang.com 23:25, 13 February 2019 (PST)
- gcc -fconcepts is the TS concepts, C++20 has different concepts. You can compile our example using clang here: https://gcc.godbolt.org/z/rVC5N5 --Cubbi (talk)
noexcept specifier
The description of functions with an implicit non-throwing exception specifier is not complete. Implicitly declared constructors and assignment operators are omitted. Also comparison operators that are defaulted on their first declaration is omitted. Furthermore it unnecessarily lists categories of constructors and assignment operators.
Version switch
With new versions of standard, many pages become bloated with many versions of the same function, differing by very little. In my opinion it results in them being unreadable. This is very generic suggestion, but it would be nice to have mechanism (maybe browser plugin?) allowing to show only state as it used to be at the requested version, without things already removed or added later. Kaznov (talk) 09:19, 14 February 2019 (PST)
- we have that, you can enable it in Special:Preferences#mw-prefsection-gadgets --Cubbi (talk) 11:41, 14 February 2019 (PST)
Requesting permission for adding examples
I wanted to enter an example for cpp/string/basic_string_view/empty but that page is locked (due to vandalism).
I'd like to request permission for entering examples, as I'm going through some pages that do not have examples and could take the opportunity to add some. Here's the precise example I wanted to include for the aforementioned page:
#include <iostream> #include <string> void check_string(std::string_view &ref) { // Print string surround by single quotes, its length, and whether it // is considered empty. std::cout << "'" << ref << "' has " << ref.size() << " characters; empty=" << ref.empty() << std::endl; } int main(int argc, char *argv[]) { // An empty string std::string_view es = ""; // Not empty: argv[0] std::string_view argv0(argv[0]); check_string(es); check_string(argv0); }
Output:
'' has 0 characters; empty=1 './a.out' has 7 characters; empty=0
Rnsanchez (talk) 04:20, 18 February 2019 (PST)
- I've added the example with tiny modifications. See {{cpp/string/basic_string_view/example empty size}}. --Fruderica (talk) 05:21, 18 February 2019 (PST)
- Note that argv[0] can be a null pointer (it is, if and only if argc == 0). And it can point to an empty string (only if argc >= 1), so one of the comments is erroneous. Also, "surround" should be "surrounded". 2001:B01:2404:4:0:0:0:59 06:07, 19 February 2019 (PST)
"powf", "std::powf" or no "powf": which one is standard?
While trying to compile a C++ program on gcc 7.3.0 (Ubuntu 18.04), the compiler complained that
In function ‘constexpr size_t representable_values()’: ../Template/TSTBalance.hpp:19:15: error: ‘powf’ is not a member of ‘std’
return (std::powf(2, sizeof(T) * CHAR_BIT));
The workaround, in my case, consisted in removing the "std::" prefix from powf and then it worked. This seems to me in contrast with [3]. Moreover, in this SO answer it is claimed that "powf()" is not ISO standard at all. So, am I missing something or is there an incongruence?
- Answers posted above were correct before C++11, since C++98/03 hadn't referred C99 library yet. According to the current standard,
powf
is declared in namespacestd
when <cmath> is included (explicitly mentioned since C++17, implicitly mentioned in C++11/14, see also N4659, N4140 and N3337).
Forstd::powf
, gcc libstdc++ is not compliant while clang libc++ is. --Fruderica (talk) 03:49, 19 February 2019 (PST)
- see also this, more recent, SO answer: https://stackoverflow.com/a/54735351 --Cubbi (talk) 08:10, 19 February 2019 (PST)
Example of "Static storage duration"
Hi,
the output of the example at <https://en.cppreference.com/w/c/language/static_storage_duration> is described as "*possible* output". Why? Isn't that output the only possible? Thanks. 2001:B01:2404:4:0:0:0:59 06:02, 19 February 2019 (PST)
- Good, thanks :-) 2001:B01:2404:4:0:0:0:59 06:44, 21 February 2019 (PST)
Sentence clarity in Template:cpp/error/exception/constructor
With this edit, the edited sentence has become a garden-path sentence and thus difficult to parse, and I think it could be reworded. I suggest "Because throwing exceptions during the copy of a standard library class derived from std::exception is not permitted". 2601:1C0:4700:7AF4:5D48:D85F:C64F:6ED 14:27, 19 February 2019 (PST)
std::pair::swap
In the description of std::pair::swap(), I would have benefited from narrative saying something like:
One might think the intent of this function is to swap the two elements of the argument pair. (This would not even make sense when the types of the elements are not identical.) However, this method swaps the entire content of the argument pair with the entire content of the caller. After the call to swap, the contents of both pairs is changed. 198.151.8.4 06:39, 20 February 2019 (PST) sharplesa
- This interpretation seems implausible given that this is a non-static member function that takes an additional parameter. T. Canens (talk) 10:10, 23 February 2019 (PST)
header/span -- Synopis typo
https://en.cppreference.com/w/cpp/header/span
Typo: Synopis => Synopsis (the second "s" is currently missing).
Possibly missing "since C++11"
https://en.cppreference.com/w/cpp/language/static
In the 'Constant static members' section code example there is a variable 'n' and it gets initialized within the class. I tried to use the line with some ancient compiler (visual c++ 6) and it failed. Could it be, that this kind of initialization was a new feature of c++11? This should be made clear then.
79.235.250.122 02:11, 22 February 2019 (PST)
Expression SFINAE DR339 / N2634
I would like to add Expression SFINAE as a C++11 feature: N2634
Supported in: GCC 4.4, clang 2.9, MSVC: no/partial support. In particular, no support for decltype [temp.deduct]/7 up to 19.15. source
Rustyx (talk) 12:40, 22 February 2019 (PST)
- what's missing from its current description in cpp/language/sfinae#Expression_SFINAE? --Cubbi (talk) 12:46, 22 February 2019 (PST)
- I think Rustyx means to add a new row in cpp/compiler support. T. Canens (talk) 10:02, 23 February 2019 (PST)
- Indeed that's what I meant, cpp/compiler support. Can't post on that page, unfortunately. Rustyx (talk) 10:48, 24 February 2019 (PST)
- I think Rustyx means to add a new row in cpp/compiler support. T. Canens (talk) 10:02, 23 February 2019 (PST)
std::terminate - an exception can be thrown during exception handling
point 4 states: 2) an exception is thrown during exception handling (e.g. from a destructor of some local object, or from a function that had to be called during exception handling)
which should instead read "2) an unhandled exception ..." since exceptions can be thrown during exception handling as long as they are handled before stack unwinding completes.
Permission for editing: Compiler support
I would like to add the Apple Clang/Xcode column to the compiler support page now. Thanks in advance for permissions.--Buovjaga (talk) 02:25, 23 February 2019 (PST)
- I don't think I have the technical ability to manually grant permissions. If you post the edits here, I can copy them over. (Although by the time you are done posting them here you may well have accumulated enough edits to get past the threshold...) T. Canens (talk) 10:00, 23 February 2019 (PST)
- I gave this a lot of thought, but I am afraid I cannot bring myself to do it. The work will require possibly creating multiple templates. I cannot reason about this in theory, I need to be able to see the effects of the templates live. Even if I could, I would essentially be writing a complex tutorial on doing the edits, which seems like a massive waste of effort. I will be waiting for the editing permissions. Buovjaga (talk) 05:49, 3 March 2019 (PST)
Hello,
can you add my lib to testing group.
thank you
Regards, Gammasoft71
lib : xtd.unit Category : Testing Description : Modern c++17 unit testing library on Windows, macOS, Linux, iOS and android. GitHub page : https://github.com/gammasoft71/xtd.tunit Home page : https://gammasoft71.wixsite.com/xtd-tunit
Testing
- xtd.tunit - Modern c++17 unit testing library on Windows, macOS, Linux, iOS and android.
Gammasoft71 (talk) 11:38, 24 February 2019 (PST)
thread_local initialization moment is not mandated by the standard
"The storage for the object is allocated when the thread begins ..." is not really true per http://eel.is/c++draft/basic.stc#thread:
1. All variables declared with the thread_local keyword have thread storage duration.
The storage for these entities shall last for the duration of the thread in which they are
created. There is a distinct object or reference per thread, and use of the declared name
refers to the entity associated with the current thread.
2. A variable with thread storage duration shall be initialized before its first odr-use and,
if constructed, shall be destroyed on thread exit.
So in other words, standard does not mandate when initialization is going to take place (it only says that it will be latest before its first odr-use) but also it does not mandate if it will take place at all.
Output of the following program on both gcc and clang () produces the output without
tls_cleanup
being triggered:
#include <iostream>
struct tls_cleanup {
tls_cleanup() {
std::cout << "tls_cleanup ctr\n";
}
~tls_cleanup() {
std::cout << "tls_cleanup dtr\n";
}
};
static thread_local tls_cleanup tls;
int main() {
std::cout << "Entering main()\n";
std::cout << "Exiting main()\n";
return 0;
}
Output:
Entering main()
Exiting main()
There is no first-odr use of tls_cleanup
and compilers are free not to initialize (instantiate) the variable at all. To force them to do so one can add sth like void* ptr = &tls; somewhere in the code.
88.207.93.70 01:52, 25 February 2019 (PST)
- The line you quoted from cpp/language/storage_duration talks about when allocation takes place (compare to static and especially automatic around it), not about initialization, which is covered in cpp/language/initialization#Non-local_variables. Added a more obvious link. --Cubbi (talk) 13:02, 26 February 2019 (PST)
new expression missing exception specs
Somewhere way down in that wall of text there is a mention of std::bad_array_new_length, but that's it. I think there should be a dedicated section "Exceptions" (as in other docs on this site) documenting std::bad_alloc and std::bad_array_new_length as well as the non-throwing versions, as this is pretty fundamental. Perhaps also an example.
Thanks! 213.68.42.195 03:02, 25 February 2019 (PST)
New user
I’m considered a new user and can’t add to a Talk page’s discussion (specifically, I’d wanted to show my support for the this proposal, but the warning says that “editing of this page is temporarily disabled for new users”). How do I become trusted enough for Talk page edits? Thanks! —LLarson (said & done) 10:45, 25 February 2019 (PST)
- It's based on autoconfirmed, so age + edit count. (IOW, the entire wiki modulo this page is effectively semi'd.) Your account is, of course, more than old enough, so it's just edit count. T. Canens (talk) 06:21, 26 February 2019 (PST)
unnecessary include in example code
The "#include <array>" seems to not be required for the example to compile and run. I suggest to remove the line that includes array.
--2001:A61:4702:2F01:8E70:5AFF:FE94:1034 12:47, 26 February 2019 (PST)
New user
Hello, I would like to make changes to the C++ compiler support page related to the addition of the "Modules" and "Coroutines" features to C++20. Can somebody give me permissions to edit or otherwise do the changes as per the following articles:
https://www.phoronix.com/scan.php?page=news_item&px=Coroutines-Modules-CPP20 https://herbsutter.com/2019/02/23/trip-report-winter-iso-c-standards-meeting-kona/
--Trifud (talk) 23:15, 26 February 2019 (PST)
- How long time does it take for a user to be activated? --Trifud (talk) 23:09, 28 February 2019 (PST)
More detailed example.
For page https://en.cppreference.com/w/cpp/algorithm/unique
Example
#include <iostream> #include <algorithm> #include <vector> #include <string> template<typename Iter> void print_values(Iter first, Iter last, Iter end) { for (auto iter = first; iter != last; ++iter) std::cout << *iter << " "; if (last != end) { for (auto iter = last; iter != end; ++iter) std::cout << "x "; } std::cout << "\n"; } template<typename Iter> void print_values(Iter first, Iter last) { print_values(first, last, last); } int main() { std::cout << "example with vector\n"; std::vector<int> v{1,2,3,1,2,3,3,4,5,4,5,6,7}; std::cout << "original data: "; print_values(begin(v), end(v)); // collapse duplicate elements sort(begin(v), end(v)); std::cout << " after sort: "; print_values(begin(v), end(v)); auto last = unique(begin(v), end(v)); std::cout << " after unique: "; print_values(begin(v), last, end(v)); // remove elements v.erase(last, end(v)); std::cout << " after erase: "; print_values(begin(v), end(v)); std::cout << "\nexample with predicate\n"; std::string raw_path = "///path////with/bloated//////separators/"; std::cout << " original string: " << raw_path << "\n"; raw_path.erase( unique( begin(raw_path), end(raw_path), [](char curr, char next) { return curr == '/' && next == '/'; }), end(raw_path)); std::cout << "after unique & erase: " << raw_path << "\n"; }
Output:
example with vector original data: 1 2 3 1 2 3 3 4 5 4 5 6 7 after sort: 1 1 2 2 3 3 3 4 4 5 5 6 7 after unique: 1 2 3 4 5 6 7 x x x x x x after erase: 1 2 3 4 5 6 7 example with predicate original string: ///path////with/bloated//////separators/ after unique & erase: /path/with/bloated/separators/
- The behavior is undefined because your predicate is not reflexive. The page used to have a similar example, until this error was pointed out. --Cubbi (talk) 06:46, 1 March 2019 (PST)
New user
I was puzzled by some example code using 23m and looked at the
C++ documentation for integer literal
|
page. A link to
C++ documentation for user literal
|
in the "See Also" section would have been very helpful. 217.158.111.130 06:14, 1 March 2019 (PST)
RFC: another implementation of Gadget-StandardRevision
source code |
---|
(function() { 'use strict'; var styles = document.createElement('style'); styles.textContent = '[hidden] { display: none !important; }'; styles.textContent += '.stdrev-rev-hide > tbody > tr > td { border: none !important; padding: 0 !important; }' styles.textContent += '.stdrev-rev-hide > tbody > tr > td:nth-child(2) { display: none; }' styles.textContent += '.stdrev-rev-hide { border: none; }' styles.textContent += '.stdrev-rev-hide > span > .t-mark-rev { display: none; }' document.head.append(styles); var rev = mw.config.get('wgTitle').indexOf('c/') === 0 ? [ 'C89', 'C99', 'C11' ] : [ 'C++98', 'C++03', 'C++11', 'C++14', 'C++17', 'C++20' ]; var select = $('<div class="vectorMenu"></div>').appendTo('#cpp-head-tools-right'); select.append('<h5><span>Std rev</span></h5>'); var list = $('<ul>').appendTo($('<div class="menu">').appendTo(select)); $.each(['DIFF'].concat(rev), function(i, v) { list.append('<li><a href="#'+v+'">'+v+'</a></li>'); }); list.on('click', 'a', function(e) { list.find('a').css('font-weight', 'normal'); $(this).css('font-weight', 'bold'); curr_rev = e.target.innerText; on_rev_changed(); }); var curr_rev = 'DIFF'; // Returns true if an element should be shown in the current revision, that is, either curr_rev is // DIFF (i.e. show all), or curr_rev is within the range [since, until). The range [since, until) // is inspected from the classes of `el`. // `el` may be the same element as the one to be shown if it has the needed classes, or it may be a // revision marker or a collection thereof (e.g. one expanded from {{mark since foo}}, or from the // {{mark since foo}}{{mark until bar}} combo). // `el` may be either a HTML element or a jQuery object. // Note that this correctly handle the case when `el` represents an empty set of elements (in which // case the element is always shown). function should_be_shown(el) { if (curr_rev === 'DIFF') return true; var curr_revid = rev.indexOf(curr_rev); var since = 0, until = rev.length; $.each(rev, function(i) { var ssince = 't-since-'+rev[i].toLowerCase().replace(/\+/g, 'x'); var suntil = 't-until-'+rev[i].toLowerCase().replace(/\+/g, 'x'); if ($(el).hasClass(ssince)) since = i; if ($(el).hasClass(suntil)) until = i; }); return since <= curr_revid && curr_revid < until; } // Called when user changes the selected revision. Inside this function, curr_rev is already set to // the value after the change. function on_rev_changed() { handle_dcl(); renumber_dcl(); handle_dsc(); handle_nv(); handle_rev(); handle_headings(); handle_list_items(); $('.t-rev-begin, .t-rev-inl').toggleClass('stdrev-rev-hide', curr_rev !== 'DIFF'); $('.t-mark-rev').each(function() { this.hidden = curr_rev !== 'DIFF'; if ($(this.nextSibling).is('br')) this.nextSibling.hidden = curr_rev !== 'DIFF'; }); } // Returns true if the jQuery object `el` contains at least one element, and all contained elements // are hidden; otherwise returns false. // This is used to hide a 'parent' or 'heading' element when all its contents are hidden. function all_hidden(el) { return $(el).length > 0 && !$(el).is(':not([hidden])'); } // Hide or show the elements expanded from the {{dcl ...}} template family. See documentation at // https://en.cppreference.com/w/Template:dcl/doc . // The dcl items (expanded from {{dcl | ... }}) may either appear alone or as children of versioned // declaration list (expanded from {{dcl rev begin | ... }}). In the latter case, the revision may // be supplied by the dcl items or by the dcl-rev (in the latter case the dcl-rev has class // t-dcl-rev-notes). // For the use of renumber_dcl(), each dcl-rev is marked as hidden if all its children dcl items // are hidden, and vice versa. function handle_dcl() { $('.t-dcl').each(function() { this.hidden = !should_be_shown(this); }); $('.t-dcl-rev').each(function() { if ($(this).is('.t-dcl-rev-notes')) { var hidden = !should_be_shown(this); this.hidden = hidden; $(this).find('.t-dcl').each(function() { this.hidden = hidden; }); } else { this.hidden = all_hidden($(this).find('.t-dcl')); } }); $('.t-dcl-begin .t-dsc-header').each(function() { var marker = $(this).find('> td > div > .t-mark-rev'); var lastheader = $(this).nextUntil(':not(.t-dsc-header)').addBack(); var elts = lastheader.nextUntil('.t-dsc-header').filter('.t-dcl, .t-dcl-rev'); this.hidden = all_hidden(elts) || !should_be_shown(marker); }); $('.t-dcl-h').each(function() { this.hidden = all_hidden($(this).nextUntil(':not(.t-dcl, .t-dcl-rev)')); }); } // Ensure that each visible dcl item in a dcl list is contiguously numbered, and rewrite mentions // to these numbers to use the modified numbering. // If a list item (e.g. those expanded from @m@) contains no number after the rewrite (i.e. it's // inapplicable in current revision), it is hidden. // Note that the use of '~ * .t-li, ~ * .t-v' effectively establishes a kind of scoping: only // numbers that appear after the dcl list and are more nested in the DOM hierarchy are affected // by the renumbering. // Requires that handle_dcl() has been called. function renumber_dcl() { $('.t-dcl-begin').each(function() { var numbering_map = []; var i = 0; $(this).find('.t-dcl, .t-dcl-rev').each(function() { var num_cell; if ($(this).is('.t-dcl')) num_cell = $(this).children('td:nth-child(2)'); else num_cell = $(this).find('> tr.t-dcl-rev-aux > td:nth-child(2)'); var number_text = /\s*\((\d+)\)\s*/.exec(num_cell.text()); if (!num_cell.attr('data-orig-num') && number_text) num_cell.attr('data-orig-num', number_text[1]); var original_num = num_cell.attr('data-orig-num'); if (original_num) { if (! numbering_map[original_num]) numbering_map[original_num] = $(this).is('[hidden]') ? null : ++i; num_cell.text('('+numbering_map[original_num]+')'); } }); $(this).find('~ * .t-li, ~ * .t-v').each(function() { if (! $(this).attr('data-orig-v')) $(this).attr('data-orig-v', $(this).text().replace(/[()]/g, '')); var original_numbers = []; $.each($(this).attr('data-orig-v').split(','), function(i, v) { var match = /(\d+)(?:-(\d+))?/.exec(v); if (match[2]) for (var i = +match[1]; +i <= +match[2]; ++i) original_numbers.push(i); else original_numbers.push(match[1]); }); var numbers = $.map(original_numbers, function(x) { return numbering_map[x]; }); var s = []; for (var i = 0; i < numbers.length; ++i) { if (numbers[i+1] - numbers[i] === 1 && numbers[i+2] - numbers[i+1] === 1) { var begin = numbers[i]; while (numbers[i+1] - numbers[i] === 1) ++i; s.push(begin+'-'+numbers[i]); } else { s.push(numbers[i]); } } if ($(this).is('.t-li')) { this.parentElement.hidden = numbers.length === 0; $(this).text(s.join(',')+')'); } else $(this).text('('+s.join(',')+')'); }); }); } // Hide or show the elements expanded from the {{dsc ...}} template family. See documentation at // https://en.cppreference.com/w/Template:dcl/doc . // The revision markers are in the first cell of each dsc item. In the general case, the visibility // of a dsc item is control by a single revision marker. But if a specialized template is used, // and the amount of entity names in the first cell matches the lines of the revision markers, // then each line controls the visibility of a single entity name, and the dsc item is hidden only // if all the entity names are hidden. // If all the dsc items are hidden, then the corresponding headings are hidden as well. function handle_dsc() { $('.t-dsc').each(function() { var member = $(this).find('.t-dsc-member-div'); if (member[0]) { var lines = member.find('> div:nth-child(2) > .t-lines').children(); var mems = member.find('> div:first-child .t-lines').children(); if (lines.length !== mems.length) this.hidden = !should_be_shown(lines.children('.t-mark-rev')); else { lines.each(function(i) { var marker = $(this).children('.t-mark-rev'); mems[i].hidden = !should_be_shown(marker); marker.hidden = !should_be_shown(marker); }); this.hidden = all_hidden(mems); } } else { var marker = $(this).find('> td:first-child > .t-mark-rev'); this.hidden = !should_be_shown(marker); } }); $('.t-dsc .t-dsc-header').each(function() { var marker = $(this).find('> td > div > .t-mark-rev'); var lastheader = $(this).nextUntil(':not(.t-dsc-header)').addBack(); this.hidden = all_hidden(lastheader.nextUntil(':not(.t-dsc)')) || !should_be_shown(marker); }); var heading_selector = ['tr:has(> td > h5)', 'tr:has(> td > h3)']; $.each(heading_selector, function(i, selector) { $(selector).each(function() { var section = $(this).nextUntil(heading_selector.slice(i).join(',')); this.hidden = all_hidden(section.filter('.t-dsc')); }); }); $('.t-dsc-begin').each(function() { this.hidden = all_hidden($(this).find('.t-dsc')); }); } // Hide or show the navbar elements expanded from the {{nv ...}} template family. See documentation // at https://en.cppreference.com/w/Template:nv/doc . // A line of revision marker only controls a single entity name, even if it's expanded from // {{nv ln | ... }} that contains multiple lines. // If a heading contains a revision marker, that revision marker controls the visibility of the // heading and its corresponding contents; otherwise the heading is hidden when it is followed by // content elements, and all of them are hidden. function handle_nv() { $('.t-nv').each(function() { var marker = $(this).find('> td > .t-mark-rev'); this.hidden = !should_be_shown(marker); }); $('.t-nv-ln-table').each(function() { var lines = $(this).find('> div:nth-child(2) > .t-lines').children(); var mems = $(this).find('> div:first-child .t-lines').children(); lines.each(function(i) { var marker = $(this).children('.t-mark-rev'); if (mems[i]) mems[i].hidden = !should_be_shown(marker); marker.hidden = !should_be_shown(marker); }); this.hidden = all_hidden(mems); }); var heading_selector = ['.t-nv-h2', '.t-nv-h1']; $.each(heading_selector, function(i, selector) { $(selector).each(function() { var section = $(this).nextUntil(heading_selector.slice(i).join(',')); var marker = $(this).find('> td > .t-mark-rev'); if (marker[0]) { section.each(function() { this.hidden = this.hidden || !should_be_shown(marker); }); this.hidden = !should_be_shown(marker); } this.hidden = all_hidden(section.find('.t-nv-ln-table')); }); }); } // Hide or show the elements expanded from the {{rev ...}} template family. See documentation at // https://en.cppreference.com/w/Template:dcl/doc . // Borders are handled by class stdrev-rev-hide. function handle_rev() { $('.t-rev, .t-rev-inl').each(function() { this.hidden = !should_be_shown(this); }); } // Hide or show headings. // If the heading contains a revision marker, that revision marker controls the visibility of it // and its corresponding contents; otherwise, a heuristic is made: if the contents contain a dsc // list, and its revision-related contents are hidden, then the heading and all contents are hidden // as well. // The heuristic requires that handle_dsc() and handle_rev() have been called. function handle_headings() { var heading_selector = ['h5', 'h4', 'h3', 'h2']; $.each(heading_selector, function(i, selector) { $(selector).each(function() { var section = $(this).nextUntil(heading_selector.slice(i).join(',')); var marker = $(this).find('> span > .t-mark-rev'); if (marker[0]) { section.each(function() { this.hidden = this.hidden || !should_be_shown(marker); }); this.hidden = !should_be_shown(marker); } if (section.is('.t-dsc-begin') && !section.is(':not(p, .t-rev-begin, .t-dsc-begin)')) { var revisioned_content = section.find('.t-dsc, .t-rev, .t-rev-inl'); section.each(function() { this.hidden = this.hidden || all_hidden(revisioned_content); }); this.hidden = all_hidden(revisioned_content); } }); }); } // Hide or show <li> elements based on the contained revision markers. function handle_list_items() { $('li').each(function() { var marker = $(this).children('.t-mark-rev'); this.hidden = !should_be_shown(marker); }); } })(); |
Features include:
- hide section based on revision markers in the heading
- hide <li> based on its contained revision markers
- hide "Defined in header ..." when the corresponding entities are hidden
- implement renumbering inside {{v}}
- much shorter than P12's implementation! (~300LOC vs ~1800LOC)
Does it make sense to include this as an "official" gadget?
--223.3.167.101 10:25, 3 March 2019 (PST)