* with -std=c++0x typeof is gone
@ 2010-01-28 6:31 Patrick Horgan
2010-01-28 6:53 ` me22
2010-01-28 6:53 ` Ian Lance Taylor
0 siblings, 2 replies; 7+ messages in thread
From: Patrick Horgan @ 2010-01-28 6:31 UTC (permalink / raw)
To: GCC-help
In a templated class we define our difference type like this:
typedef typeof(T() - T()) differenceType;
How simple, how elegant, but typeof is not part of the C++ standard, and
isn't available when we use -std=c++0x. Other than using
specializations for each type that we might use with this class, is
there some other equivalently simple way to do this?
Patrick
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with -std=c++0x typeof is gone
2010-01-28 6:31 with -std=c++0x typeof is gone Patrick Horgan
@ 2010-01-28 6:53 ` me22
2010-01-28 8:43 ` Patrick Horgan
2010-01-28 6:53 ` Ian Lance Taylor
1 sibling, 1 reply; 7+ messages in thread
From: me22 @ 2010-01-28 6:53 UTC (permalink / raw)
To: phorgan1; +Cc: GCC-help
On 28 January 2010 01:31, Patrick Horgan <phorgan1@yahoo.com> wrote:
> In a templated class we define our difference type like this:
>
> typedef typeof(T() - T()) differenceType;
>
That works? Wouldn't it give unsigned when T is unsigned?
> How simple, how elegant, but typeof is not part of the C++ standard, and
> isn't available when we use -std=c++0x. Other than using specializations
> for each type that we might use with this class, is there some other
> equivalently simple way to do this?
>
I assume that decltype can do it.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2115.pdf
~ Scott
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with -std=c++0x typeof is gone
2010-01-28 6:31 with -std=c++0x typeof is gone Patrick Horgan
2010-01-28 6:53 ` me22
@ 2010-01-28 6:53 ` Ian Lance Taylor
1 sibling, 0 replies; 7+ messages in thread
From: Ian Lance Taylor @ 2010-01-28 6:53 UTC (permalink / raw)
To: phorgan1; +Cc: GCC-help
Patrick Horgan <phorgan1@yahoo.com> writes:
> In a templated class we define our difference type like this:
>
> typedef typeof(T() - T()) differenceType;
>
> How simple, how elegant, but typeof is not part of the C++ standard,
> and isn't available when we use -std=c++0x. Other than using
> specializations for each type that we might use with this class, is
> there some other equivalently simple way to do this?
g++ should support __typeof__ even with -std=c++0x.
Ian
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with -std=c++0x typeof is gone
2010-01-28 6:53 ` me22
@ 2010-01-28 8:43 ` Patrick Horgan
2010-01-28 22:06 ` me22
0 siblings, 1 reply; 7+ messages in thread
From: Patrick Horgan @ 2010-01-28 8:43 UTC (permalink / raw)
To: me22; +Cc: GCC-help
me22 wrote:
> On 28 January 2010 01:31, Patrick Horgan <phorgan1@yahoo.com> wrote:
>
>> In a templated class we define our difference type like this:
>>
>> typedef typeof(T() - T()) differenceType;
>>
>>
>
> That works? Wouldn't it give unsigned when T is unsigned?
>
Yeah, that's a problem! Love the decltype solution, but it does the
same. So gcc chooses between typeof and decltype with #ifdef
__GXX_EXPERIMENTAL_CXX0X__
Anyone know if that's always set for -std=c++0x?
Patrick
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with -std=c++0x typeof is gone
2010-01-28 8:43 ` Patrick Horgan
@ 2010-01-28 22:06 ` me22
[not found] ` <4B620CAB.40407@yahoo.com>
0 siblings, 1 reply; 7+ messages in thread
From: me22 @ 2010-01-28 22:06 UTC (permalink / raw)
To: phorgan1; +Cc: GCC-help
On 28 January 2010 03:42, Patrick Horgan <phorgan1@yahoo.com> wrote:
> me22 wrote:
>>
>> That works? Wouldn't it give unsigned when T is unsigned?
>>
>
> Yeah, that's a problem!
>
You probably want type traits instead. In C++0x, make_signed (see
meta.trans.sign in n3000), or in boost
http://www.boost.org/libs/type_traits/doc/html/boost_typetraits/reference/make_signed.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with -std=c++0x typeof is gone
[not found] ` <4B620CAB.40407@yahoo.com>
@ 2010-01-28 22:22 ` me22
[not found] ` <4B621082.6060905@yahoo.com>
0 siblings, 1 reply; 7+ messages in thread
From: me22 @ 2010-01-28 22:22 UTC (permalink / raw)
To: phorgan1; +Cc: GCC-help
On 28 January 2010 17:16, Patrick Horgan <phorgan1@yahoo.com> wrote:
>
> So are you saying something like:
>
> typedef std::make_signed<declspec(T() - T())> difftype;
>
Just this should be sufficient:
typedef std::make_signed<T> difftype;
No need for extensions or C++0x features.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with -std=c++0x typeof is gone
[not found] ` <4B621082.6060905@yahoo.com>
@ 2010-01-29 2:08 ` me22
0 siblings, 0 replies; 7+ messages in thread
From: me22 @ 2010-01-29 2:08 UTC (permalink / raw)
To: phorgan1; +Cc: GCC-help
2010/1/28 Patrick Horgan <phorgan1@yahoo.com>:
>
> But that assumes that operator- returns the same type (possibly signed) as
> its arguments. How could you know that? The declspec(T()-T()) would take
> the return type of the (possible) operator-, no?
>
You're right; I am assuming that.
I don't know your situation. I do wonder whether even the declspec
solution would be sufficient if T used expression templates or other
such techniques, though.
~ Scott
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-01-29 2:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-28 6:31 with -std=c++0x typeof is gone Patrick Horgan
2010-01-28 6:53 ` me22
2010-01-28 8:43 ` Patrick Horgan
2010-01-28 22:06 ` me22
[not found] ` <4B620CAB.40407@yahoo.com>
2010-01-28 22:22 ` me22
[not found] ` <4B621082.6060905@yahoo.com>
2010-01-29 2:08 ` me22
2010-01-28 6:53 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).