基于方法参数的Consteval方法的返回类型

发布于 2025-02-04 08:08:57 字数 410 浏览 1 评论 0原文

考虑以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文