类模板参数扣除类,并带有其他非类型参数
在这种情况下,是否可以使CTAD适用于t
?
enum class boundary_type:int{inclusive, exclusive};
template<class T, boundary_type left, boundary_type right>
struct interval
{
using value_type = T;
T begin;
T end;
};
我试图添加分点指南
template<boundary_type left, boundary_type right, class T>
interval(T, T) -> interval<T, left, right>;
,但仍然有错误
模板参数数量错误(2,应为3)
尝试时
interval<boundary_type::inclusive, boundary_type::exclusive>{0, 2}
Is it possible to make CTAD work for T
in this case?
enum class boundary_type:int{inclusive, exclusive};
template<class T, boundary_type left, boundary_type right>
struct interval
{
using value_type = T;
T begin;
T end;
};
I tried to add the decuction guide
template<boundary_type left, boundary_type right, class T>
interval(T, T) -> interval<T, left, right>;
But still gets error
wrong number of template arguments (2, should be 3)
when trying
interval<boundary_type::inclusive, boundary_type::exclusive>{0, 2}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CTAD无法与明确指定的模板参数一起使用 。但是您可以使用普通模板功能来执行此操作
CTAD cannot work with the partially explicitly specified template parameter. But you can do this using normal template function
有了更多的代码,您可以通过为包含有关这些包装器提供的信息的边界信息的边界提供包装器类型来使用类似的语法:使用:
使用
With a bit more code you could allow the user to use a similar syntax by providing wrapper types for the boundaries containing information about the boundaries on information provided by those wrappers:
usage