std::is_signed<T>
和std::numeric_limits<T>::is_signed
都应该给出关于T
的签名的答案。
为什么现在有两个签名指示符(即从C++ 11开始)?std :: is_signed之间的区别<T>和std :: numeric_limits <T> :: is_signed?
回答
我会冒险猜测唯一的区别是如果std::numeric_limits<T>
专门为用户定义的类型。这种用户定义类型当然可以为is_signed
提供自己的值。但要求这种类型的std::is_signed<T>::value
将始终返回false
除非std::is_signed<T>
已被独立专门化。
它好像是std::is_signed<T>
代表的条件是
is_arithmetic<T>::value && T(-1) < T(0)
更新:永远在线见地霍华德Hinnant(欣南特)points out,虽然std::numeric_limits<>
可以合法,专业,没有什么<type_traits>
被允许除非另有规定,否则专门化,并且is_signed
未被指定为可专门化。
因此,std::numeric_limits<T>::is_signed
可能为用户定义类型的返回true
(如果它被专业),但std::is_signed<T>::value
将始终为用户定义类型返回false
。
您可以专注于' std :: numeric_limits
@DavidHammen:不,限制在那里,但不适用于专业化。你可以在'std'中专门化现有的模板,你不能添加你自己的东西。 – 2013-03-09 01:04:45
@DavidHammen:在命名空间'std'中完全专门化模板总是合法的,只是不能部分专门化类模板或重载函数/函数模板。 – ildjarn 2013-03-09 01:04:57
- 1. std :: regex_match和std :: regex_search之间的区别?
- 2. double.Epsilon与std :: numeric_limits <double> :: min()
- 3. std :: to_string,boost :: to_string和boost :: lexical_cast <std::string>有什么区别?
- 4. 模板和std :: numeric_limits
- 5. vector :: begin()和std :: begin()之间的区别
- 6. std :: endl和\ n之间的区别
- 7. std :: result_of和decltype之间的区别
- 8. Ruby中+和<<之间的区别
- 9. setbase(8)和std :: cout << std :: oct
- 10. C++:std :: shared_ptr <T>和std :: shared_ptr <T const>有什么区别?
- 11. std :: string name和std :: string&name之间的C++区别
- 12. 警告C4003和错误C2589和C2059:x = std :: numeric_limits <int> :: max();
- 13. std :: numeric_limits :: digits10 <float>和点后的精度
- 14. 来自标准<memory>文件的boost :: shared_ptr和std :: shared_ptr之间的区别
- 15. std :: condition_variable和std :: condition_variable_any之间有什么区别?
- 16. C++循环std :: vector <std :: map <std :: string,std :: string>>
- 17. std :: forward实现之间的区别
- 18. <%! %>与<% %>之间的区别
- 19. iterate std :: vector <std :: vector <char>>?
- 20. <s:Line>和graphics.lineTo()之间的区别
- 21. 类和类之间的区别<?>
- 22. C++ std :: vector <std :: shared_ptr>
- 23. 如何获得std :: numeric_limits <char> :: min()的值?
- 24. 部队更新TGT
- 25. std :: sort on std :: vector <std::string>
- 26. print unordered_map <std :: string,std :: list <std::string>
- 27. 在std :: vector上使用std :: unique()<std :: unordered_set <T>>
- 28. 将std :: vector <std :: pair <const K, V> *>转换为std :: vector <std :: pair <const K, V>>
- 29. 将std :: vector <std :: unique_ptr <T>>移动到std :: vector <std :: shared_ptr <T>>
- 30. std :: set和std :: vector有什么区别?
'std :: is_signed'是一种类型,而'std :: numeric_limits :: is_signed'成员只是一个值。在元编程中,让前者更方便,也更一致。 –
Xeo
2013-03-09 00:36:04
那么你实际上使用'std :: is_signed :: value'。你会直接在哪里使用'std :: is_signed '? –
2013-03-09 00:37:14
但是他们的结果是否有所不同? – smilingthax 2013-03-09 00:38:29