Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
1 answer
83 views

consteval member function allowed?

I have this c++20/23 code: #include <cstddef> template <size_t N> class Foo { public: consteval size_t size() noexcept { return N; } size_t real_size() { ...
HCSF's user avatar
  • 2,587
4 votes
1 answer
95 views

Why does operator() copy movable temporaries in Clang?

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
  • 19.3k
4 votes
2 answers
110 views

Move elision in explicit object member functions

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
  • 19.3k
1 vote
3 answers
110 views

Is std::move_only_function thread safe?

Is it safe to call a std::move_only_function object in one thread and replace the function it points to in another thread? My code: #include <future> #include <functional> int main() { ...
Benjamin Buch's user avatar
2 votes
1 answer
95 views

Overload resolution between ordinary and explicit object member functions

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
  • 19.3k
3 votes
1 answer
126 views

Explicit object member function with void parameter

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
  • 19.3k
0 votes
1 answer
86 views

/Fo Command Does Not Output Object When Compiling C++ std Module

Context I am using Visual Studio 2022 v17.10.4 So I am attempting to make a script to make compiling C++ programs easier for me using the Visual Studio 2022 compiler. I found a textbook about ...
Xbox 360's user avatar
4 votes
0 answers
105 views

Run time depends on code after the measured part

Consider the following C++23 program (online). #include <chrono> #include <cstdio> #include <print> constexpr size_t NWrites = 10000000000; #define DEST_STORAGE static #define ...
Dr. Gut's user avatar
  • 2,723
4 votes
1 answer
83 views

Can you call virtual methods on a base class in a union when a derived class is active?

While std::variant is great for some use cases, it's a bit analogous to std::tuple in that you can't name each individual variant. Often a struct is better than a tuple. I'm wondering if it's legal ...
user3188445's user avatar
  • 4,362
-4 votes
0 answers
108 views

Why std::flat_set etc. lack of the merge support?

I don't understand why std::flat_set etc. lack merge member functions. There's already a perfect algo for implementing it — std::ranges::merge. And I know that while de jure time complexity is ...
Adam A.C. Fox's user avatar
5 votes
1 answer
295 views

Explicit object member function discrepancies between different compilers

I wrote the following program in c++23. Here I've overloaded member functions. But for all cases different compilers give different result as shown below in comment. As you can see I have three cases ...
Alan's user avatar
  • 1,118
1 vote
0 answers
69 views

Why is Clang rejecting this coroutine code?

Here's the code: #include <generator> std::generator<int> foo() { int i{}; while (true) { co_yield i++; } } Clang 18.1.8 rejects it with /usr/bin/../lib64/gcc/x86_64-...
Enlico's user avatar
  • 26.7k
0 votes
1 answer
74 views

Is GCC correct in rejecting overload between ref-qualified and non-ref-qualified member function? [duplicate]

If I understand this correctly, [over.load] doesn't exist in c++23, and so what I read in [over.load]/2.3 should not be true anymore, so this code struct Foo { int const& bar() const; int bar()...
Enlico's user avatar
  • 26.7k
2 votes
1 answer
108 views

In C++ std::ranges, how do I build a map out of a views::join result?

I'm using GCC 14 in C+23 mode. In the following code, I create a view of views of pairs, which I then flatten with views::join and put into a vector: auto c = std::ranges::views::iota(1, 5) | ...
notsurewhattodo's user avatar
1 vote
1 answer
71 views

Calling a consteval function within if consteval causes error in non-constexpr context

The following code does not compile with g++ 14.1 or clang++ 18.1: #include <type_traits> consteval int plusone(int n) { return n+1; } constexpr int maybeplusone(int n) { if (std::...
user3188445's user avatar
  • 4,362

15 30 50 per page
1
2 3 4 5
28