Return type of function or expression

G

GH

Hi all, is there a way to statically reference the return type of a
function or expression? To make myself clear, take the iomanip
std::setw for example. The standard explicitly leaves the return type
of std::setw implementation dependent. Suppose I want to know and
reference the type of std::setw(8) (e g create a variable of that
type), is there anyway to reference that type without going to the
headers and using the implementation dependent type such as std::_Setw
in g++?
 
D

darylew

If you're using C++11, use decltype( std::setw(8) ), i.e. take the type of the expression, where said expression is a function call.

Daryle W.
 
S

Stefan Ram

GH said:
Hi all, is there a way to statically reference the return type of a
function or expression?

An expression has a type (not a return type).
To make myself clear, take the iomanip
std::setw for example

»The« requires an English noun. If I want to use
»iomanip std::setw« as a name, I use it without »the«.
. The standard explicitly leaves the return type
of std::setw implementation dependent.

It is T6, an »unspecified implementation type«.
Suppose I want to know and reference the type of std::setw(8)
(e g create a variable of that type), is there anyway to
reference that type without going to the headers and using
the implementation dependent type such as std::_Setw in g++?

Assume that this would be possible, so you could write

{ RETURNTYPEOF(std::setw) e; ... }

to declare the variable e of that type, which is unknown
to you, the programmer. What operations could you apply
to »e« in »...« that case? What could you do with it?
 
I

Ian Collins

An expression has a type (not a return type).


»The« requires an English noun. If I want to use
»iomanip std::setw« as a name, I use it without »the«.

If you are being pedantic, iomanip being short for I/O manipulator can
be used as a noun.
It is T6, an »unspecified implementation type«.


Assume that this would be possible, so you could write

Which you can with the new decltype operator.
{ RETURNTYPEOF(std::setw) e; ... }

to declare the variable e of that type, which is unknown
to you, the programmer. What operations could you apply
to »e« in »...« that case? What could you do with it?

Very useful inn conjunction with the new suffix return type syntax.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top