I am using a sequence of string from this link: here
template<typename Char, Char... Cs>
struct char_sequence
{
static constexpr const Char c_str[] = {Cs..., 0};
};
// That template uses the extension
template<typename Char, Char... Cs>
constexpr auto operator"" _cs() -> char_sequence<Cs...> {
return {};
}
Then, I would make a call :
call_lib("Test"_cs);
where
template<char... Cs>
void call_lib(char_sequence<char, Cs...> url){
const_str(url.c_str); // this gives an error
}
// a Class from library
class const_str{
const char* const begin_;
template<unsigned N>
constexpr const_str(const char (&arr)[N]):
begin_(arr);
{
}
}
The error when constructing the class const_str
error: no matching conversion for functional-style cast from 'const char const[]' to 'const_str' const_str(url.c_str);
The complainer then complains of no matching copy constructor or move constructor (This is expected since this is not the one we need for constructing it). However, the other note from the compiler is:
note: candidate template ignored: could not match 'const char' against 'const char'
which is referring to the template constructor template<unsigned N> constexpr const_str(const char (&arr)[N])
Why is the compiler saying that it could not match const char to const char. It sounds a bit counter intuitive.
How can I solve this problem without having to edit the class const_str
CodePudding user response:
Once I fixed the many typos in your code (please don't post rubbish), the fix was simple enough.
Just change this:
constexpr auto operator"" _cs() -> char_sequence<Cs...> { ...
to this:
constexpr auto operator"" _cs() -> char_sequence<Char, Cs...> { ...
// ^^^^
and then it compiles.
Whether it does what you want or not is another thing. I didn't check that because I don't claim to understand it. And the code is specific to gcc, note, and fails to compile if you specify -pedantic-errors
as many people here recommend.