c++23 Questions

1

Solved

I understand that std::is_constant_evaluated() was useful to determine compile time evaluation in C++20. But since C++23 we have if consteval. However there is no mention of deprecation for std::is...
Araceli asked 2/10 at 14:3

2

Solved

I'm trying to learn C++ ranges. As far as I can see, the simplest (and the only, short of implementing a custom range view class) way to create a range view object that generates a custom sequence ...
Angers asked 30/9 at 16:44

1

Solved

I'm reading the documentation on std::expected::operator==, and apparently it's not SFINAE-friendly. Instead of "doesn't participate in overload resolution if [types are not eq-comparable]&quo...
Eward asked 20/9 at 11:16

3

Solved

Let me describe a scenario, first we have a function which returns us some sort of data which we can't be sure about the validity of, i.e. auto random_predicate() -> bool { int v = uniform_dist...
Exemplar asked 25/2, 2023 at 23:33

1

Solved

I want to implement a sequence lock in C++23. If possible, it should not rely on non-standard extensions or undefined behavior. There is the proposal P1478R8: Byte-wise atomic memcpy, which covers ...
Shirring asked 22/8 at 21:14

1

Solved

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 con...

1

I wrote the following program that compiles with EDG but is rejected by gcc, clang and msvc. Demo struct C { C(const C&&) = default; // EDG: ok, gcc: No, Clang: No }; int main() { } Afa...
Belk asked 31/7 at 16:17

1

Solved

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) { ...

2

Using -std=c++23, gcc accepts the following code while clang rejects it: struct outer { struct { int x; inline int get_x() const; } inner; }; inline int decltype(outer::inner)::get_x() const {...
Jabot asked 27/7 at 9:26

1

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 cas...
Knackwurst asked 17/7 at 7:39

7

In C++23, given: expected<A, string> getA(const X& x); expected<B, string> getB(const Y& y); C compute_all(const A& a, const B& b); Is there a way to avoid a classic s...
Geophysics asked 11/7 at 9:47

2

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 ...

1

Solved

template <typename... Ts> struct A { template <typename C> constexpr auto proc() noexcept { return C{ }; } constexpr size_t size() noexcept { return sizeof...(Ts); } }; template &lt...
Frit asked 5/7 at 10:37

1

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...

1

I understand that std::tag_invoke is not technically necessary, but what does it do? I thought the point of tag_invoke was that you could customize some::cpo for your type Foo by overloading tag_in...
Tocology asked 23/6 at 12:57

1

Solved

I'm looking for a simple example when C++ 23 auto(x) could be useful. This is what I have so far: struct A { A() = default; explicit A(const A&) {} // copy constructor }; struct B { A child;...
Jurdi asked 13/6 at 6:4

2

Solved

As we know, C++23 support Standard Library Modules. Until May 2023, MSVC support it but we need add Standard Library Modules manually as Microsoft blog mentioned. But how to use import std in CMake...
Thesaurus asked 17/5, 2023 at 3:55

1

When examining the constructors of std::tuple on the cppreference site, I came across the move constructor defined below, which is available in C++23. template< class... UTypes > constexpr tu...
Hadrian asked 5/5 at 13:42

1

Solved

As shown here, the behavior of allocate(0) is unspecified. So, what will happen if I call allocate_at_least(0) according to C++23 standard? Is the behavior implementation-defined, or will it be tre...

1

Solved

When should I use std::expected and when should I use exceptions? Take this function for example: int parse_int(std::string_view str) { if (str.empty()) { throw std::invalid_argument("string...
Diverticulum asked 12/6, 2023 at 22:16

1

Solved

I have a struct with a class member I'd like to make const because it should never be changed after the constructor: struct S { S(const double pp) : p(pp){} const double p; }; However, I ...
Titmouse asked 22/4 at 3:10

2

According to this and CMake 3.28, we should be able to import std without any extra effort. But I'm getting the error Module 'std' not found with following simple demo. import std; int main() { s...
Omnibus asked 18/10, 2023 at 19:29

4

Solved

Is there any better way to drop last element in container using c++20 ranges than reverse it twice? #include <iostream> #include <vector> #include <ranges> int main() { std::vec...
Resultant asked 31/3, 2022 at 8:15

1

Solved

I try to create a non-copyable and non-movable class, whose object construction should only be done via a create function instead of public constructors. The create function will return a std::expe...
Agbogla asked 27/3 at 10:36

3

As I know in C++17, I can write a recursive lambda like this: auto dfs = [&](const auto &self, int x) -> void { // .... self(self, x); }; dfs(dfs, 0); Unfortunately, I have to ...
Memorialist asked 15/3 at 10:17

© 2022 - 2024 — McMap. All rights reserved.