Problem with basic usage of std::enable_if

后端 未结 1 1926
南笙
南笙 2021-01-22 19:12

I\'m trying to make a simple template function that given some parameters, it outputs them with a space in between. Some of those can be elements of an enum, and in that case I

相关标签:
1条回答
  • 2021-01-22 19:54

    Default template arguments are not part of the function definition. Use a dummy parameter instead, so that the second argument has a different type:

    template<typename T, typename std::enable_if_t<std::is_enum<T>::value, int> = 0>
    constexpr std::ostream& debug(const T& a) {
      std::cerr << (int)(a);
      return std::cerr;
    }
    
    template<typename T, typename std::enable_if_t<!std::is_enum<T>::value, int> = 0>
    constexpr std::ostream& debug(const T& a) {
      std::cerr << a;
      return std::cerr;
    }
    
    0 讨论(0)
提交回复
热议问题