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

Add support for std::string_view in wil::str_concat #505

Open
jonwis opened this issue Feb 21, 2025 · 1 comment
Open

Add support for std::string_view in wil::str_concat #505

jonwis opened this issue Feb 21, 2025 · 1 comment
Labels
feature-request New feature or request

Comments

@jonwis
Copy link
Member

jonwis commented Feb 21, 2025

I've got code that wants to combine three strings, two of which are wstring_view. It'd be nice to use wil::str_concat to build it. Right now, wil::str_concat presumes all its inputs are PCWSTR. Instead it should probably think in "view like" things internally, converting any raw pointers or pointer-holders to a counted string type.

@dunhor
Copy link
Member

dunhor commented Feb 26, 2025

Cribbing this from something else I was working on that would likely be useful here

    // Matches types like 'std::basic_string' and 'std::basic_string_view'. Given some 'value' of type 'T', the following
    // operations can be performed:
    //      value.length()
    //      value.data()
    template <typename T, typename CharT>
    struct is_string_view_like_t
    {
        template <typename U>
        static auto evaluate(U&& value, int)
            -> wistd::enable_if_t<
                wistd::conjunction_v<
                    wistd::is_same<typename U::value_type, wistd::remove_const_t<CharT>>, // Character type must match
                    wistd::is_convertible<decltype(value.data()), wistd::add_const_t<CharT>*>, // .data() exists and returns acceptable type
                    wistd::is_same<decltype(value.length()), size_t>, // .length() exists and returns correct type
                    wistd::is_same<decltype(value.find_first_of(wistd::declval<CharT>())), size_t> // Sanity check for 'basic_string' / 'basic_string_view' types
                    >,
                wistd::true_type>;

        template <typename U>
        static wistd::false_type evaluate(U&& value, ...);

        static constexpr const bool value = decltype(evaluate(wistd::declval<T>(), 0))::value;
    };

    template <typename T, typename CharT>
    constexpr const bool is_string_view_like = is_string_view_like_t<T, CharT>::value;

@dunhor dunhor added the feature-request New feature or request label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants