Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_string_view bug with suggested fix (related to issue #1282) #1539

Closed
adnsv opened this issue Jan 30, 2020 · 1 comment
Closed

to_string_view bug with suggested fix (related to issue #1282) #1539

adnsv opened this issue Jan 30, 2020 · 1 comment

Comments

@adnsv
Copy link

adnsv commented Jan 30, 2020

Custom type stringers defined with to_string_view fail to compile:

The source for this problem is in <core.h>:

template <typename S, typename = void> struct char_t_impl {};
template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
  using result = decltype(to_string_view(std::declval<S>()));
  using type = typename result::char_type;
};

In this code, result::char_type could be replaced with result::value_type, or better yet with result::traits_type::char_type.

Here is a temporary workaround that I'm using:

namespace NS {

struct MyStruct{
...
string_view sv() const {...}
...
};

inline std::string_view to_string_view(const MyStruct& v)
{
    return {v.sv()};
}
}; // namespace NS

// somewhere in the root namespace...
template <> struct fmt::internal::char_t_impl<NS::MyType> {
    using result = decltype(to_string_view(std::declval<NS::MyType>()));
    using type = typename result::traits_type::char_type;
};
@vitaut
Copy link
Contributor

vitaut commented Feb 1, 2020

Good catch, thanks! Fixed in b55ea58.

@vitaut vitaut closed this as completed Feb 1, 2020
sthagen added a commit to sthagen/fmtlib-fmt that referenced this issue Feb 2, 2020
string_view::char_type -> value_type (fmtlib#1539)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants