C++ Logo

std-proposals

Advanced search

Re: is_value_constructible

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sun, 2 May 2021 12:56:10 -0400
On Sun, May 2, 2021 at 12:36 PM Bjorn Reese via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I am considering proposing the addition of type traits to check if a
> type is constructible from arguments except if the argument are the
> copy/move constructors of the type.
>
> The purpose is to have a common way of writing a condition for
> templated constructors:
>
> struct alpha {
> alpha(const alpha&);
> template <typename T>
> requires(condition-that-excludes-copy-constructor)
> alpha(T&&);
> };
>

Your proposal is very confused at the moment. I recommend showing a Tony
Table: what does the code *for a real problem* look like before your
proposal, and after it?

I emphasize "for a real problem" because the code you've showed above is
not real: `alpha` is an empty struct, and you didn't provide the body of
the "value constructor," so it's not clear to the reader what it's planning
to do with the T&& it receives.

Your code snippets in the paper are also clearly wrong; e.g.

struct alpha {
    alpha(const alpha&);
    template <typename T,
        typename = std::enable_if_t<is_value_constructible_v<T>>>
    alpha(T&&);
};

implies that "is_value_constructible_v" is a property of `T` alone, whereas
I assume you meant it to depend on `alpha` as well.

In fact, from your examples, I think all you're looking for is what libc++
calls `__is_same_uncvref<T, U>` — i.e.,

template<class T, class U>
struct is_same_uncvref : is_same<remove_cvref_t<T>, remove_cvref_t<U>> {};

struct AlphableRef {
    template<class T>
        // "value-construct" from anything that's not cvref-qualified
`AlphableRef`
        requires (not is_same_uncvref<T, AlphableRef>::value)
    AlphableRef(T&& t) {

Full example (which would have to go in the paper):
https://godbolt.org/z/drhEadKT7

However, I don't see any need to standardize is_same_uncvref; it seems
trivial to write by hand.
Notice I could also have done
    requires (not same_as<remove_cvref_t<T>, AlphableRef>)
which is almost as short.

–Arthur

Received on 2021-05-02 11:56:23