Skip to content

Compilation failed with only moveable type or only copyable type #32

Open

Description

@cbegue

Hi,

First of all thanks for this great library

I can't use nonstd::expected with a non copyable type or a non moveable type can you tell me if this behavior is expected ?

You can find my test code and the compilation error here https://godbolt.org/z/o2Evdr (with gcc-9.2 and clang-8)

Thank you in advance for your answer

Activity

  1. Innokentiy-Alaytsev commented on Sep 13, 2019

    @Innokentiy-Alaytsev

    Hello!

    Same problem here. What is the motivation behind this design?

  2. Innokentiy-Alaytsev commented on Sep 13, 2019

    @Innokentiy-Alaytsev

    I've applied the following patch to my local copy to make it work with non-copyable or non-movable types.

    allow-non-copyable-and-non-movable.patch

  3. martinmoene commented on Sep 14, 2019

    @martinmoene
    Collaborator

    Likeky related to issue #29

  4. cbegue commented on Sep 16, 2019

    @cbegue
    Author

    Thanks for your patches I will test your modifications soon and give you a feedback.

  5. flexferrum commented on Oct 7, 2019

    @flexferrum

    According to this issue: jinja2cpp/Jinja2Cpp#157
    For now, nonstd::expected_lite has got no copy-constructor:

    home/travis/build/jinja2cpp/examples-build/thirdparty/Jinja2Cpp/src/statements.cpp:426:6:   required from here
    /home/travis/build/jinja2cpp/examples-build/thirdparty/variant-lite/include/nonstd/variant.hpp:1915:17: error: use of deleted function ‘nonstd::expected_lite::expected<std::shared_ptr<jinja2::TemplateImpl<char> >, jinja2::ErrorInfoTpl<char> >::expected(const nonstd::expected_lite::expected<std::shared_ptr<jinja2::TemplateImpl<char> >, jinja2::ErrorInfoTpl<char> >&)’
             return v(arg);
    

    But current wording of p0323 requires the explicit copy-ctor:

    constexpr expected(const expected&);
        constexpr expected(expected&&) noexcept(see below);
        template<class U, class G>
            explicit(see below) constexpr expected(const expected<U, G>&);
        template<class U, class G>
            explicit(see below) constexpr expected(expected<U, G>&&);
    

    Looks like the proper solution for this issue is to keep the previous version of copy-ctor (before the patch) and add extra template<class U, class G> explicit(see below) constexpr expected(const expected<U, G>& rhs); ctor with the corresponding requirements.

  6. flexferrum commented on Oct 7, 2019

    @flexferrum

    The possible solution looks like this: https://godbolt.org/z/sbB4PL

    I. e. move moveable/copyable traits handling to the storage_t class via additional template params and partial specialization. In this case expected_t will inherit this traits automatically.

  7. flexferrum commented on Oct 8, 2019

    @flexferrum

    The problem with the current implementation is perfectly described here: https://stackoverflow.com/questions/27073082/conditionally-disabling-a-copy-constructor
    (in the question)

  8. martinmoene commented on Oct 8, 2019

    @martinmoene
    Collaborator

    Thanks @flexferrum for the help & pointers. Will look at it later.

  9. prince-chrismc commented on Apr 24, 2020

    @prince-chrismc

    Would it be possible to get a 0.3.1 release with these changes? its much easier than tracking patches.

  10. martinmoene commented on Apr 24, 2020

    @martinmoene
    Collaborator

    @prince-chrismc I'll release current state as version 0.4.0, hopefully by tomorrow.

  11. prince-chrismc commented on Apr 24, 2020

    @prince-chrismc

    Wow thanks! It's greatly appreciated! Absolutely love this project ❤️

  12. martinmoene commented on Apr 24, 2020

    @martinmoene
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions