C ++标准库中是否存在算术类型的概念? [英] Will there be a concept for arithmetic types in C++ standard library?

查看:110
本文介绍了C ++标准库中是否存在算术类型的概念?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览 C ++参考书上的概念库,但我无法找到算术类型的概念。我也在 p0898 。我认为这样的概念将非常有帮助。
愿意这样做:

I've been looking through concepts library on C++ reference and i couldn't find a concept for arithmetic types. I couldn't also find it in p0898. I think such concept would be very helpful. Insted of doing:

template <typename T>
T some_function(T arg) requires std::integral<T> || std::floating_point<T>
{ /* functions body */ }

我可以这样做:

template <std::arithmetic T>
T some_function(T arg)
{ /* functions body */ }

我显然可以自己定义它,而且也不难(例如 template< typename T>概念算术= std :: integral< T> || std :: floating_point< T> ),但我认为此类基本概念应在标准库中定义。有什么充分的理由为什么它不存在?还是有任何建议添加它?

I could obviously define it myself and it wouldn't be hard (ex. template <typename T> concept arithmetic = std::integral<T> || std::floating_point<T>;), but in my opinion such basic concept should be defined in standard library. Is there any good reason why it's not there? Or is there any proposal to add it?

推荐答案


是否有充分的理由说明它不存在?还是有任何添加建议?

Is there any good reason why it's not there? Or is there any proposal to add it?

没有任何添加建议,但我希望看到一个NB仅提出 template< typename T>的注释概念算术= std :: is_arithmetic_v< T> :: value; (这并不保证C ++ 20将具有此概念,至少

There isn't any proposal to add it, but I would expect to see an NB comment that just proposes template <typename T> concept arithmetic = std::is_arithmetic_v<T>::value; (which doesn't guarantee that C++20 will have this concept, merely that at least it will be considered).

标准库概念由Ranges提案添加,并且受某些概念的算法需求所驱动。 积分出现了很多,但是我想算术从来没有做过,所以就从来没有添加。如果您看的是 N4382 (从2015年初开始),您可以看到 Integral (以及 SignedIntegral UnsignedIntegral )从一开始就存在...而甚至 FloatingPoint 也后来添加了。 (作者: P0631 ,于2019年7月...甚至添加了浮点概念的论文也没有提及算术

The standard library concepts were added by the Ranges proposal and were driven by needs in algorithms for certain concepts. integral comes up a lot, but I guess arithmetic never did and so it just never got added. If you look at, say, N4382 (from early 2015), you can see that Integral (and SignedIntegral and UnsignedIntegral) were there from the very beginning... whereas even FloatingPoint got added way later. (by P0631, in July 2019... and even the paper that added the floating point concept didn't make any mention of arithmetic)

当然,然后您会遇到一个有趣的问题,即它应该严格基于该类型特征还是应该 template< typename T>概念算术=积分T。 || float_point< T> ;; ,这样积分 floating_point 概念都包含算术。大概?也许?

Of course, then you get into the fun question of whether it should be based on strictly that type trait or should it be template <typename T> concept arithmetic = integral<T> || floating_point<T>; so that both the integral and floating_point concepts subsume arithmetic. Probably? Maybe?

这篇关于C ++标准库中是否存在算术类型的概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆