Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #68489 > unrolled thread
| Started by | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| First post | 2019-09-18 07:37 +0000 |
| Last post | 2019-09-26 16:34 +0200 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.c++
Conversion operator to pointer-to-array Juha Nieminen <nospam@thanks.invalid> - 2019-09-18 07:37 +0000
Re: Conversion operator to pointer-to-array Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-18 08:58 -0700
Re: Conversion operator to pointer-to-array Öö Tiib <ootiib@hot.ee> - 2019-09-18 09:32 -0700
Re: Conversion operator to pointer-to-array Frederick Gotham <cauldwell.thomas@gmail.com> - 2019-09-26 00:12 -0700
Re: Conversion operator to pointer-to-array Juha Nieminen <nospam@thanks.invalid> - 2019-09-26 08:39 +0000
Re: Conversion operator to pointer-to-array Manfred <noname@add.invalid> - 2019-09-26 16:34 +0200
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2019-09-18 07:37 +0000 |
| Subject | Conversion operator to pointer-to-array |
| Message-ID | <qlsmr8$235h$2@adenine.netfront.net> |
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; }
};
[toc] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2019-09-18 08:58 -0700 |
| Message-ID | <86y2yl38bd.fsf@linuxsc.com> |
| In reply to | #68489 |
Juha Nieminen <nospam@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.
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2019-09-18 09:32 -0700 |
| Message-ID | <1598ec07-cc54-40e4-91ae-c595deb65d3f@googlegroups.com> |
| In reply to | #68489 |
On Wednesday, 18 September 2019 10:37:23 UTC+3, Juha Nieminen wrote:
> 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; }
> };
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; }
};
[toc] | [prev] | [next] | [standalone]
| From | Frederick Gotham <cauldwell.thomas@gmail.com> |
|---|---|
| Date | 2019-09-26 00:12 -0700 |
| Message-ID | <2a3db8b0-73f5-4c37-823a-c68afe13587c@googlegroups.com> |
| In reply to | #68489 |
On Wednesday, September 18, 2019 at 8:37:23 AM UTC+1, Juha Nieminen wrote:
> 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; }
> };
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];
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2019-09-26 08:39 +0000 |
| Message-ID | <qmhtg6$2fsj$1@adenine.netfront.net> |
| In reply to | #68687 |
Frederick Gotham <cauldwell.thomas@gmail.com> wrote:
> On Wednesday, September 18, 2019 at 8:37:23 AM UTC+1, Juha Nieminen wrote:
>> 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; }
>> };
>
>
> 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];
I think you answered your own question...
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2019-09-26 16:34 +0200 |
| Message-ID | <qmii9c$s2i$1@gioia.aioe.org> |
| In reply to | #68687 |
On 9/26/2019 9:12 AM, Frederick Gotham wrote:
> On Wednesday, September 18, 2019 at 8:37:23 AM UTC+1, Juha Nieminen wrote:
>> 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; }
>> };
>
>
> 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];
>
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web