szaszm commented on code in PR #1680: URL: https://github.com/apache/nifi-minifi-cpp/pull/1680#discussion_r1356699329
########## libminifi/include/utils/StringUtils.h: ########## @@ -187,48 +187,40 @@ constexpr size_t size(const std::basic_string_view<CharT>& str) noexcept { retur namespace detail { // implementation detail of join_pack -template<typename CharT> -struct str_detector { - template<typename Str> - using valid_string_t = decltype(std::declval<std::basic_string<CharT>>().append(std::declval<Str>())); +template<typename Str, typename CharT> +concept valid_string = requires(std::basic_string<CharT> left, Str appended) { + left.append(appended); }; -template<typename ResultT, typename CharT, typename... Strs> -using valid_string_pack_t = std::enable_if_t<(meta::is_detected_v<str_detector<CharT>::template valid_string_t, Strs> && ...), ResultT>; +// normally CharT would be at the end, because we're checking that Strs are valid strings for CharT, +// but the syntax needs the parameter pack at the end +template<typename CharT, typename... Strs> +concept valid_string_pack = (valid_string<Strs, CharT> && ...); -template<typename CharT, typename... Strs, valid_string_pack_t<void, CharT, Strs...>* = nullptr> -static std::basic_string<CharT> join_pack(const Strs&... strs) { - std::basic_string<CharT> result; - result.reserve((size(strs) + ...)); - (result.append(strs), ...); - return result; -} +template<typename Str> struct char_type_of_impl {}; +template<typename CharT> struct char_type_of_impl<std::basic_string<CharT>> : std::type_identity<CharT> {}; +template<typename CharT> struct char_type_of_impl<CharT*> : std::type_identity<std::remove_cv_t<CharT>> {}; Review Comment: `const char*` and `char*` are both considered strings of `char`. ########## libminifi/include/utils/StringUtils.h: ########## @@ -187,48 +187,40 @@ constexpr size_t size(const std::basic_string_view<CharT>& str) noexcept { retur namespace detail { // implementation detail of join_pack -template<typename CharT> -struct str_detector { - template<typename Str> - using valid_string_t = decltype(std::declval<std::basic_string<CharT>>().append(std::declval<Str>())); +template<typename Str, typename CharT> +concept valid_string = requires(std::basic_string<CharT> left, Str appended) { + left.append(appended); }; -template<typename ResultT, typename CharT, typename... Strs> -using valid_string_pack_t = std::enable_if_t<(meta::is_detected_v<str_detector<CharT>::template valid_string_t, Strs> && ...), ResultT>; +// normally CharT would be at the end, because we're checking that Strs are valid strings for CharT, +// but the syntax needs the parameter pack at the end +template<typename CharT, typename... Strs> +concept valid_string_pack = (valid_string<Strs, CharT> && ...); -template<typename CharT, typename... Strs, valid_string_pack_t<void, CharT, Strs...>* = nullptr> -static std::basic_string<CharT> join_pack(const Strs&... strs) { - std::basic_string<CharT> result; - result.reserve((size(strs) + ...)); - (result.append(strs), ...); - return result; -} +template<typename Str> struct char_type_of_impl {}; +template<typename CharT> struct char_type_of_impl<std::basic_string<CharT>> : std::type_identity<CharT> {}; +template<typename CharT> struct char_type_of_impl<CharT*> : std::type_identity<std::remove_cv_t<CharT>> {}; +template<typename CharT> struct char_type_of_impl<std::basic_string_view<CharT>> : std::type_identity<CharT> {}; +template<typename Str> using char_type_of = typename char_type_of_impl<std::decay_t<Str>>::type; Review Comment: Decay here is intentional: not only do we want to ignore cv-qualifiers and references, but `char` arrays should be decayed to pointers, to match the second specialization above. ########## CPPLINT.cfg: ########## @@ -1,2 +1,2 @@ set noparent -filter=-runtime/reference,-runtime/string,-build/c++11,-build/include_subdir,-whitespace/forcolon,-build/namespaces_literals,-readability/check,-build/include_what_you_use,-readability/nolint +filter=-runtime/reference,-runtime/string,-build/c++11,-build/include_subdir,-whitespace/forcolon,-build/namespaces_literals,-readability/check,-build/include_what_you_use,-readability/nolint,-readability/braces Review Comment: Got this after both concept declarations: ``` /home/szaszm/nifi-minifi-cpp-3/libminifi/include/utils/StringUtils.h:193: You don't need a ; after a } [readability/braces] [4] ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org