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

Proposed changes to "Constexpr Parameters" proposal #1

Open
Nekotekina opened this issue Oct 11, 2019 · 0 comments
Open

Proposed changes to "Constexpr Parameters" proposal #1

Nekotekina opened this issue Oct 11, 2019 · 0 comments

Comments

@Nekotekina
Copy link

Hello! I hope it's okay to post it here. I'm sorry if this is not a right place for such discussions. I want the following changes to be "considered":

  1. Make constexpr function parameter mean what is currently described as "Maybe Constexpr". Possibly allow consteval function parameters with meaning "Strictly Constexpr". I believe that "maybe constexpr" is significantly more useful and flexible, and it's trivial to turn it into "strict" one by static_assert, but not the other way around.
  2. Remove overloading based on constexpr-ness of the parameters. Reasons:
  • Overloading rules are already too complex.
  • We already have if constexpr which solves many problems very elegantly. The paper provides example of implementing std::is_constant_expression with overloading. But it does not justify overloading, since std::is_constant_expression can also be implemented as a compiler builtin.
  • Overloading does not scale well. It "seems fine" if only one parameter may or may not be constexpr. But if a function has, for example, 8 such parameters, and we want to overload it based on each possible combinations, we need to provide 256 different overloads.
  1. Add consteval operator to the language, instead of std::is_constant_expression in STL. It's shorter, but there is probably no other motivation about it. The meaning remains the same.
  2. Consider adding constexpr NSDM with similar meaning to maybe constexpr parameters. At least for aggregates, it seems to combine nicely with CTAD. This is a very rough example.
template <>
struct data {
  constexpr int x;
  constexpr int y;
  constexpr int z;
};

void foo(int x, int y) {
  data x1{x, y, 0}; // Only two data members are initialized as NSDM, z is static constexpr.
  static_assert(sizeof(x1) == sizeof(int) * 2);
  static_assert(x1.z == 0);
}

Thanks!

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

1 participant