Subject: Re: [std-proposals] Explicit using
From: Arthur O'Dwyer (arthur.j.odwyer_at_[hidden])
Date: 2021-01-15 10:11:22
On Fri, Jan 15, 2021 at 10:54 AM Yves Bailly via Std-Proposals <
> First, the "stronger type alias":
> using U = new T;
As you've realized (good!), the problems are going to be with T's existing
- std::swap(u, u)
> With this declaration:
- Any implicit conversion to T (e.g. from constructor) is also an implicit
> conversion to U.
> - There's an implicit conversion from U to T.
> - But there's no implicit conversion from T to U.
> - Any function which takes a T can also take a U, unless explicitly
> - But any function which takes a U can't take a T.
T's copy constructor is an "implicit conversion to T" â I mean, if T is
std::string and U is Name, then
T t = "Yves";
tfoo(t); // OK, implicitly calls T(const T&)
ufoo(t); // OK, would have implicitly called T(const T&), so there
must be a U(const T&) by the first bullet point quoted above
using Name = new std::string;
> void Store(std::string the_name); // (1)
> void Store(Name the_name); // (2)
> /* error */ Store("Your name here"); // ambiguous, ill-formed
FWIW, this is mildly surprising; this would be a place where
`std::is_base_of_v<T, U>` and yet the signature `void(U)` is not considered
But I think this is just an indication that your intuition about
std::is_base_of is wrong. Types with no inheritance relationships (no base
classes) definitely should *not* claim to have is_base_of relationships.
/* ok */ using Names_Income = std::unordered_map<Name, double>;
> // std::hash<std::string> used because of
> // implicit cast from Name to std::string
If there's an implicit conversion from Name to std::string, then why did
s = name;
STD-PROPOSALS list run by firstname.lastname@example.org
Standard Proposals Archives on Google Groups