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 8157407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:16:27+00:00 2026-06-06T17:16:27+00:00

C++11 supports a new function syntax: auto func_name(int x, int y) -> int; Currently

  • 0

C++11 supports a new function syntax:

auto func_name(int x, int y) -> int;

Currently this function would be declared as:

int func_name(int x, int y);

The new style does not seem to be widely adopted yet (say in the gcc stl)

However, should this new style be preferred everywhere in new C++11-programs, or will it only be used when needed?

Personally, I prefer the old style when possible, but a code-base with mixed styles looks pretty ugly.

  • 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-06T17:16:29+00:00Added an answer on June 6, 2026 at 5:16 pm

    There are certain cases where you must use a trailing return type. Most notably, a lambda return type, if specified, must be specified via a trailing return type. Also, if your return type utilizes a decltype that requires that the argument names are in scope, a trailing return type must be used (however, one can usually use declval<T> to work around this latter issue).

    The trailing return type does have some other minor advantages. For example, consider a non-inline member function definition using the traditional function syntax:

    struct my_awesome_type
    {
        typedef std::vector<int> integer_sequence;
    
        integer_sequence get_integers() const;
    }; 
    
    my_awesome_type::integer_sequence my_awesome_type::get_integers() const
    {
        // ...
    }
    

    Member typedefs are not in scope until after the name of the class appears before ::get_integers, so we have to repeat the class qualification twice. If we use a trailing return type, we don’t need to repeat the name of the type:

    auto my_awesome_type::get_integers() const -> integer_sequence
    {
        // ...
    }
    

    In this example, it’s not such a big deal, but if you have long class names or member functions of class templates that are not defined inline, then it can make a big difference in readability.

    In his “Fresh Paint” session at C++Now 2012, Alisdair Meredith pointed out that if you use trailing return types consistently, the names of all of your functions line up neatly:

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

    I’ve used trailing return types everywhere in CxxReflect, so if you’re looking for an example of how code looks using them consistently, you can take a look there (e.g, the type class).

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

Sidebar

Related Questions

unique_ptr<T> does not allow copy construction, instead it supports move semantics. Yet, I can
The latest Google App Engine release supports a new Task Queue API in Python.
I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth
I'm currently evaluating options for adding sub-domain support to a new Ruby on Rails
I know that eclipse can do this, can Intellij via the new Android support
I'm new to Boost, but not to functional programming, and I'm trying to see
I want to test with JavaScript whether the browser supports cookies or not. The
I made an article spinner that used regex to find words in this syntax:
Situation: I'm implementing a list-like container that supports a Pop() function that should return
I'm not new to C++ but I am used to running a g++ compiler

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.