Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make engine constexpr under c++14 and higher #75

Open
MBalszun opened this issue Mar 28, 2022 · 4 comments
Open

Make engine constexpr under c++14 and higher #75

MBalszun opened this issue Mar 28, 2022 · 4 comments

Comments

@MBalszun
Copy link

Would you be interested in a PR that makes most functions of this library constexpr? I haven't really investigated this yet, but it seems that one could just slab a CONSTEXPR_IN_ CPP14 -style macro in front of most functions.
The only tricky bit would be to make sure that this macro is restrictive enough that it doesn't accidentally add constexpr for a compiler / c++ version combination that nominally supports e.g. c++14 constexpr, but actually has an incomplete implementation which then results in a compilation error even when the function isn't used in a constexpr context.

@timoscs
Copy link

timoscs commented Jul 28, 2023

@MBalszun a potentially useful hint, if you ever get around to working on such a PR: you can't make seed constexpr as-is under anything less than C++20, since it uses placement new internally (in C++20, you can use std::construct_at which does the trick).

I know this because I'm using my own fork under C++20 and wanted constexpr functionality, but I did that without macros and tested only on GCC12 so it's not directly useful for what you're suggesting.

@MBalszun
Copy link
Author

MBalszun commented Dec 5, 2023

@timoscs: Thanks for the hint. However, I got the impression, this repo is no longer maintained anyway and I don't see any option to open PRs.

@imneme
Copy link
Owner

imneme commented Dec 5, 2023

To answer the original question, yes, I'd be interested. There is something to be said for having backwards compatibility to older versions of C++, but supporting constexpr use would be a valuable feature.

@tbxfreeware
Copy link

tbxfreeware commented Aug 31, 2024

PCG uses placement new internally

Placement-new also has the unexpected side-effect of resetting the stream. With generators such as pcg32 and pcg64, the streams you select are discarded when you call either seed() or seed(itype).

This is the subject of Issue #94, where I wrote a fuller explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants