C++ Logo

std-proposals

Advanced search

Re: [std-proposals] concepts in <complex>

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 4 May 2022 12:04:31 -0400
On Wed, May 4, 2022 at 3:25 AM Jens Maurer via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On 04/05/2022 09.10, Abdullah Qasim via Std-Proposals wrote:
> >
> >
> > Right now, complex class is pretty WIERD:
> >
> >
> >
> > complex<char> c(‘1’, ‘2’);
>
> What's weird about this?
>
> See [complex.numbers.general] p2;
> your implementation is at liberty to make that ill-formed.
>
> > LOL.
>
> As I said in some other thread, please don't assume
> acronyms you're familiar with have any meaning for
> the diverse international audience (including non-
> native speakers) in this forum.

It should also be noted that, even for those familiar with the idioms,
the use of such idioms may be taken as a sign that the poster is just
not being serious. That is, that the suggestion is an off the cuff
idea rather than a fully-considered proposal.

>
> > Why not implement a concept in <complex.h>: (in anonymous namespace)
>
> Adding a concept to an existing template may have
> ABI impact. We need an analysis when that happens
> and how widespread the backward compatibility problems
> might be.
>
> Jens
>
>
> > template <typename T>
> >
> > concept C = std::_Is_nonbool_integral<T>() || std::is_floating_point_v<T>();

If your issue is that `char` can be used in `std::complex`, this
concept doesn't actually *fix* that problem. If the name
"`_Is_nonbool_integral`" is to be taken at face value, it's clear that
it would treat `char` as an integral type... because that's how C++
defines it.

In any case, if the goal is to forbid `char` and similar types from
being used in `std::complex`, that's a bad goal. C++ does not have a
byte-sized integral type that *isn't* some kind of `char`. Even
`std::int8_t` could be defined as a typedef of `signed char` on
platforms with 8-bit chars (ie: most of them). So this code would
break anybody who does `std::complex<std::int8_t>` on such platforms.

`char` is an integral type. That's just how C++ is. It's unfortunate
in some cases, but "fixing" that would require making major,
backwards-incompatible changes to the language. It's a non-starter.

Received on 2022-05-04 16:05:18