Skip to content

Invalid copy/move constructible/assignable detection #61

@deadem

Description

@deadem

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

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