fredoverflow
fredoverflow

Reputation: 263118

Does any compiler support constexpr yet?

I want to play with constexpr, does any compiler support it yet?

Upvotes: 13

Views: 9154

Answers (4)

Acmovian PL
Acmovian PL

Reputation: 1

Usage of "constexpr" is really easy. Look at this piece of code:

constexpr int get_five(){
return 5;}

This function returns always 5, so it can be declared with "constexpr" keyword. But factorial function returns value depending on argument, so its "output" is not always the same.

Upvotes: -9

Ricbit
Ricbit

Reputation: 839

As of July 2011, gcc 4.7 supports constexpr. You need to build it from svn though.

Upvotes: 4

Dennis Hunt
Dennis Hunt

Reputation: 19

Agreed, g++ 4.5 and 4.6 support the keyword, but ignore the implications. I just compiled a simple factorial program (on both versions using -std=c++0x) with the line:

constexpr fact(int i) { return (i>1) ? fact(i-1)*i : 1; }

and it compiled and ran but when examining the asm source (-S option) it showed the function was called with the parameter instead of being determined by the compiler.

Upvotes: -2

James McNellis
James McNellis

Reputation: 355049

The Apache Stdcxx project has a nice table detailing which C++0x features are supported by which compilers. It's been updated on a regular basis and covers most of the modern C++ compilers.

According to that, only GCC 4.5 supports constexpr (note that that support may be experimental).

Between that list and what has been said in the comments, it appears the answer is "no."

Upvotes: 10

Related Questions