基于方法参数的Consteval方法的返回类型
考虑以下代码:
template<typename... Arg>
class foo {
[[nodiscard]]
consteval static int stoi(std::string_view) { return 1; /* dynamically determined */ }
consteval auto argOf(std::string_view i) -> std::tuple_element_t<stoi(i),std::tuple<Arg...>>
{
/* ... */
}
};
由于Consteval输入参数必须为编译时间常数,并且Stoi保证返回值也是编译时间值,因此从这种角度来看,此类代码是否有效吗?
Consider following code:
template<typename... Arg>
class foo {
[[nodiscard]]
consteval static int stoi(std::string_view) { return 1; /* dynamically determined */ }
consteval auto argOf(std::string_view i) -> std::tuple_element_t<stoi(i),std::tuple<Arg...>>
{
/* ... */
}
};
as consteval input arguments must be compile time constants, and stoi guarantees that the return value is also compile time value, wouldn't code like this be valid from this point of view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论