wg21 | WG21 : C Standards Committee Papers | Blockchain library
kandi X-RAY | wg21 Summary
kandi X-RAY | wg21 Summary
The top-level of this repository contains the source code for various proposals and the generated/ directory contains the generated proposals (HTML or PDF). This repository also includes a paper-writing framework using Pandoc.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Prepare code elements .
- Generate a comparison table .
- Wrap a div element .
- Prepare documentation .
- Create a table .
- Handle header element .
wg21 Key Features
wg21 Examples and Code Snippets
Community Discussions
Trending Discussions on wg21
QUESTION
will debut in C++23 (see cppreference). According to the proposal, they are string-streams with
std::span
based buffers.
My questions are:
- Does
std::spanstream
have somewhat equivalent uses of the oldstd::strstream
(orstrstream
deprecated in C++ 98)? - What will be the benefits of using them after the full release of C++ 23?
ANSWER
Answered 2021-Jun-10 at 15:42They are intended to be a near drop-in replacement for strstream
(except with proper bounds checking). As such, they will have the exact same use cases. When you have an existing buffer that you want to stream into/outof.
The ability to move a std::string
into stringstream
s added in C++20 eliminated the use case when the existing buffer is in a std::string
. But sometimes you just have a naked char const*
with a known length.
QUESTION
The "Template non-type arguments" paragraph of the article „Template parameters and template arguments“ states:
The only exceptions are that non-type template parameters of reference or pointer type and non-static data members of reference or pointer type in a non-type template parameter of class type and its subobjects (since C++20) cannot refer to/be the address of
- a temporary object (including one created during reference initialization);
- a string literal;
- the result of
typeid
;- the predefined variable
__func__
;- or a subobject (including non-static class member, base subobject, or array element) of one of the above (since C++20).
Emphasis is mine.
And below there is an example
...ANSWER
Answered 2021-Jun-06 at 19:34The wording changed as part of P1907R1, which was adopted as part of C++20. Note that the first draft you cited - N4835 - predates this adoption (that draft was published Oct 2019, and this paper was adopted the following month at the Belfast meeting in Nov 2019). The closest draft to C++20 is N4861, which you can also conveniently view in html form.
As a result, the following:
QUESTION
My coworker wants to send some data represented by a type T
over a network. He does this The traditional way™ by casting the T
to char*
and sending it using a write(2)
call with a socket:
ANSWER
Answered 2021-Jun-01 at 00:28The dicey part is not so much the memory alignment, but rather the lifetime of the T
object. When you reinterpret_cast<>
memory as a T
pointer, that does not create an instance of the object, and using it as if it was would lead to Undefined Behavior.
In C++, all objects have to come into being and stop existing, thus defining their lifetime. That even applies to basic data types like int
and float
. The only exception to this is char
.
In other words, what's legal is to copy the bytes from the buffer into an already existing object, like so:
QUESTION
Violating strict-aliasing rules yields undefined behavior, e.g. when sending a struct over the network into a char buffer, and then that char pointer is C-style/std::reinterpret_cast()
casted to a struct pointer.
The C++ std::bit_cast()
function looks like it could be used to cast such pointers in an (implementation?) defined way, i.e. without violating strict-aliasing rules.
Example:
...ANSWER
Answered 2021-May-30 at 22:19Converting the pointer value is irrelevant. What matters is the object. You have a pointer to an object of type X, but the pointer's type is Y. Trying to access the object of type X through a pointer/reference to unrelated type Y is where the UB comes from.
How you obtained those pointers is mostly irrelevant. So bit_cast
is no better than reinterpret_cast
in this regard.
If there is no sockaddr_in
there, then you can't pretend that there is one. However, it's possible that implicit object creation in C++20 already solves this matter, depending on your code. If it does, then it still doesn't matter how you get the pointer.
QUESTION
Below is from an authoritative C++ proposal:
...ANSWER
Answered 2021-May-15 at 02:58Because fold expressions are... expressions. A for loop is a statement. ...
unpacking applies (with one or two exceptions) to expressions, not to statements.
QUESTION
So I have been quite looking forward to metaclasses. I then heard that it won't be in c++23, as they think we first need reflection and reification in the language before we should add metaclasses.
Looking over c++23 reflection, there appears to be reification capabilties. Are they sufficient to solve what metaclasses would do; ie, are metaclasses just syntactic sugar?
Using the current proposal, can we replicate someone writing a type like:
...ANSWER
Answered 2021-May-15 at 00:24Looking over c++23 reflection, there appears to be reification capabilties. Are they sufficient to solve what metaclasses would do; ie, are metaclasses just syntactic sugar?
Calling it C++23 reflection is... optimistic. But the answer is yes. To quote from P2237:
metaclasses are just syntactic sugar on top of the features described [earlier]
As the paper points out, the metaclass syntax:
QUESTION
Here is an example from temp.deduct.partial.
...ANSWER
Answered 2021-May-12 at 14:01CWG1395 does not appear to change anything related to the example you cited from the standard. Keep in mind that CWG1935 was issued to allow for e.g.
QUESTION
On my application, I receive two signed 32-bit int
and I have to store them. I have to create a sort of counter and I don't know when it will be reset, but I'll receive big values and frequently. Beacause of that, in order to store these values, I decided to use two unsigned 64-bit int
.
The following could be a simple version of the counter.
...ANSWER
Answered 2021-May-07 at 14:40A little background, just for reference: binary operators such arithmetic addition work on operands of the same type (the specific CPU instruction to which is translated depends on the number representation that must be the same for both instruction operands). When you write something like this (using fixed width integer types to be explicit):
QUESTION
I have an std::function
object that many threads access. Threads can can change the function it points to (through its copy constructor) and can call the function it points to.
So, my question is, that in what ways is the std::function
object itself thread safe? I'm not talking about the function it points to/calls, I'm talking about the std::function object itself.
There are surprisingly only a few sites on the internet that talk about this, and all of them (what I encountered) talk about the function it points to, not the object itself.
These are the main sites I've read:
Does std::function lock a mutex when calling an internal mutable lambda?
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4348.html
If you read them, you can see that none of them talk about the safety of the std::function object itself.
According to the second answer on this page, the STL library is thread safe in these cases:
simultaneous reads of the same object are OK
simultaneous read/writes of different objects are OK
Based on this, when I'm setting the function the std::function
object points to, for this use case the std::function
object is not thread safe. But I'm asking just in case it is, because according to this question's answer, it has some kind of internal mutex.
So, what way can I make it thread safe? One option would be using mutexes, but that won't fully work due to the example demonstrated below:
Suppose I have an std::function
object func
and std::mutex m
to protect func. I lock m and call the function (to protect other threads from setting func while the function it points to is being called) and will unlock m when the function exits. Lets say this function call will take very long. This way, when one thread wants to set func, it will attempt to lock the mutex, but will be blocking until the latter function call exits. What can I do in this case?
I thought of using a pointer that will point to an std::function object. This way, I will use the mutex to protect this pointer and when I will make a function call, I lock the mutex just for getting retrieving the function object from the pointer.
...ANSWER
Answered 2021-May-04 at 15:50A function object is like all other objects. Just data, and there is no built in mutexes in std::function.
If you want to protect the function with a mutex you yourself would need to create a mutex and use when interacting with function (pointing it to something else or calling it).
QUESTION
Now that GCC 11, which supports the new calendar and time zone features is released, I am trying to use these in my code.
With the following minimal example:
...ANSWER
Answered 2021-May-02 at 23:54Only partial C++20 chrono support is in gcc at this time. Here is the current state of the libstdc++ source code on this matter. This shows a simple forward declaration of utc_clock
, and no definition, which is consistent with the error message you are seeing.
I am seeing more support for file_clock
, including a low-level API to convert between file_clock::time_point
and system_clock::time_point
. This is a significant addition.
Additionally I'm seeing support for the calendrical types in C++20 (e.g. year_month_day
, etc.), which is what the release notes refers to.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install wg21
You can use wg21 like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page