Which parts of the C++14 Standard Library could be and which parts will be made constexpr?

which parts of the Standard Library will now be marked constexpr? From the draft that I’ve looked at for C++14, N3690, the following will be changed to constexpr thus far (In comparison with the C++11 standard)†: std::error_category‘s default constructor std::forward std::move std::move_if_noexcept All of std::pair‘s operator comparisons std::get for std::pair and std::tuple. std::make_tuple All of … Read more

Constexpr is not allowed in declaration of friend template specialization?

GCC is wrong here. All references are to N4431, the latest C++ WD. [tl;dr: There’s a difference between a function being inline (or more precisely, being an inline function, as defined in 7.1.2/2) and being declared with the inline specifier. The constexpr specifier makes a function inline, but isn’t an inline specifier.] Specifiers are described … Read more

C++20 constexpr vector and string not working

Your program is actually ill-formed, though the error may be hard to understand. constexpr allocation support in C++20 is limited – you can only have transient allocation. That is, the allocation has to be completely deallocated by the end of constant evaluation. So you cannot write this: int main() { constexpr std::vector<int> v = {1, … Read more

why is there a “never use non-literal type” rule in constexpr functions?

I’m just guessing here, but can it be because being std::string s = “abc” an automatic variable and allocated in the stack at function begin (even if not yet constructed) breaks the constexpr rules? If I change the code to: using namespace std::string_literals; bool bar(std::string); template <class T> constexpr bool foo(T t) { if (t>0) … Read more

Can I use a constexpr value in a lambda without capturing it?

Should this be considered a bug in clang 3.8? Yep. A capture is only needed if [expr.prim.lambda]/12 mandates so: Note in particular the highlighted example. f(x) does not necessitate x to be captured, because it isn’t odr-used (overload resolution selects the overload with the object parameter). The same argumentation applies to your code – [basic.def.odr]/3: … Read more

Why aren’t std::algorithms constexpr and which could be?

It could be constexpr, but cannot be evaluated as a constant expression, since in this case, for example for compile-time find it is required that: begin/end should be constexpr, the * operator of the iterator should be constexpr, operator == should be constexpr, operator != for the iterator should be constexpr, operator ++ for the … Read more

Why is non-const std::array::operator[] not constexpr?

Ok, it is indeed an oversight in the standard. There even exists a proposal to fix this: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0107r0.pdf [N3598] removed the implicit marking of constexpr member functions as const. However, the member functions of std::array were not revisited after this change, leading to a surprising lack of support for constexpr in std::array’s interface. This paper … Read more

Should we use constexpr everywhere we can?

It won’t bother the compiler. The compiler will (or should anyway) give you a diagnostic when/if you use it on code that doesn’t fit the requirements of a constexpr. At the same time, I’d be a bit hesitant to just slap it on there because you could. Even though it doesn’t/won’t bother the compiler, your … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)