On Tue, Jan 18, 2022 at 12:49 PM Barry Revzin <barry.revzin@gmail.com> wrote:


On Tue, Jan 18, 2022 at 12:29 PM Peter Dimov via SG7 <sg7@lists.isocpp.org> wrote:
> But on the other hand, if you have a `char const*`, it's trivial to obtain a
> string_view from it, whereas the reverse... isn't.

<source>:9:27: error: 'std::basic_string_view<char>' is not a valid type for a template non-type parameter because it is not structural
    9 | template<std::string_view sv> consteval auto to_charp()
      |                           ^~

Yeah :-(

This is actually a good reason to return string and vector<info> instead of string_view/char const* and span<info>. The containers will be usable as non-type template parameters (eventually), but the views will never be, and while char const* could be it's also not as usable.

Barry

I take the highlighted part back, that was quite an overstep. string_view/span could certainly become usable as non-type template parameters. It's just that they would have to compare shallowly (e.g. if you have two string_view's a and b such that a == b, you could still have C<a> and C<b> be different types if a.data() != b.data()... )

Barry