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

P0655R1 visit<R>() #201

Merged
merged 5 commits into from
Oct 26, 2019
Merged

Conversation

NathanSWard
Copy link
Contributor

@NathanSWard NathanSWard commented Oct 22, 2019

Description

This is an implementation of std::visit<R>.
Addresses issue #31

Checklist

  • I understand README.md. I also understand that acceptance of
    community PRs will be delayed until the test and CI systems are online.
  • Identifiers in product code changes are properly _Ugly as per
    https://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
  • The STL builds successfully and all tests have passed (must be manually
    verified by an STL maintainer before CI is online, leave this unchecked for
    initial submission).
  • These changes introduce no known ABI breaks (adding members, renaming
    members, adding virtual functions, changing whether a type is an aggregate
    or trivially copyable, etc.).
    I changed the underlying machinery of std::variant to not assume the return type to be _Variant_visit_result_t but rather have it be a templated parameter that is passed down by the calling std::visit function. I don't believe this causes ABI breaks, but am unsure.
  • These changes were written from scratch using only this repository and
    the C++ Working Draft as a reference (and any other cited standards).
    If they were derived from a project that's already listed in NOTICE.txt,
    that's fine, but please mention it. If they were derived from any other
    project (including Boost and libc++, which are not yet listed in
    NOTICE.txt), you must mention it here, so we can determine whether the
    license is compatible and what else needs to be done.

@NathanSWard NathanSWard requested a review from a team as a code owner October 22, 2019 21:18
@NathanSWard
Copy link
Contributor Author

NathanSWard commented Oct 22, 2019

This is the example test case I used for this implementation. It directly mimics WG21-P0655's example cases.

#include <variant>
#include <type_traits>

template <class I>
using O = I;

struct process {
    template<class I>
    constexpr auto operator()(I i) -> O<I> {
        return {};
    }
};

int main() {
    using I1 = int;
    using I2 = double;

    std::variant<I1, I2> input = {};

    auto output = std::visit<std::variant<O<I1>, O<I2>>>(process{}, input);
    auto result = std::visit<std::common_type_t<O<I1>, O<I2>>>(process{}, input);
    std::visit<void>(process{}, input);
}

stl/inc/variant Outdated Show resolved Hide resolved
@NathanSWard
Copy link
Contributor Author

"fixup"-ed typo commit to original commit to make the entire commit easier to read.

stl/inc/variant Show resolved Hide resolved
stl/inc/variant Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

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

I have only minor stylistic comments remaining. The rest looks good to me (although I am not a variant expert). Thanks!

stl/inc/variant Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
stl/inc/variant Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

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

This looks good to me as well. I'll throw some test coverage together.

@CaseyCarter
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BillyONeal
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

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

LGTM pending the usual test caveats in this repo at the moment.

stl/inc/variant Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@CaseyCarter CaseyCarter merged commit fb7dba4 into microsoft:master Oct 26, 2019
@CaseyCarter
Copy link
Member

All green to merge. Thanks, @NathanSWard - great work!

@BillyONeal
Copy link
Member

Thanks!

fengjixuchui added a commit to fengjixuchui/STL that referenced this pull request Oct 26, 2019
@NathanSWard NathanSWard deleted the variant_visit_r branch October 27, 2019 05:30
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.

6 participants