在模板中使用“普通” constexpr函数参数

问题描述 投票:0回答:1

假设我具有此功能:

constexpr void foo(size_t x)
{ }

以及此模板:

template<size_t X>
class bar;

如果我知道我将始终用constexpr评估该函数(C ++ 17),是否可以用foo函数中的constexpr size_t x实例化模板栏的实例?

templates c++17 constexpr
1个回答
0
投票

如果我正确理解您的要求,]:>

constexpr void foo(size_t x)
{
    bar<x> b{};
}
© www.soinside.com 2019 - 2024. All rights reserved.