代码之家  ›  专栏  ›  技术社区  ›  fredoverflow

有编译器支持constexpr吗?

  •  12
  • fredoverflow  · 技术社区  · 15 年前

    我想和你一起玩 constexpr ,有编译器支持它吗?

    4 回复  |  直到 15 年前
        1
  •  10
  •   James McNellis    15 年前

    Apache Stdcxx项目 a nice table detailing which C++0x features are supported by which compilers

    据此,只有GCC4.5支持 constexpr

    在这份名单和评论中的说法之间,答案似乎是“不”

        2
  •  4
  •   Ricbit    14 年前

        3
  •  -2
  •   Xeo    14 年前

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

    它编译并运行,但在检查asm源(-S选项)时,它显示函数是用参数调用的,而不是由编译器确定的。

        4
  •  -9
  •   Acmovian PL    14 年前

    “constexpr”的用法非常简单。看看这段代码:

    constexpr int get_five(){
    return 5;}
    

    此函数始终返回5,因此可以用“constexpr”关键字声明它。 但阶乘函数根据参数返回值,所以它的“输出”并不总是相同的。