Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #13787 > unrolled thread

Return type of function or expression

Started byGH <yzghan@gmail.com>
First post2012-02-04 07:29 -0800
Last post2012-02-07 18:08 +1300
Articles 4 — 3 participants

Back to article view | Back to comp.lang.c++


Contents

  Return type of function or expression GH <yzghan@gmail.com> - 2012-02-04 07:29 -0800
    Re: Return type of function or expression darylew@gmail.com - 2012-02-04 12:34 -0800
      Re: Return type of function or expression Ian Collins <ian-news@hotmail.com> - 2012-02-07 17:29 +1300
    Re: Return type of function or expression Ian Collins <ian-news@hotmail.com> - 2012-02-07 18:08 +1300

#13787 — Return type of function or expression

FromGH <yzghan@gmail.com>
Date2012-02-04 07:29 -0800
SubjectReturn type of function or expression
Message-ID<6ea9f13e-061d-4b73-a3c3-502ebd3ea545@c20g2000vbb.googlegroups.com>
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++?

[toc] | [next] | [standalone]


#13788

Fromdarylew@gmail.com
Date2012-02-04 12:34 -0800
Message-ID<2951787.2126.1328387657170.JavaMail.geo-discussion-forums@vbcw9>
In reply to#13787
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.

[toc] | [prev] | [next] | [standalone]


#13789

FromIan Collins <ian-news@hotmail.com>
Date2012-02-07 17:29 +1300
Message-ID<9pbnkdFicgU6@mid.individual.net>
In reply to#13788
On 02/ 5/12 09:34 AM, darylew@gmail.com wrote:

Context?

> 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.


-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#13810

FromIan Collins <ian-news@hotmail.com>
Date2012-02-07 18:08 +1300
Message-ID<9pbpu5FicgU8@mid.individual.net>
In reply to#13787
On 02/ 7/12 05:39 PM, Stefan Ram wrote:
> GH<yzghan@gmail.com>  writes:
>> 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«.

If you are being pedantic, iomanip being short for I/O manipulator can 
be used as a noun.

>> . 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

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.

-- 
Ian Collins

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web