Jump to page: 1 25  
Page
Thread overview
Zig vs D generics
Oct 09, 2022
Walter Bright
Oct 10, 2022
Salih Dincer
Oct 10, 2022
Kagamin
Oct 10, 2022
Paulo Pinto
Oct 10, 2022
Paulo Pinto
Oct 10, 2022
Quirin Schroll
Oct 10, 2022
Paulo Pinto
Oct 11, 2022
Tejas
Oct 11, 2022
ryuukk_
Oct 11, 2022
Paulo Pinto
Oct 11, 2022
IGotD-
Oct 11, 2022
user1234
Oct 11, 2022
Paulo Pinto
Oct 12, 2022
Paulo Pinto
Oct 12, 2022
ryuukk_
Oct 12, 2022
ryuukk_
Oct 12, 2022
Adam D Ruppe
Oct 12, 2022
Sergey
Oct 12, 2022
ryuukk_
Oct 12, 2022
ryuukk_
Oct 12, 2022
ryuukk_
Oct 14, 2022
Paulo Pinto
Oct 14, 2022
Kagamin
Oct 14, 2022
wjoe
Oct 12, 2022
IGotD-
Oct 12, 2022
Tejas
Oct 10, 2022
Quirin Schroll
Oct 10, 2022
Paulo Pinto
Oct 11, 2022
Paulo Pinto
Oct 11, 2022
German Diago
October 09, 2022
https://news.ycombinator.com/item?id=33142751
October 10, 2022
On Sunday, 9 October 2022 at 21:48:38 UTC, Walter Bright wrote:
> https://news.ycombinator.com/item?id=33142751

Can we create a real derived structure with templates at compile time? Still, I remembered that there was such a thing as a static structure. What can the Zig programming language add to D?

SDB@79
October 10, 2022
>In contrast, C++ code attempting to call non-constexpr functions (i.e. functions only accessible at run time) in a constexpr context (i.e. functions which are available both at compile time and run time) will give an error at the call site.

Eh? So can C++ support an allocator that works both at compile time and at run time? I use such allocator in my D code so it's ctfeable.
October 10, 2022
On Monday, 10 October 2022 at 07:30:38 UTC, Kagamin wrote:
>>In contrast, C++ code attempting to call non-constexpr functions (i.e. functions only accessible at run time) in a constexpr context (i.e. functions which are available both at compile time and run time) will give an error at the call site.
>
> Eh? So can C++ support an allocator that works both at compile time and at run time? I use such allocator in my D code so it's ctfeable.

Depends on how much you expect from it, featurewise,

https://www.cppstories.com/2021/constexpr-new-cpp20


October 10, 2022
On Monday, 10 October 2022 at 07:30:38 UTC, Kagamin wrote:
> Eh? So can C++ support an allocator that works both at compile time and at run time? I use such allocator in my D code so it's ctfeable.

No, only encapsulated types can hold memory. This is the right approach when you don't have garbage collection. If you allow manual compile time allocation you end up with something that doesn't scale in terms of debugging.

Or you need a very advanced debugger.


October 10, 2022

On Monday, 10 October 2022 at 09:55:32 UTC, Ola Fosheim Grøstad wrote:

>

On Monday, 10 October 2022 at 07:30:38 UTC, Kagamin wrote:

>

Eh? So can C++ support an allocator that works both at compile time and at run time? I use such allocator in my D code so it's ctfeable.

No, only encapsulated types can hold memory. This is the right approach when you don't have garbage collection. If you allow manual compile time allocation you end up with something that doesn't scale in terms of debugging.

Or you need a very advanced debugger.

Argh, I couldn't make this work either in C++20. I thought std::string("hello world) should be constexpr returnable. Apparently not, unless I did something wrong. (That is a big weakness, so I really hope I did something wrong. ;-)

October 10, 2022

On Monday, 10 October 2022 at 10:23:44 UTC, Ola Fosheim Grøstad wrote:

>

On Monday, 10 October 2022 at 09:55:32 UTC, Ola Fosheim Grøstad wrote:

>

On Monday, 10 October 2022 at 07:30:38 UTC, Kagamin wrote:

>

Eh? So can C++ support an allocator that works both at compile time and at run time? I use such allocator in my D code so it's ctfeable.

No, only encapsulated types can hold memory. This is the right approach when you don't have garbage collection. If you allow manual compile time allocation you end up with something that doesn't scale in terms of debugging.

Or you need a very advanced debugger.

Argh, I couldn't make this work either in C++20. I thought std::string("hello world) should be constexpr returnable. Apparently not, unless I did something wrong. (That is a big weakness, so I really hope I did something wrong. ;-)

I guess you did something wrong, :)

https://godbolt.org/z/qKPGvbd1W

#include <string>
#include <iostream>

constexpr std::string hello() {
    return std::string("hello world");
}

int main() {
    static constexpr auto greeting = hello();

    std::cout << greeting << std::endl;
}
October 10, 2022

On Monday, 10 October 2022 at 14:18:52 UTC, Paulo Pinto wrote:

>

I guess you did something wrong, :)

Didn't work in clang for me… but good to know that it is supposed to work.

October 10, 2022

On Monday, 10 October 2022 at 16:27:11 UTC, Ola Fosheim Grøstad wrote:

>

On Monday, 10 October 2022 at 14:18:52 UTC, Paulo Pinto wrote:

>

I guess you did something wrong, :)

Didn't work in clang for me… but good to know that it is supposed to work.

I was rather sure it was supposed not to work. There is constexpr new in C++20, but memory allocated with it must be constexpr delete’d. Could be that GCC’s std::string does not allocate memory for initializing the string with a literal, but Clang does.

My advice: Don’t rely on GCC’s behavior.

October 10, 2022

On Monday, 10 October 2022 at 14:18:52 UTC, Paulo Pinto wrote:

>

I guess you did something wrong, :)

#include <string>
#include <iostream>

constexpr std::string hello() {
    return std::string("hello world");
}

int main() {
    static constexpr auto greeting = hello();

    std::cout << greeting << std::endl;
}

This only works because you initialize the std::string with a literal. It fails on this:

     return std::string("hello ") + "world";
« First   ‹ Prev
1 2 3 4 5