constexpr 与编译期求值顺序
constexpr 函数不保证在编译期求值。只有在需要常量表达式的场合——数组长度、模板实参、static_assert——编译器才强制走编译期;其它情况下它可以退化成普通的函数调用。
标签
constexpr 函数不保证在编译期求值。只有在需要常量表达式的场合——数组长度、模板实参、static_assert——编译器才强制走编译期;其它情况下它可以退化成普通的函数调用。
C++ Templates Templates are C++'s mechanism for generic programming — writing code that works with any type without repeating yourself. Unlike runtime polymorphism (virtual …