Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Conversion operator to pointer-to-array

29 views
Skip to first unread message

Juha Nieminen

unread,
Sep 18, 2019, 3:37:23 AM9/18/19
to
Is there a way to express this without using the type alias?
This is one instance where my C++-fu isn't strong enough.

struct S
{
using DArray4 = double(*)[4];
operator DArray4() { return nullptr; }
};

Tim Rentsch

unread,
Sep 18, 2019, 11:58:40 AM9/18/19
to
Juha Nieminen <nos...@thanks.invalid> writes:

> Is there a way to express this without using the type alias?
>
> struct S
> {
> using DArray4 = double(*)[4];
> operator DArray4() { return nullptr; }
> };

There is.

Öö Tiib

unread,
Sep 18, 2019, 12:33:07 PM9/18/19
to
You may not use () or [] in type identifier of conversion operator.
It is still possible without type alias but then the solutions
that I can produce look far worse than what you had. Example:

#include <type_traits>

struct S
{
operator std::common_type_t<double(*)[4]>() { return nullptr; }
};

Frederick Gotham

unread,
Sep 26, 2019, 3:12:54 AM9/26/19
to
I'm still stuck in C++03, I haven't learned the C++11 stuff yet...

But I must ask...

Why the use of "using" above when we can simply do. . .

typedef double (*DArray4)[4];

Juha Nieminen

unread,
Sep 26, 2019, 4:39:46 AM9/26/19
to
I think you answered your own question...

Manfred

unread,
Sep 26, 2019, 10:34:34 AM9/26/19
to
In C++11 the 'using' construct can do more than this, however in this
case 'using' and typedef' are equivalent.

'Simply' is a matter of taste. In the context of C++ and later, the
'using' form is a more generic type alias declaration, which includes
template aliases.
0 new messages