On 10 May 2017 at 10:17, Daniel Santos wrote: > Maybe "constexpr" would be a better name, as it mirrors the C++11 keyword. > When I first read about C++ getting constexpr, my first thought was, "Yeah, > as if they needed yet another way to do metaprogramming!" :) However, I
Because writing functions in normal C++ is much simpler and more expressive than writing class templates and recursive partial specializations. Just because there's already one way to do something doesn't mean better ways to do it are bad. > hadn't gone so far as to investigate using this new attribute on functions > since we already have __attribute__((const)). I haven't used this before so > maybe I'm not aware of something that makes it unusable for such cases? > Which of course raises the question if __attribute__((const)) would work out > since it's only currently used on function declarations (and pointers to > function declarations, but I don't fully understand what that is doing in > handle_const_attribute). __attribute__((const)) is not a substitute for constexpr, it's not even in the same ballpark. It says the function doesn't touch global memory, it doesn't mean its return value is a constant expression, so you can't do: int f() __attribute__((const)); int f() { return 1; } int i[f()]; I don't think __attribute__((const)) is useful for your goal.