ในหนังสือ "The Cpp Standard Library" ฉบับพิมพ์ครั้งที่ 2 โดย Nicolai M. Josuttis กล่าวไว้ (5.4, หน้า 125) ว่าคำจำกัดความของประเภททั่วไปของ struct มีดังนี้:
template <typename T1, typename T2>
struct common_type<T1,T2> {
typedef decltype(true ? declval<T1>() : declval<T2>()) type;
};
ฉันมีปัญหาร้ายแรงที่จะเชื่อว่านี่เป็นคำจำกัดความที่ถูกต้องของ common_type เหตุผล:
typedef decltype(true ? declval<T1>() : declval<T2>()) type;//As far as I understand this will always pick second operand, declval<T1>(), due to the fact that there is 'true' value. Am I right?
false
เช่นกัน เนื่องจากโค้ดไม่เคยทำงาน เป็นไปได้มากว่าไม่มีแม้แต่รหัสใด ๆ ที่สร้างขึ้นสำหรับสิ่งนี้ แม้กระทั่งข้อผิดพลาดที่จะมีstd::declval
ในโค้ดที่ถูกดำเนินการ - person Some programmer dude   schedule 07.11.2012common_type
นี้ส่งผลให้เกิดพฤติกรรมที่ไม่ได้ตั้งใจในบางกรณี ดูที่ รายงานข้อบกพร่อง DR2142 แต่คำตอบของ Eugene Mamin ยังคงถูกต้อง - person dyp   schedule 08.11.2012