0

I have a function like :

template <const char delim = ' ', typename Arg>
inline std::string jq2StlString(const Arg& arg)
{
    if constexpr (std::is_same_v<Arg, std::wstring>)
    {
        jqWideChar2StlString(arg);
    }
    else if constexpr (std::is_convertible_v<Arg, const wchar_t*>)
    {
        jqWideChar2StlString(arg);
    }
...
}

how could I match wchar_t array with different size like :

wchar_t[8]
wchar_t[3]

so on ?

tonyc
  • 41
  • 6

1 Answers1

0

You can use std::extent to get the size of a 1-dimensional array:

template <const char delim = ' ', typename Arg>
inline std::string jq2StlString(const Arg& arg)
{
    if constexpr (std::is_same_v<Arg, std::wstring>)
    {
        jqWideChar2StlString(arg);
    }
    else if constexpr (std::is_convertible_v<Arg, const wchar_t*>)
    {
      constexpr std::size_t extend = std::extent_v<Arg>;
      if constexpr (extend == 8) {
        // match wchar_t[8]
      } else if constexpr(extend == 3) {
        // match wchar_t[3]
      }
    }
}
康桓瑋
  • 33,481
  • 5
  • 40
  • 90