我一直在浏览C ++参考上的概念库,但找不到算术类型的概念。在p0898中也找不到它。我认为这样的概念将非常有帮助。插手:
template <typename T>
T some_function(T arg) requires std::integral<T> || std::floating_point<T>
{ /* functions body */ }
Run Code Online (Sandbox Code Playgroud)
我可以做:
template <std::arithmetic T>
T some_function(T arg)
{ /* functions body */ }
Run Code Online (Sandbox Code Playgroud)
我显然可以自己定义它,这并不难(例如template <typename T> concept arithmetic = std::integral<T> || std::floating_point<T>;),但是我认为这种基本概念应该在标准库中定义。有什么充分的理由为什么它不存在?还是有任何添加建议?