It's not new that IntelliSense often lags behind C++ development.
For instance, the code below is valid in C++20, using the new Template String-Literal Operator feature.
template<typename C, size_t Size>
struct StrWrapper
{
std::array<C, Size> m_buf;
consteval StrWrapper(const C(&str)[Size]) : m_buf{}
{
std::copy(str, str + Size, m_buf.begin());
}
};
template <StrWrapper c>
consteval auto operator ""_wrap()
{
return c;
}
"hello world"_wrap;
But IntelliSense will report these errors:
E2500 a literal operator template must have a template parameter list equivalent to '<char ...>'
E2486 user-defined literal operator not found
I have found others who have the same problem, there are two reports on Developer Community, the earliest one is from Jan 2021, it's been nearly two years since.
It looks like Microsoft didn't want to solve the issue since this feature is somewhat not used often, and they're still struggling with the modules.
Is there any way to work around this? I've searched for a way to disable specific errors in IntelliSense but there seems to be none. Actually, there is one but it wouldn't help in this case since every single string that uses ""_wrap
would have to be in the __INTELLISENSE__
preprocessor block.
Depending on how you use the return value of your operator afterwards, you might satisfy IntelliSense by providing a dummy implementation just for IntelliSense:
template <typename C, size_t Size>
struct StrWrapper
{
std::array<C, Size> m_buf;
consteval StrWrapper(const C (&str)[Size])
: m_buf{}
{
std::copy(str, str + Size, m_buf.begin());
}
};
#ifndef __INTELLISENSE__
template <StrWrapper c>
consteval auto operator""_wrap()
{
return c;
}
#else
// Dummy, only seen by IntelliSense.
consteval auto operator""_wrap(const char*, size_t)
{
return StrWrapper("");
}
#endif
void foo()
{
constexpr auto t = "hello world"_wrap;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With