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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:32:35+00:00 2026-06-11T17:32:35+00:00

GCC 4.7 in C++11 mode is letting me define a function taking a lambda

  • 0

GCC 4.7 in C++11 mode is letting me define a function taking a lambda two different ways:

// by value
template<class FunctorT>
void foo(FunctorT f) { /* stuff */ }

And:

// by r-value reference
template<class FunctorT>
void foo(FunctorT&& f) { /* stuff */ }

But not:

// by reference
template<class FunctorT>
void foo(FunctorT& f) { /* stuff */ }

I know that I can un-template the functions and just take std::functions instead, but foo is small and inline and I’d like to give the compiler the best opportunity to inline the calls to f it makes inside. Out of the first two, which is preferable for performance if I specifically know I’m passing lambdas, and why isn’t it allowed to pass lambdas to the last one?

  • 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-11T17:32:36+00:00Added an answer on June 11, 2026 at 5:32 pm

    FunctorT&& is a universal reference and can match anything, not only rvalues. It’s the preferred way to pass things in C++11 templates, unless you absolutely need copies, since it allows you to employ perfect forwarding. Access the value through std::forward<FunctorT>(f), which will make f an rvalue again if it was before, or else will leave it as an lvalue. Read more here about the forwarding problem and std::forward and read here for a step-by-step guide on how std::forward really works. This is also an interesting read.

    FunctorT& is just a simple lvalue reference, and you can’t bind temporaries (the result of a lambda expression) to that.

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

Sidebar

Related Questions

Using GCC and C99 mode, I have a function declared as: void func(float *X);
What macro does Clang define to announce C++11 mode, if any? GCC defines __GXX_EXPERIMENTAL_CXX0X__
I've recently found myself using the following macro with gcc 4.5 in C++11 mode:
GCC seem to think that I am trying to make a function call in
gcc 4.4.2 c89 I have a function that has to run (config_relays). It make
(Environment: gcc/g++ 4.6.1 in -std=gnu++0x mode on Linux 3.0 / x86_64...) #include <stdlib.h> #include
I'm using gcc 4.6 in c++0x mode. I've noticed I don't seem to get
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 Apache protable runtime 1.4 c89 and compiling in -m32 mode
GCC disables lots of builtins when running in strict mode -std=c... . Outside strict
I have this code that I'm putting through the GCC in advanced compilation mode:

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.