Skip to content

optional is "is_copy_constructible" when T is not. #54

Open

Description

@biocomp

Hi.
I encountered issues while trying to use std::vector<boost::optional<std::tuple<NonCopyable, std::function<...>>>. THis failed to compile on msvc.

Looks like it boiled down to this repro: https://godbolt.org/g/cFNcUN

#include <boost/optional.hpp>
#include <type_traits>
#include <optional>

struct NonCopyAble
{
    NonCopyAble() = default;

    NonCopyAble(const NonCopyAble&) = delete;
    NonCopyAble& operator=(const NonCopyAble&) = delete;

    NonCopyAble(NonCopyAble&&) = default;
    NonCopyAble& operator=(NonCopyAble&&) = default;
};

static_assert(!std::is_copy_constructible<NonCopyAble>::value, "NonCopyAble is_copy_constructible when shouldn't be");
static_assert(!std::is_copy_constructible<std::optional<NonCopyAble>>::value, "std::optional<NonCopyAble> is_copy_constructible when shouldn't be");    
static_assert(!std::is_copy_constructible<boost::optional<NonCopyAble>>::value, "boost::optional<NonCopyAble> is_copy_constructible when shouldn't be");    // This assert fails

Activity

  1. akrzemi1 commented on May 11, 2018

    @akrzemi1
    Member

    Thanks for the report. I will investigate. I acknowledge the divergence between std::optional and boost::optional. But in general the expectation on transitive detectable copiability is not valid:

    static_assert(!std::is_copy_constructible<std::vector<NonCopyAble>>::value,
                  "vector of this is not copyable");
  2. joergbrech commented on Mar 14, 2024

    @joergbrech

    I encountered the same issue with std::is_copy_assignable, see here: https://stackoverflow.com/q/78157267/12173376

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