wg21 | Various documents and code related to proposals for WG21
kandi X-RAY | wg21 Summary
kandi X-RAY | wg21 Summary
Work on revision R7 of linear algebra proposal P1385 is currently underway in the r7 branch.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of wg21
wg21 Key Features
wg21 Examples and Code Snippets
cd
mkdir build-dir
cd build-dir
cmake [-G ] [configuration options] ..
cmake --build . [--config ]
ctest [--config ]
cd
mkdir build-debug
cd build-debug
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
cmake --build .
ctest
cd
mkdir build-r
cd
mkdir build-win
cd build-win
cmake -G "Visual Studio 16 2019" ..
cmake --build . --config Debug
ctest -C Debug
cmake --build . --config Release
ctest -C Release
cd
mkdir build
cd build
cmake [-G ] [configuration options] -DCMAKE_INSTALL_PREFIX= ..
cmake --build . --target install
Community Discussions
Trending Discussions on wg21
QUESTION
There used to be a paragraph in the standard which stated that
...the names of a namespace-scope friend functions of a class template specialization are not visible during an ordinary lookup unless explicitly declared at namespace scope. Such names may be found under for associated classes.
ANSWER
Answered 2022-Feb-17 at 10:23From P1787R6:
Merged [temp.inject] into [temp.friend]
(Adopted in N4885 in March 2021)
The current draft (N4901) reads ([temp.friend]p2):
Friend classes, class templates, functions, or function templates can be declared within a class template. When a template is instantiated, its friend declarations are found by name lookup as if the specialization had been explicitly declared at its point of instantiation
Which seems to cover the old [temp.inject]p2
QUESTION
I'm using the SG14 flat_map
as a container.
As per a standard map, it takes Key
and Value
template parameters.
Unlike a standard map, however, it doesn't store std::pair
in a binary search tree, but rather stores the keys and values in two separate containers (additional template arguments which default to std::vector
)
ANSWER
Answered 2022-Feb-16 at 16:17Why does the combination of
const
range andconst auto&
lambda argument fail to compile, while pasing a mutable range works and taking the lambda argument by value works?
First, the operator*()
of the iterator of flat_map
is defined as follows:
QUESTION
Let's take P1907 as an example. Is it accepted into the C++ standard? To which version? When?
...ANSWER
Answered 2022-Feb-07 at 21:51The papers are managed on Github: https://github.com/cplusplus/papers/issues?q=
https://github.com/cplusplus/papers/issues/653
You can also look into the compiler compatibility page of cppreference: https://en.cppreference.com/w/cpp/compiler_support/20
QUESTION
return_void
consider the coroutine's ReturnObject
below and note the comments before the method ReturnObject::promise_type::return_void
:
ANSWER
Answered 2022-Jan-20 at 12:51[stmt.return.coroutine]/2 says that the expressions
QUESTION
I am trying to initialize a span
— that is, a list of pointers to const data.
However, the rules for const
conversion amongst pointers and span<>
's available constructors are thwarting me.
I'm sure there's a way to do it, but I cannot find the right casting/invocation.
Aside: I'm actually not using C++20, but tcb::span, which uses the older P0122R7 set of constructors, with (pointer,size) rather than iterators. But I suspect getting something working on C++20 will get me in the right direction.
The below example demonstrates what I'm trying to do, and some failed attempts at fixing it:
...ANSWER
Answered 2022-Jan-20 at 00:37What's wrong with:
QUESTION
Another question discusses the legitimacy for the optimizer to remove calls to new
: Is the compiler allowed to optimize out heap memory allocations?. I have read the question, the answers, and N3664.
From my understanding, the compiler is allowed to remove or merge dynamic allocations under the "as-if" rule, i.e. if the resulting program behaves as if no change was made, with respect to the abstract machine defined in the standard.
I tested compiling the following two-files program with both clang++ and g++, and -O1
optimizations, and I don't understand how it is allowed to to remove the allocations.
ANSWER
Answered 2022-Jan-09 at 20:34Allocation elision is an optimization that is outside of and in addition to the as-if rule. Another optimization with the same properties is copy elision (not to be confused with mandatory elision, since C++17): Is it legal to elide a non-trivial copy/move constructor in initialization?.
QUESTION
The standard defines several 'happens before' relations that extend the good old 'sequenced before' over multiple threads:
[intro.races]
11 An evaluation A simply happens before an evaluation B if either
(11.1) — A is sequenced before B, or
(11.2) — A synchronizes with B, or
(11.3) — A simply happens before X and X simply happens before B.[Note 10: In the absence of consume operations, the happens before and simply happens before relations are identical. — end note]
12 An evaluation A strongly happens before an evaluation D if, either
(12.1) — A is sequenced before D, or
(12.2) — A synchronizes with D, and both A and D are sequentially consistent atomic operations ([atomics.order]), or
(12.3) — there are evaluations B and C such that A is sequenced before B, B simply happens before C, and C is sequenced before D, or
(12.4) — there is an evaluation B such that A strongly happens before B, and B strongly happens before D.[Note 11: Informally, if A strongly happens before B, then A appears to be evaluated before B in all contexts. Strongly happens before excludes consume operations. — end note]
(bold mine)
The difference between the two seems very subtle. 'Strongly happens before' is never true for matching pairs or release-acquire operations (unless both are seq-cst), but it still respects release-acquire syncronization in a way, since operations sequenced before a release 'strongly happen before' the operations sequenced after the matching acquire.
Why does this difference matter?
'Strongly happens before' was introduced in C++20, and pre-C++20, 'simply happens before' used to be called 'strongly happens before'. Why was it introduced?
[atomics.order]/4
says that the total order of all seq-cst operations is consistent with 'strongly happens before'.
Does it mean that it's not consistent with 'simply happens before'? If so, why not?
I'm ignoring the plain 'happens before', because it differs from 'simply happens before' only in its handling of memory_order_consume
, the use of which is temporarily discouraged, since apparently most (all?) major compilers treat it as memory_order_acquire
.
I've already seen this Q&A, but it doesn't explain why 'strongly happens before' exists, and doesn't fully address what it means (it just states that it doesn't respect release-acquire syncronization, which isn't completely the case).
Found the proposal that introduced 'simply happens before'.
I don't fully understand it, but it explains following:
- 'Strongly happens before' is a weakened version of 'simply happens before'.
- The difference is only observable when seq-cst is mixed with aqc-rel on the same variable (I think, it means when an acquire load reads a value from a seq-cst store, or when an seq-cst load reads a value from a release store). But the exact effects of mixing the two are still unclear to me.
ANSWER
Answered 2022-Jan-02 at 18:21Here's my current understanding, which could be incomplete or incorrect. A verification would be appreciated.
C++20 renamed strongly happens before
to simply happens before
, and introduced a new, more relaxed definition for strongly happens before
, which imposes less ordering.
Simply happens before
is used to reason about the presence of data races in your code. (Actually that would be the plain 'happens before', but the two are equivalent in absence of consume operations, the use of which is discouraged by the standard, since most (all?) major compilers treat them as acquires.)
The weaker strongly happens before
is used to reason about the global order of seq-cst operations.
This change was introduced in proposal P0668R5: Revising the C++ memory model, which is based on the paper Repairing Sequential Consistency in C/C++11 by Lahav et al (which I didn't fully read).
The proposal explains why the change was made. Long story short, the way most compilers implement atomics on Power and ARM architectures turned out to be non-conformant in rare edge cases, and fixing the compilers had a performance cost, so they fixed the standard instead.
The change only affects you if you mix seq-cst operations with acquire-release operations on the same atomic variable (i.e. if an acquire operation reads a value from a seq-cst store, or a seq-cst operation reads a value from a release store).
If you don't mix operations in this manner, then you're not affected (i.e. can treat simply happens before
and strongly happens before
as equivalent).
The gist of the change is that the synchronization between a seq-cst operation and the corresponding acquire/release operation no longer affects the position of this specific seq-cst operation in the global seq-cst order, but the synchronization itself is still there.
This makes the seq-cst order for such seq-cst operations very moot, see below.
The proposal presents following example, and I'll try to explain my understanding of it:
QUESTION
Some ranges adaptors such as filter_view
, take_while_view
and transform_view
use std::optional
's cousin copyable-box
to store the callable object:
ANSWER
Answered 2021-Oct-09 at 14:20All the algorithms require copy-constructible function objects, and views are basically lazy algorithms.
Historically, when these adaptors were added, views were required to be copyable
, so we required the function objects to be copy_constructible
(we couldn't require copyable
without ruling out captureful lambdas). The change to make view
only require movable
came later.
It is probably possible to relax the restriction, but it will need a paper and isn't really high priority.
QUESTION
So I have code that uses std::weak_ptr
and maintains them in an std::set
, and that works just fine -- and has worked for the last 5 or 7 years. Recently I thought I'd fiddle with using them in an std::unordered_set
(well, actually in an f14::F14ValueSet
) and for that, I would need a hash of it. As of now, there is no std::hash
, so what should I do instead?
The answer seems to be "just hash the control block", as implied by this question and reply: Why was std::hash not defined for std::weak_ptr in C++0x?, but how do I get access to the control block? In glibc, it's located at __weak_ptr<>::_M_refcount._M_pi->
but that's private (and implementation specific). What else can I do?
One answer is "just wait": maybe someday there will be a standard owner_hash()
for std::weak_ptr
, but I'd prefer something available now.
ANSWER
Answered 2021-Nov-27 at 21:43Make your own augmented weak ptr.
It stores a hash value, and supports ==
based off owner_before()
.
You must make these from shared_ptr
s, as a weak ptr with no strong references cannot be hashed to match its owner; this could create two augmented weak ptrs that compare equal but hash differently.
QUESTION
I am trying to generate unique IDs from template template parameters. I tried this function
...ANSWER
Answered 2021-Nov-19 at 14:44There is no UB here. The template GetID
is instantiated once for each unique template argument, but GCC wrongly treats the alias templates as the template they alias itself, because they are equivalent here, as Davis Herring pointed out.
I think the simplest general solution is to pass the argument types in the alias templates through another alias template that makes them dependent names.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install wg21
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