Namespaces
Variants
Views
Actions

Talk:Main Page/suggestions/archive 2

From cppreference.com
< Talk:Main Page‎ | suggestions
Revision as of 20:50, 18 September 2024 by T. Canens (Talk | contribs)


Contents

std::inner_product description typo?

In the first sentence of the initial description of std::inner_product, I believe std::distance(first1, first2) should be std::distance(first1, last1).

NCSUMaxPower (talk) 08:44, 5 August 2024 (PDT)

Fixed. Done --Xmcgcg (talk) 17:47, 5 August 2024 (PDT)

<type_traits> header page is missing reference_converts/constructs_from_temporary

Thanks for the great work of maintaining the website!

The "<type_traits> header page" (https://en.cppreference.com/w/cpp/header/type_traits) is missing the following entries:

The expected result is it has a similar "Supported operations" section as the "Metaprogramming library" (https://en.cppreference.com/w/cpp/meta)

Regards, Zhao

Done. --Fruderica (talk) 21:01, 25 July 2024 (PDT)

Span's Defect reports has a type

Defect report LWG 3903 unnucessary should be unnecessary

82.75.229.3 10:25, 20 July 2024 (PDT) Hupie

Fixed. Done --Xmcgcg (talk) 02:34, 21 July 2024 (PDT)

LegacyInputIterator requirements: wrong type / semantics for r

In the requirements summary for LegacyInputIterator, the expression r is introduced to have type T&, namely a reference to X's value type (where X is a supposed LegacyInputIterator), and then is described to have iterator semantics, as evidenced by the following sample that appears in the table :

T x = *r;
++r;
return x;

This doesn't make sense and is very puzzling to stumble upon. This used to be correct up until a revision on June 16th 2024: before then, r was described as an lvalue of type It, for which the above semantics made sense.

--Deqyra (talk) 00:37, 17 July 2024 (PDT)

That's quite an oversight, thanks. Fixed and improved the names so this kind of thing should be harder to allow  Done --Ybab321 (talk) 03:38, 17 July 2024 (PDT)

'}}' in page

there is a '}}' at the bottom of the page cpp/language/while

--Zyctree (talk) 05:10, 17 July 2024 (PDT)

Fixed, thanks  Done --Ybab321 (talk) 05:58, 17 July 2024 (PDT)

cpp/thread/jthread/stop suggested code change

I found the existing example somewhat misleading. I believe this change would better convey the intent.

--- before.cpp  2024-04-22 13:31:41.118514403 -0600
+++ after.cpp   2024-04-22 13:33:05.353596405 -0600
@@ -29,13 +29,9 @@
     {
         std::mutex mutex;
         std::unique_lock lock(mutex);
-        std::condition_variable_any().wait(lock, stoken,
-            [&stoken] { return false; });
-        if (stoken.stop_requested())
-        {
-            std::cout << "Waiting worker is requested to stop\n";
-            return;
-        }
+        std::condition_variable_any().wait(lock, stoken, [] { return false; });
+        std::cout << "Waiting worker is requested to stop\n";
+        return;
     });
 
     // std::jthread::request_stop() can be called explicitly:

— Preceding unsigned comment added by 73.229.98.126 (talkcontribs) 2024-04-22 13:31.

 Done, updated.) --Space Mission (talk) 14:47, 22 April 2024 (PDT)

wrong comment in example

In https://en.cppreference.com/w/c/language/operator_logical, in the first example, the comment says

int n = isspace('a'); // zero if 'a' is a space, nonzero otherwise
, but it should be the other way around (see https://en.cppreference.com/w/c/string/byte/isspace, "Non-zero value if the character is a whitespace character, zero otherwise.")

Cvttsd2si (talk) 02:20, 23 April 2024 (PDT)

Fixed, thanks  Done --Ybab321 (talk) 05:33, 23 April 2024 (PDT)

Add code example for std::chrono::hh_mm_ss constructor

Add code example for https://en.cppreference.com/w/cpp/chrono/hh_mm_ss/hh_mm_ss

#include <chrono>
#include <iostream>
 
int main() {
    auto now = std::chrono::system_clock::now();
    std::chrono::hh_mm_ss time_of_days{now - std::chrono::floor<std::chrono::days>(now)};
    std::cout << "The time of day is: " << time_of_days;
}

Possible output:

The time of the day is: 10:43:52.265396171
 Added, thanks.) --Space Mission (talk) 05:28, 24 April 2024 (PDT)

Update the libc++ URL with the current one

The current URL https://github.com/llvm-mirror/libcxx/blob/a12cb9d211019d99b5875b6d8034617cbc24c2cc/include/algorithm#L4219 for libc++ seems like quite a bit old. LLVM has moved their development tree from SVN to git about 5 years ago. Even though the logic is basically the same, it seems rather a good idea to link the current development tree.

Link: https://github.com/llvm/llvm-project/blob/8350d9c23d76fb95f42674a1563cbe8c32582dd5/libcxx/include/__algorithm/upper_bound.h#L35

Thanks.

Thanks for the link, updated  Done --Ybab321 (talk) 14:48, 24 April 2024 (PDT)

range_error copy constructor noexcept is since c++11

In range_error page,

THIS:

3) Copy constructor. If *this and other both have dynamic type std::range_error then std::strcmp(what(), other.what()) == 0. No exception can be thrown from the copy constructor.(until C++11)

SHOULD BE:

3) Copy constructor. If *this and other both have dynamic type std::range_error then std::strcmp(what(), other.what()) == 0. No exception can be thrown from the copy constructor.(since C++11)


replace "until C++11" with "since C++11". noexept is added in C++11

64.125.32.42 13:48, 24 April 2024 (PDT)

I'm actually not sure where this copy constructor comes from in the first place, noexcept or not, it doesn't seem to appear in the standard, at least not in the [diagnostics] section... If it's the implicitly generated one, then I suppose we should add the move ctor too? But even then I don't see where the noexcept comes from --Ybab321 (talk) 14:41, 24 April 2024 (PDT)
It comes from [exception]/2: "Except where explicitly specified otherwise, each standard library class T that derives from class exception has the following publicly accessible member functions, each of them having a non-throwing exception specification: [...] copy constructor." --D41D8CD98F (talk) 05:23, 26 April 2024 (PDT)
Ah, thanks :) --Ybab321 (talk) 03:55, 27 April 2024 (PDT)

 Done I removed the "until C++11" mark. For the record, the non-throwing requirement was introduced by LWG 471. --D41D8CD98F (talk) 05:34, 26 April 2024 (PDT)

Typo/small error in Class template argument deduction (CTAD)

In

Class template argument deduction (CTAD) > Deduction for class templates > Implicitly-generated deduction guides > 1st bullet point > 2nd bullet point,

there is a missing word "Fi". The sentence should read "the associated constraints of Fi are the conjunction of the associated constraints of C and the associated constraints of Ci"

174.138.232.125 06:06, 26 April 2024 (PDT)

 Fixed here. Thank you indeed.) --Space Mission (talk) 12:00, 26 April 2024 (PDT)

Replace the part about multiple subscripts for operator[] with correct `rev begin/end` and `rev|until/since` block

operator[] can only take one subscript. In order to provide multidimensional array access semantics, e.g. to implement a 3D array access a[i][j][k] = x;, operator[] has to return a reference to a 2D plane, which has to have its own operator[] which returns a reference to a 1D row, which has to have operator[] which returns a reference to the element. To avoid this complexity, some libraries opt for overloading operator() instead, so that 3D access expressions have the Fortran-like syntax a(i, j, k) = x;.

(until C++23)

operator[] can take any number of subscripts. For example, an operator[] of a 3D array class declared as T& operator[](std::size_t x, std::size_t y, std::size_t z); can directly access the elements.

(since C++23)
 Done. OK, applied, thanks.) --Space Mission (talk) 12:26, 26 April 2024 (PDT)

cpp/container/map/try_emplace:

Under "Return value", replace "that was inserted or updated" with "whose key is equivalent to `k`".

Elements are never updated. The suggested replacement matches one in the standard wording.

Addressed, thanks  Done --Ybab321 (talk) 12:49, 27 April 2024 (PDT)

cpp/types/byte

Page: cpp/types/byte

Please add:

std::byte can only compared with other std::byte value.

Not possible:

   std::byte x = 2;        // Can't be assigned
   if (x == 3) {           // Can't be compared
       int A[] = { 1, 2, 4, 8 };
       int b   = A[x];     // Can't be used as an index
   }
Done  Done --Ybab321 (talk) 07:15, 30 April 2024 (PDT)
 Added. --Space Mission (talk) 17:07, 1 May 2024 (PDT)

in owner_hash in the member function the title is owner_less instead of owner_hash

just change the owner_less to owner_hash — Preceding unsigned comment added by Shar-yashuv (talkcontribs) 12:55, 30 April 2024‎

 Done thx --Cubbi (talk) 06:13, 30 April 2024 (PDT)

Add external links to Windows/Linux locales to the (std::)setlocale pages

The `std::locale` constructor page (https://en.cppreference.com/w/cpp/locale/locale/locale) has some seemingly useful external links to lists of locale names for Windows and Linux. I suggest adding these same links to the pages for `setlocale` (https://en.cppreference.com/w/c/locale/setlocale) and `std::setlocale` (https://en.cppreference.com/w/cpp/locale/setlocale).

External links

1.  List of Windows locale names.
2.  List of Linux locale names.
 Done as you suggested.) --Space Mission (talk) 10:27, 3 May 2024 (PDT)

Allocator-aware copy constructor in AllocatorAwareContainer has wrong postcondition

Hi,

I have the feeling, that there is a mistake in [[1]]

The postcondition of

X u(t, m);

claims that

u.get_allocator() == A() must be true.


All C++ standards that I checked mention as postcondition that

u.get_allocator() == m must be true.


I therefore propose, that the postcondition of X u(t, m); is changed to:

u == t and u.get_allocator() == m are both true.

LittleHuba (talk) 08:10, 3 May 2024 (PDT)

 Fixed (per container.alloc.reqmts). Good catch, thanks.) --Space Mission (talk) 14:21, 3 May 2024 (PDT)

Wrong return types of vector::rend and array::rend

iterator rend() noexcept;
const_iterator rend() const noexcept;
const_iterator crend() const noexcept;

The return types for these function is not correct. It should be:

reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_reverse_iterator crend() const noexcept;

--Nori0815 (talk) 06:06, 5 May 2024 (PDT)

 Yep, affected pages vector::rend, array::rend have been fixed. THX! --Space Mission (talk) 13:22, 5 May 2024 (PDT)

ambiguities in https://en.cppreference.com/w/cpp/language/explicit_cast

Hello,

I believe the following statements from the page https://en.cppreference.com/w/cpp/language/explicit_cast (accessed at 6th of May, 2024) seem contradicting each other:

1)

6,7) The auto specifier is replaced with the deduced type of the invented variable x declared with auto x(expression); (which is never interpreted as a function declaration) or auto x{expression};, respectively. The result is always a prvalue of an object type.

Such a statement means that, for C++23, in "auto(s)" the keyword auto is replaced by the type deduced from the expression 's'. It also reads "never interpreted as a function declaration".

Going on in the page, in the section "Ambiguous declaration statement", there is:

2)

However, if the outermost declarator in the ambiguous declaration statement has a trailing return type, the statement will only be treated as a declaration statement if the trailing return type starts with auto:

Let us now discuss the two example cases:

A) "auto(s)()->M; // function declaration, equivalent to M s();"

B) "S(s)()->M; // expression"

According to the statements in (1), "auto(s)()->M" in case (A) should become "S(s)()->M", that is, equivalent to case (B), but the result is different (also experimented on godbolt with gcc 13.2 and option '-std=c++2b'), therefore the statement (1) should be refined.

Moreover, the statement (2) reads that the disambiguation in case of trailing return type selects a declaration only when such a type starts with auto. But, in case (A), such a type is 'M', not 'auto', against the fact that in case(A) we get a function declaration named 's'.

Finally, the statement (1) reads that with auto(expression) we should never get a declaration as result, but the case (A) proves the opposite.

Hope this helps to refine/improve the explanation in that page.

Wording (1) is copied from P0849R8, which is not adpoted into C++23 as-is. The editor report (N4902) says:
Poll LWG-8: The specification was subsequently simplified by reusing the term “placeholder type deduction”
The inaccurate wording has been fixed based on the current wording in the working draft. --Xmcgcg (talk) 04:13, 6 May 2024 (PDT)

max_align_t is not "usually" the largest scalar type

In the notes on the `max_align_t` page, it says that `max_align_t` is usually the largest scalar type on the platform, typically `long double`. Since that is *not* the case for gcc, I don't think it's a fair comment. In fact, readers should be alerted to the fact that, on gcc (using libc++), not only is `max_align_t` *not* a scalar type, it's `sizeof` is surprisingly larger than its `alignof`. I consider this a bug in libc++ (a `struct` should have been a `union`), but the standard does not require that `max_align_t` be the *smallest* type having maximum alignment.

Fixed, thanks. It wasn't a very interesting note anyway tbh  Done --Ybab321 (talk) 10:33, 7 May 2024 (PDT)

Patterns, idioms, tips and tricks

Kediaaditi30 (talk) 03:49, 10 May 2024 (PDT) Add in Patterns, idioms, tips and tricks - C++ Cheat Sheet[2]

Not a suggestion. But I will leave a personal opinion: that cheat sheet sucks. I assume it's lazily copied from a python one, because C++ has no ** or //= operator.  Done --Ybab321 (talk) 04:19, 10 May 2024 (PDT)
User:Ybab321 that was supposed to be  Not done, right? --109.178.139.220 16:52, 11 May 2024 (PDT)
Heh, yes, thank you :) --Ybab321 (talk) 14:31, 12 May 2024 (PDT)

cpp/language/reference says references to void are allowed

Just a small mistake in cpp/language/reference#Defect reports. "Allowed" should obviously be changed to "disallowed". 109.178.139.220 16:48, 11 May 2024 (PDT)

 Done yep --Cubbi (talk) 18:54, 11 May 2024 (PDT)

std::println overload 4 looks wrong

cpp/io/println

4) Equivalent to std::println(stream, "\n").

std::println(stream, "\n") will print two newlines. Should be std::println(stream, "") or std::print(stream, "\n"). (Comments on the example say former.)

--98.128.166.54 05:31, 12 May 2024 (PDT)

It should refer to std::print, now fixed.  Done --Xmcgcg (talk) 08:46, 12 May 2024 (PDT)

Wrong link to Transactional Memory TS

This diff should be reverted, it incorrectly updates from the Transactional Memory TS V2 paper to the *C++ Extensions for Concurrency V2* paper.

https://en.cppreference.com/mwiki/index.php?title=cpp/experimental&diff=157290&oldid=152301

Corrected, thanks  Done --Ybab321 (talk) 07:06, 13 May 2024 (PDT)

Add in Patterns, idioms, tips and tricks

Aditikedia (talk) 23:15, 13 May 2024 (PDT) Add in Patterns, idioms, tips and tricks - C++ tricks[3] by Programiz

 Not done We heard you the first time. Did you really need to make another account to say the same thing? --2A02:587:7E1E:1E00:7D68:2510:14C9:8672 00:45, 14 May 2024 (PDT)

fseek() return value is incorrect

The Return value description for fseek() is incorrect - https://en.cppreference.com/w/c/io/fseek

It should read:

File position indicator on success or -1L if failure occurs.

On error, the errno variable is set to implementation-defined positive value.



Citations: https://man7.org/linux/man-pages/man3/fseek.3p.htm

https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fseek-fseeki64?view=msvc-170

 Done. The POSIX requirements were appended to the Notes section. The C Standard only requires "nonzero value" on error.) --Space Mission (talk) 01:16, 14 May 2024 (PDT)

is_corresponding_member broken link

https://en.cppreference.com/w/cpp/types/is_corresponding_member

The "Standard layout" section in language/data_members was renamed to "Standard-layout", breaking the "common initial sequence" link at the top.

--155.4.128.189 02:48, 19 January 2024 (PST)

 Done. The link's been fixed. Thanks. --Space Mission (talk) 05:22, 19 January 2024 (PST)

etalon, n. 1. A Fabry-Pérot interferometer. 2. archaic. An uncastrated male horse; a stallion.

Curiously, there once was even more obsolete meaning of ‘etalon’ that fell out of use by the Late Middle English period, probably in the early 14c: 3. A castrated male sheep; a wether.

I don't have a permission to modify the pages https://en.cppreference.com/w/cpp/memory/ranges/uninitialized_default_construct and https://en.cppreference.com/w/cpp/memory/ranges/uninitialized_default_construct_n.

I would really appreciate it if anyone blessed with edit access could replace etalon in the code example with e.g., letters, abcd, or anything else that you may find more appropriate. ‘Etalon’ is clearly not a meaningful identifier. — ⋖ Cy “kkm” K. N.  ∺  talk ⋗ 03:56, 19 January 2024 (PST)

I've replaced the word etalon (one of the meaning – "standard of measurement", from early 20th century French étalon) with more neutral sample which is close enough to the originally intended meaning. Will it be good enough)? Ah, thanks anyway.)  Done --Space Mission (talk) 06:11, 19 January 2024 (PST)

Non-compiling exemple in alignas page

The page https://en.cppreference.com/w/cpp/language/alignas contains an example in which one of the lines is:

       << "alignof(cacheline) = " << alignof(alignas(64) char[64]) << '\n'

This line does not compile and if replaced by:

       << "alignof(cacheline) = " << alignof(cacheline) << '\n'

It is still a GNU extension (-Wgnu-alignof-extension)

Have a nice day

Joseph

195.68.40.4 05:56, 17 January 2024 (PST)

 Updated with type alias.) --Space Mission (talk) 14:00, 17 January 2024 (PST)

The type alias doesn't compile in Clang. From my understanding, alignas cannot be used in typedefs and usings. 240E:391:EC1:E280:0:0:0:1000 02:19, 21 July 2024 (PDT)