Namespaces
Variants
Views
Actions

Difference between revisions of "Talk:Main Page/suggestions"

From cppreference.com
(thread_local initialization moment is not mandated by the standard: new section)
(new expression missing exception specs: new section)
Line 277: Line 277:
  
 
[[Special:Contributions/88.207.93.70|88.207.93.70]] 01:52, 25 February 2019 (PST)
 
[[Special:Contributions/88.207.93.70|88.207.93.70]] 01:52, 25 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!
 +
[[Special:Contributions/213.68.42.195|213.68.42.195]] 03:02, 25 February 2019 (PST)

Revision as of 03:02, 25 February 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.

Contents

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 (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)
Thanks for including and improving it! --Rnsanchez (talk) 10:58, 18 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 namespace std when <cmath> is included (explicitly mentioned since C++17, implicitly mentioned in C++11/14, see also N4659, N4140 and N3337).
For std::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)

doesn't seem to be a good reason, I removed "possible" --Cubbi (talk) 08:13, 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).

updated --Cubbi (talk) 14:18, 21 February 2019 (PST)

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)

no, that's a C++98 feature. --Cubbi (talk) 06:34, 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)

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.

Adjusted. T. Canens (talk) 10:08, 23 February 2019 (PST)

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)

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)

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)