Return type of function or expression

Discussion in 'C++' started by GH, Feb 4, 2012.

  1. GH

    GH Guest

    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++?
    GH, Feb 4, 2012
    #1
    1. Advertising

  2. GH

    Guest

    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.
    , Feb 4, 2012
    #2
    1. Advertising

  3. GH

    Ian Collins Guest

    On 02/ 5/12 09:34 AM, 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
    Ian Collins, Feb 7, 2012
    #3
  4. GH

    Stefan Ram Guest

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

    >. 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?
    Stefan Ram, Feb 7, 2012
    #4
  5. GH

    Ian Collins Guest

    On 02/ 7/12 05:39 PM, Stefan Ram wrote:
    > GH<> 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
    Ian Collins, Feb 7, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greenhorn
    Replies:
    15
    Views:
    807
    Keith Thompson
    Mar 6, 2005
  2. Diego Martins
    Replies:
    5
    Views:
    483
    Diego Martins
    Sep 5, 2006
  3. Diego UTN-FRP
    Replies:
    4
    Views:
    4,505
    Diego UTN-FRP
    Nov 29, 2009
  4. Luca Forlizzi
    Replies:
    4
    Views:
    459
    Luca Forlizzi
    Nov 14, 2010
  5. andrew cooke
    Replies:
    1
    Views:
    180
    Steven D'Aprano
    Apr 3, 2011
Loading...

Share This Page