Questions tagged [c++20]
C++20 is the version of C++ after C++17. This tag should be used (along with the [C++] tag) for questions about C++ features specific to C++20.
c++20
5,585
questions
1
vote
0
answers
51
views
Should std::span be passed by value or const reference? [duplicate]
Should std::span be passed by value or const reference? What are the implications of either?
void MyFunction(std::span s);
// or
void MyFunction(const std::span& s);
Technically the const ...
0
votes
0
answers
54
views
Is it legal to pass two views to ranges::views::concat such that iterating on the first view will shrink the range backing up the second view?
Here's a small (ok, maybe not minimal) example
#include <range/v3/view/concat.hpp>
#include <range/v3/view/transform.hpp>
#include <unordered_set>
#include <vector>
#include &...
0
votes
0
answers
31
views
Boost.Asio how does io_context poll work and how to poll in a tight loop?
I have been playing around with Boost.Asio and I want to be able to busy poll rather than simply perform an io_context.run(). My application currently consists of 2 io_context object each running on a ...
3
votes
1
answer
51
views
Coroutine return_void; difference between co_return; and falling off the end
On cppreference I read the following (emphasis mine):
Falling off the end of the coroutine is equivalent to co_return;, except that the behavior is undefined if no declarations of return_void can be ...
-1
votes
0
answers
26
views
Template-template parameters cause linking errors when specializing `std::formatter` [duplicate]
Note: This is a follow-up to my previous question, where I figured out how to properly separate the interface and implementation of a std::formatter specialization for a non-templated custom type (TL;...
1
vote
0
answers
130
views
Why is the arrow operator not generated?
I'm trying to write an iterator Iter such that std::iterator_traits<Iter> deduces a maximum amount of information from it. To this end, if I understood correctly, Iter needs to "satisfy the ...
4
votes
1
answer
124
views
How would std::optional need to be modified in order to make it a monad via coroutines?
There's not really much when searching for c++coroutine "optional", but from the final part of this answer I'd deduce that std::optional can't be made to work with the coroutine below non-...
1
vote
1
answer
65
views
Why does separating the interface and implementation of a `std::formatter` specialization cause constraints to fail?
I was trying to specialize std::formatter<T> for a basic custom type Vector3D, but I'm receiving a compiler error. Here is a minimal reproducible example:
vector.h defines the Vector3D class and ...
2
votes
1
answer
80
views
Can you call a static constexpr member function at compile time? [duplicate]
g++ and clang++ disagree on whether I can call a static constexpr method at compile time. Here is a small program to illustrate the difference:
#include <print>
struct foo {
static constexpr ...
0
votes
3
answers
95
views
Can we call the respective original function with parameters automatically from proxy class in C++?
I have a class and a proxy class which holds pointer to original class to call its functions in C++. I am using proxy class for logging purpose . From each function of proxy class , In addition to ...
2
votes
1
answer
113
views
In GCC, inside a lambda, I can get constexpr variable from a non-constexpr template lambda, but not in Visual C++
This code compiles fine in gcc, but fail in Visual C++.
MCVE = https://godbolt.org/z/K7d5PEs65
int main(){
int localVariable=0; //some local variable
auto lamb=[&]<int s>() {
...
1
vote
2
answers
60
views
get constexpr variable from a lambda function is fine , but compile fail (Visual C++) and fine (gcc) when such statement is in a new lambda
This code compiles fine in gcc, but fail in Visual C++.
MCVE = https://wandbox.org/permlink/SqNI85EospSrwm5T
int main() {
auto func_do1Pass2=[&]() {
return 8;
};
constexpr int ...
3
votes
2
answers
89
views
Count matching elements after splitting
I want to combine std::views::split or std::views::lazy_split with std::ranges::count but I cannot get it to work.
This is what I currently have:
std::string setting;
std::string extension;
const ...
-1
votes
1
answer
57
views
Need help designing a constexpr lookup [closed]
I am developing a library to run pipelines defined at compile time. This is done for some stricter compile-time checks and works fairly well in the scenarios tried so far. Now I want to add a new kind ...
0
votes
0
answers
50
views
Suspending coroutine and resuming later in boost.Asio
In my application, I use Asio for asynchronous websockets and coroutines (custom websocket server). It works in a way that I have callback which is called when data is received and by interacting with ...