Skip to main content
Filter by
Sorted by
Tagged with
5 votes
1 answer
148 views

Consider the following: https://godbolt.org/z/o5r7jf4rK #include <memory> struct Ignore { constexpr Ignore(auto&& unknown_reference) {} }; struct X { constexpr bool f1() { ...
Artyer's user avatar
  • 44.2k
6 votes
2 answers
204 views

I'm trying to use C++23's explicit object parameters (as introduced in P0847R7, "Deducing this") to replace the Curiously Recurring Template Pattern (CRTP) for a simple inheritance hierarchy,...
Aaron Chifwalo Shavesha's user avatar
17 votes
0 answers
371 views

Consider the following code: struct A { void foo(this auto &&) noexcept(true) {} auto bar() -> decltype(foo()) {} }; Clang 19 rejects this code with the error below, while GCC and ...
HolyBlackCat's user avatar
4 votes
1 answer
191 views

Can comparison operators for a class in C++23 have explicit object parameter of a type distinct from the class type? Consider for example struct A { int i; constexpr bool operator==(this int x,...
Fedor's user avatar
  • 24.7k
6 votes
1 answer
162 views

In addition to an implicitly-defined copy assignment operator, if a class also defines an operator= without an lvalue-reference object parameter, which of the operators must be selected? Please ...
Fedor's user avatar
  • 24.7k
2 votes
1 answer
127 views

In C++23 a class can have explicit object member functions (with the first parameter prefixed by this), including member comparison operators. Which of them a compiler can generate automatically after ...
Fedor's user avatar
  • 24.7k
7 votes
1 answer
152 views

Below is a recursive lambda expression that can compute the values of Fibonacci sequence both in runtime and during constant evaluation: auto fib = [](this auto && f, auto && p) { ...
Fedor's user avatar
  • 24.7k
4 votes
1 answer
127 views

In the following C++23 program struct A { A() {} A(A&&) = default; void f(this A) {} void operator() (this A) {} }; int main() { A{}.f(); // ok A{}(); // Clang error ...
Fedor's user avatar
  • 24.7k
4 votes
2 answers
171 views

If one calls explicit object member function of a temporary, must the move of the temporary be elided in the explicit object parameter? Consider the following example, where struct A has move ...
Fedor's user avatar
  • 24.7k
2 votes
1 answer
122 views

In the following test program, struct B has two member functions f, which can be called using B{}.f(): one ordinary f() and another with explicit object f(this A). struct A { int f() { return 1; } ...
Fedor's user avatar
  • 24.7k
6 votes
2 answers
233 views

According to cppreference since C++23 For a non-static non-virtual member function not declared with cv-qualifier or ref-qualifier, its first parameter, if not being a function parameter pack, can be ...
Fedor's user avatar
  • 24.7k
11 votes
2 answers
740 views

There was some code floating around on Reddit that defined a member-function with an explicit this object parameter defined as type int. This made me wonder how this member-function could possibly be ...
303's user avatar
  • 4,852
7 votes
1 answer
372 views

I wrote the following program in C++23 that compiles with gcc and clang but is rejected by msvc. I want to know is this well-formed or ill-formed etc as per the standard. Live demo struct C { void ...
user avatar
2 votes
1 answer
118 views

TL;DR Is there a way to have the same code snippet (macro), that calls a given member function from another member functions, which might have both explicit or implicit object parameters? Something ...
Mikhail's user avatar
  • 22.1k
19 votes
1 answer
2k views

I recently noticed a strange issue regarding C++23 Deducing this feature. Suppose we have a struct S with a simple conversion operator: struct S { operator int() { return 42; } }; int i = S{}; ...
康桓瑋's user avatar
  • 46.8k
2 votes
3 answers
439 views

So I've run into a problem when trying to use explicit object parameters for a function pointer, for a project I'm working on. The code at a glance seems syntactically fine but as this is a new ...
Nathaniel Burchell's user avatar
5 votes
1 answer
337 views

How do I get the return type of a lambda that has a deducing this signature using std::invoke_result_t. auto lambda = [](this auto& self, int x) -> int { return x; }; auto x = std::...
Gallaros's user avatar
2 votes
2 answers
107 views

Suppose I have the following very simple class: class A { public: static constexpr A make() { return A{}; } constexpr A() : _v(0) {} constexpr A& setV(int v) { _v = v; return *this; }...
Patrick Wright's user avatar
1 vote
1 answer
138 views

One of the problems Deducing this solves is duplication by making member functions cvref aware of the cvref-ness of the object the function is being called on. By declaring Alias templates (Template ...
Aaron Chifwalo Shavesha's user avatar
0 votes
1 answer
196 views

I'm writing a hierarchy of classes of C++, let's say A, B inheriting A, C inheriting A, and D inheriting B. Now, all of these classes must have a method bar() &, whose body is: { A::foo(); ...
einpoklum's user avatar
  • 137k
14 votes
2 answers
1k views

Is it possible to perfectly forward *this object inside member functions? If yes, then how can we do it? If no, then why not, and what alternatives do we have to achieve the same effect. Please see ...
parth_07's user avatar
  • 1,428
4 votes
1 answer
248 views

From §4.2.7 of the proposal http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0847r7.html#pathological-cases It said that: These are even more unlikely to be actually useful code. In this ...
Desmond Gold's user avatar
  • 2,278
3 votes
1 answer
231 views

From declarations / functions / 9.3.4.6 / 6.2 (i apologize on how to cite the specific sentence from standard): An explicit-object-parameter-declaration is a parameter-declaration with a this ...
Desmond Gold's user avatar
  • 2,278
12 votes
1 answer
5k views

In C++23, deducing this is finally added to the standard. Based on what I've read from the proposal, it opens up a new way of creating mixins, and possible to create recursive lambdas. But I'm ...
Desmond Gold's user avatar
  • 2,278
2 votes
2 answers
1k views

P0847 proposes the possibility of using explicit this parameter for member functions. Among other great goodies that this proposal brings, there is also the great new possibility for CRTP without C, R ...
Amir Kirsh's user avatar
  • 14.4k
4 votes
2 answers
182 views

struct BananaHolder { vector<Banana>& getBananas(); const vector<Banana>& getBananas() const; }; My classes are cluttered with this kind of duplication. Is there a cleaner,...
Vittorio Romeo's user avatar
329 votes
22 answers
61k views

Let's say I have the following class X where I want to return access to an internal member: class Z { // details }; class X { std::vector<Z> vecZ; public: Z& Z(size_t index) ...
Kevin's user avatar
  • 26.2k