fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template<typename T>
  5. constexpr typename std::remove_reference<T>::type makeprval(T && t) {
  6. return t;
  7. }
  8.  
  9. #define constexpr_or_zero(e) (noexcept(makeprval(e)) ? (e) : 0)
  10.  
  11. const int cvalue = 7;
  12. int ivalue = 7;
  13.  
  14. using type1 = std::integral_constant<int, constexpr_or_zero(cvalue)>;
  15. using type2 = std::integral_constant<int, constexpr_or_zero(ivalue)>;
  16.  
  17. int main() {
  18. std::cout << "type1::value is " << type1::value << '\n';
  19. std::cout << "type2::value is " << type2::value << '\n';
  20. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
type1::value is 7
type2::value is 0