Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:25:31+00:00 2026-06-11T07:25:31+00:00

In one system header file, I see the expression like this: auto create_task(_Ty _Param)

  • 0

In one system header file, I see the expression like this:

auto create_task(_Ty _Param) -> task<typename details::_TaskTypeFromParam<_Ty>::_Type>
{…}

I don’t know what "->" means, it isn’t pointer expression or lambda expression, can anyone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:25:33+00:00Added an answer on June 11, 2026 at 7:25 am

    It’s the new function declaration syntax from C++11, and it’s called the “trailing return type”. At the end of a function declaration, -> means that the following is the return type of the function. It can only be used when the auto keyword is used instead of an actual return type where you would normally expect it.

    For instance, these two declarations are compatible:

    int foo();
    auto foo() -> int;
    

    Depending on your tastes, you may find it prettier than the old declaration syntax, especially when the return type is extremely long/complex:

    task<typename details::_TaskTypeFromParam<_Ty>::_Type> create_task(_Ty _Param);
    auto create_task(_Ty _Param) -> task<typename details::_TaskTypeFromParam<_Ty>::_Type>;
    

    But sometimes it can be necessary with templates, when the return type of the function could vary with the arguments.

    Say you want a templated function to add variables:

    template<typename T>
    T add(const T& x, const T& y)
    {
        return x + y;
    }
    

    That’s great, but you’ll only be able to add variables of the same type. Suppose you would like to be able to add variables of any type (like add((int)1, (double)2)).

    template<typename T, typename U>
    ??? add(const T& x, const U& y)
    {
        return x + y;
    }
    

    EDIT: note that in C++14 and onwards, it’s legal to write auto add(const T& x, const U& y), without a trailing return type, for function definitions (in other words, when you define the body of your function).


    The problem is that you can’t tell in advance what the result type of x + y will be. As templates stand, they could even be non-integral types. (Wouldn’t you like to be able to do add(std::string("x"), "y")?)

    Decltype, along with the new function declaration syntax, lets you solve this problem.

    template<typename T, typename U>
    auto add(const T& x, const U& y) -> decltype(x + y)
    {
        return x + y;
    }
    

    Decltype “returns” the type of an expression. Since you need x and y to have been declared for decltype(x + y) to work, you need the new syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to migrate a very large dataset from one system to another. One
We're about to make data transformation from one system to another using SSIS. We
As part of one our system's we enable a user in the backoffice to
Objective-C uses a sophisticated message-passing system when one object calls a method on another
One element of my site is a rating system. I am puzzled a bit
One of my application tasks is to get the current system date and compares
In one of my project i have to gather full system information (hardware and
How would one enumerate the installed browsers on an OS X system from a
In my system I have two different projects, one defining its interfaces and another
I saw that one of our tools uses a ConsoleAppender to System.err next to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.