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

Invalid copy/move constructible/assignable detection #61

Open
deadem opened this issue Dec 2, 2020 · 1 comment
Open

Invalid copy/move constructible/assignable detection #61

deadem opened this issue Dec 2, 2020 · 1 comment

Comments

@deadem
Copy link

deadem commented Dec 2, 2020

Code:

#include <https://raw.githubusercontent.com/martinmoene/optional-lite/master/include/nonstd/optional.hpp>
#include <iostream>
#include <string>

struct A
{
    A() = default;
    A(const A &) = delete;
    A& operator=(const A &) = delete;
    A(A &&) = delete;
    A& operator=(A &&) = delete;
};

int main()
{
    std::cout << "Copy constructible: "
        << std::is_copy_constructible<A>::value << " "
        << std::is_copy_constructible<nonstd::optional<A>>::value
        << std::endl;

    std::cout << "Move constructible: "
        << std::is_move_constructible<A>::value << " "
        << std::is_move_constructible<nonstd::optional<A>>::value
        << std::endl;

    std::cout << "Copy assignable: "
        << std::is_copy_assignable<A>::value << " "
        << std::is_copy_assignable<nonstd::optional<A>>::value
        << std::endl;

    std::cout << "Move assignable: "
        << std::is_move_assignable<A>::value << " "
        << std::is_move_assignable<nonstd::optional<A>>::value
        << std::endl;
}

Output:

Copy constructible: 0 1
Move constructible: 0 1
Copy assignable: 0 1
Move assignable: 0 1

Expected output:

Copy constructible: 0 0
Move constructible: 0 0
Copy assignable: 0 0
Move assignable: 0 0

Live demo: https://godbolt.org/z/a7fhv3

@martinmoene
Copy link
Owner

martinmoene commented Apr 15, 2021

Added another demo at godbolt.

Relevant talks:

Output:

B / std::optional<B> - C++ std
Copy constructible: 00
Move constructible: 00
Copy assignable   : 00
Move assignable   : 00
Trivially destructable: 11

B / boost::optional<B> - Boost
Copy constructible: 01
Move constructible: 01
Copy assignable   : 01
Move assignable   : 01
Trivially destructable: 10

B / std::experimental::optional<B> - Andrzej Krzemieński
Copy constructible: 01
Move constructible: 01
Copy assignable   : 01
Move assignable   : 01
Trivially destructable: 11

B / tl::optional<B> - Sy Brand
Copy constructible: 00
Move constructible: 00
Copy assignable   : 00
Move assignable   : 00
Trivially destructable: 11

B / nonstd::optional<B> - this library
Copy constructible: 01
Move constructible: 01
Copy assignable   : 01
Move assignable   : 01
Trivially destructable: 10

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

No branches or pull requests

2 participants