Is constexpr useful for overload

后端 未结 3 2000
有刺的猬
有刺的猬 2021-01-21 23:52

Is there a way in c++ to get a different overload called based on the runtime/compile time constness of an input? My version(12) of MSVC can\'t do this using constexpr. Reading

3条回答
  •  执笔经年
    2021-01-22 00:26

    Your code is illegal.

    [C++11, dcl.constexpr] The constexpr specifier shall be applied only to the definition of a variable, the declaration of a function or function template, or the declaration of a static data member of a literal type (3.9). ... [ Note: Function parameters cannot be declared constexpr. — end note ]

    constexpr doesn't even exist in MSVC 2013, so you couldn't try it even if you wanted to. Also, if you're wondering why the feature isn't allowed, see constexpr overloading.

提交回复
热议问题