Skip to content

Conversation

@BillyONeal
Copy link
Member

Extracted from #1514

VCPKG_MSVC_WARNING(pop)

template<class T>
std::string adapt_to_string(const T& val)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a constexpr functor object?

constexpr struct AdaptToString
{
    template<class T>
    std::string operator()(const T& val) {
        std::string result;
        val.to_string(result);
        return result;
    }
} adapt_to_string;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe anything else would want the name adapt_to_string to require such ADL defenses?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, to put this another way: Maybe. To accomplish what?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it "better" when used in functional style like .map(adapt_to_string)

auto want_literal = to_string_literal(pgh.want);
auto state_literal = to_string_literal(pgh.state);
serialize(pgh.package, out_str);
out_str.append("Status: ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out_str.append("Status: ")
Strings::append(out_str, "Status: ", want_literal, " ok ", state_literal, "\n");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to do this because in #1514 I replaced all of this with the normal 'the way we write paragraph fields' function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillyONeal BillyONeal merged commit 9828694 into microsoft:main Oct 24, 2024
6 checks passed
@BillyONeal BillyONeal deleted the to-string-pattern branch October 24, 2024 16:45
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

Successfully merging this pull request may close these issues.

3 participants