检查类型(a)==类型(b)还是类型(a)==类型(b带有删除的constness)
我在元素的向量存储中创建矩阵视图。
有效组合为:
vector value_type | 矩阵value_type |
---|---|
const(arithmetic) | const(arithmetic) |
(arithmetic)(arithmetic) | const(arithmetic)(arithmetic) |
(arithmetic) | (arithmetic) (arithmetic) |
so,so,一个典型的矩阵构造者可以可以是:
template<std::contiguous_iterator It>
requires(std::is_same_v<typename std::iterator_traits<It>::value_type, value_type> ||
std::is_same_v<typename std::iterator_traits<It>::value_type, std::remove_const_t<value_type>>)
matrix(It it) requires(H != -1 && view) : elements(std::to_address(it)) {}
我可以使用STD设施更短暂/简短/简短/简短?
我尝试了std :: convertible_to&lt; const double,double&amp;&gt;
用于测试并完成工作,但随后我尝试了std :: convertible_to&lt&const&const double,const int,const int&gt; /code>,并且它不会像我想要的那样失败。
I create a matrix view over a vector storage of elements.
Valid combinations are:
vector value_type | matrix value_type |
---|---|
const (arithmetic) | const (arithmetic) |
(arithmetic) | const (arithmetic) |
(arithmetic) | (arithmetic) |
So, a typical matrix constructor can be:
template<std::contiguous_iterator It>
requires(std::is_same_v<typename std::iterator_traits<It>::value_type, value_type> ||
std::is_same_v<typename std::iterator_traits<It>::value_type, std::remove_const_t<value_type>>)
matrix(It it) requires(H != -1 && view) : elements(std::to_address(it)) {}
Can I do this a little bit more brief/short/laconic with an std facility?
I tried std::convertible_to<const double, double&>
for testing and it does the job, but then I tried std::convertible_to<const double, const int&>
and it does not failed as I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想约束其参考类型可以转换为
value_type
的迭代器类型,则可以通过以下方式重写构造函数。重要的是要注意,要使约束甚至更短,
std :: iterator_traits
类型特征被std :: iter _**
组替换。If you want only to constraint iterator types whose reference type can be converted into
value_type
, it is possible to rewrite the constructor in the following way.It is important to note that, to make the constraint even shorter, the
std::iterator_traits
type trait is replaced by thestd::iter_*
group of aliases.