C++11 and typeof?

35 views
Skip to first unread message

Stephan Beal

unread,
Apr 8, 2012, 8:28:12 AM4/8/12
to v8-juic...@googlegroups.com
Hi, all!

Do any of you know enough about C++11 to know whether we could convert this:

    FunctionTo< InCa, int(char const *), ::puts>::Call;

To:

    FunctionTo11< InCa, ::puts>::Call;

such that it would internally use (typeof ::puts) to dispatch to the former template?

:-?

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

Anton Yemelyanov

unread,
Apr 8, 2012, 9:05:41 AM4/8/12
to v8-juic...@googlegroups.com
Hi Stephan,

I don't seem to be able to find anything related to this...  Actually I don't seem to be able to find any reference to typeof being something that C++11 implements  (do you have any pointers?).

typeof seems to be something GCC specific that it had for a number of years now.

I did few experiments and MSVS 2010 doesn't seem to recognize this keyword at all...

Anton

n Sun, Apr 8, 2012 at 8:28 AM, Stephan Beal <sgb...@googlemail.com> wrote:
Hi, all!

Do any of you know enough about C++11 to know whether we could convert this:

    FunctionTo< InCa, int(char const *), ::puts>::Call;

To:

    FunctionTo11< InCa, ::puts>::Call;

such that it would internally use (typeof ::puts) to dispatch to the former template?

:-?

Anton Yemelyanov

unread,
Apr 8, 2012, 9:19:37 AM4/8/12
to v8-juic...@googlegroups.com
Funny... 

The very next thing I saw after sending this e-mail was "decltype".

Instead of supplying a function signature as a template argument to one of my FunctionToInCaVoid, I supplied decltype(fn) and it just worked without any questions.

So looks like you may be right, signatures can be eliminated using this...

!!!

Anton

Stephan Beal

unread,
Apr 8, 2012, 11:00:41 AM4/8/12
to v8-juic...@googlegroups.com
On Sun, Apr 8, 2012 at 3:05 PM, Anton Yemelyanov <anton.ye...@gmail.com> wrote:
Hi Stephan,

I don't seem to be able to find anything related to this...  Actually I don't seem to be able to find any reference to typeof being something that C++11 implements  (do you have any pointers?).

As it turns out - i just read that it's a gcc extension. My bad. i thought i had read that C++11 has that. Now i remember: C++ re-uses "auto", but i don't know if it's usable in template signatures.

--

Stephan Beal

unread,
Apr 8, 2012, 11:04:45 AM4/8/12
to v8-juic...@googlegroups.com
On Sun, Apr 8, 2012 at 3:19 PM, Anton Yemelyanov <anton.ye...@gmail.com> wrote:
The very next thing I saw after sending this e-mail was "decltype".


So looks like you may be right, signatures can be eliminated using this...

Now i wish i had the energy left to try it out again :/. i played with it a few hours ago (without decltype()) but couldn't come up with a syntactically legal construct.

--

Anton Yemelyanov

unread,
Apr 8, 2012, 11:22:41 AM4/8/12
to v8-juic...@googlegroups.com
Simply replace a signature argument with decltype(fn) and build..  if this works on gcc (i am confirming that at least plain functions work on vc 2010), then this will be good to go.

You will then need to replace each use of signature with decltype(fn) and remove extra template argument.

Or.. create an intermediate template function that doesn't take a signature but then invokes the original template function with decltype(fn) as a signature..

"awesome" wouldn't event begin to describe that...

Anton

Stephan Beal

unread,
Apr 8, 2012, 11:39:28 AM4/8/12
to v8-juic...@googlegroups.com
On Sun, Apr 8, 2012 at 5:22 PM, Anton Yemelyanov <anton.ye...@gmail.com> wrote:
Simply replace a signature argument with decltype(fn) and build..  if this works on gcc (i am confirming that at least plain functions work on vc 2010), then this will be good to go.

Have you been able to reduce the call to 2 arguments, or did you do:

Function...< ..., decltype(::puts), ::puts >

?

i'm looking to create a template like:

typedef FunctionTo11< InCa, ::puts > Callback;

but i cannot figure out how to syntactically declare the FunctionTo11 template. (11 == C++11)

You will then need to replace each use of signature with decltype(fn) and remove extra template argument.

But i have an ordering problem:

FunctionTo< Tag, Signature, FunctionPtr >

in order to get Signature i have to decltype(FunctionPtr). So far i have not been able to formulate that properly (==compile errors).
 
Or.. create an intermediate template function that doesn't take a signature but then invokes the original template function with decltype(fn) as a signature..

How do i declare the intermediary to be able to take any function pointer? The only way i know of to do that is to generate specializations for each arity.

"awesome" wouldn't event begin to describe that...

Let's get it working, then :). i'm stuck on the syntax and i'm not finding much about decltype in the context of template parameters. Mostly stackoverflow questions (some of them interesting, but haven't solved this problem so far).

Anton Yemelyanov

unread,
Apr 8, 2012, 11:54:21 AM4/8/12
to v8-juic...@googlegroups.com
I did 

Function...< ..., decltype(::puts), ::puts > 

Hm.. I see the ordering problem you are talking about. :-/  Trying some experiments on my end...  Will let you know if I come up with anything...

ASY

Stephan Beal

unread,
May 4, 2012, 4:13:11 PM5/4/12
to v8-juic...@googlegroups.com
On Sun, Apr 8, 2012 at 5:22 PM, Anton Yemelyanov <anton.ye...@gmail.com> wrote:
Simply replace a signature argument with decltype(fn) and build..  if this works on gcc (i am confirming that at least plain functions work on vc 2010), then this will be good to go.


i might have found an example:

Pay close attention to this code snippet:


the API for the add() call looks like:


i haven't tried it (my hand is still in a cast), but i'm looking forward to it.

Stephan Beal

unread,
May 4, 2012, 4:27:56 PM5/4/12
to v8-juic...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages