Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Draft saved
Draft discarded
Cancel
8
  • 3
    A quote from this paper seems relevant to your question. We don’t propose to make constexpr applicable to function arguments because it would be meaningless for non-inline functions (the argument would be a constant, but the function wouldn’t know which) and because it would lead to complications of the overloading rules (can I overload on constexpr-ness? — no). Commented Jan 20, 2012 at 6:21
  • Another related issue that I've recently considered is this: it would be nice to combine assert with static_assert. In other words, if the compiler can determine that an assertion would fail (due to, for example, inlining), I would like for it to just let me know at compile-time rather than waiting until I encounter it at run-time. However, if it cannot determine it at compile time, I'd want just a regular assert. It seems like the easiest way to implement this would be something like if (is_constexpr (value)) static_assert (condition); else assert (condition); Commented Apr 3, 2012 at 4:15
  • if (is_constexpr (value)) static_assert (condition); else assert (condition); Dead code elimination does not work in such way. Commented May 22, 2013 at 8:07
  • 3
    I too would like this. Another example where this would be helpful is bit/population count of a bit field. Many processors include special instructions for this, so if the constexpr function is called with non-constexpr argument I'd like to use the processor instruction. But processor instructions aren't available at compile-time so I need to use another alogrithm at compile-time. Commented Jul 22, 2013 at 22:50
  • 3
    @Adam: No. I am working on a paper targeting C++23: github.com/davidstone/isocpp/blob/master/… Commented Jun 14, 2020 at 15:01

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /