0

The following is not working:

template<class charT, class traits = std::char_traits<charT> >
void f(std::basic_string_view<charT, traits> sv) {

}

int main(){
    std::basic_string_view sv = "no";//ok
    std::basic_string_view svw = L"shit";//ok

    f("sherlock");//not ok
}

I want to use the deduction guide (implicit or otherwise) of basic_string_view in the function f. How is that possible ?

4

1 回答 1

0

This isn't possible directly when combined with the function argument deduction. However it is possible by just forwarding instead:

template<class T>
void f(T&& str) {
   std::basic_string_view sv = str;//using deduction guide here
   using CharT = decltype(sv)::value_type;
}

So isolated to inside the function there isn't an issue.

于 2019-11-22T10:20:30.487 回答