Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
0 answers
106 views

C++11. auto in lambda

I have the next code (C++11): ... ATTRIBUTE_PROBLEM getAttrWithCustomType(const std::string& attrName) { auto attr = std::find_if( attributes.cbegin(), ...
Валентин Никин's user avatar
1 vote
1 answer
152 views

GCC leaking its lambda implementation into the user's program?

How is it possible that the following code is successfully compiled by GCC version [6..10] ? int main(int argc, char *argv[]) { auto const answer = 42; auto lambda = [&answer] {}; auto ...
Bulletmagnet's user avatar
  • 5,961
2 votes
2 answers
256 views

Nested lambda and mutable keyword

Consider the following piece of code: void f() { int a = 3; [=]() { [=] () mutable { a = 5; }(); }(); } It compiles on Clang (https://godbolt.org/z/IEXotM) ...
KireinaHoro's user avatar
5 votes
3 answers
945 views

Erratic behavior of GCC's std::sort with lambdas

The following code generates a segmentation fault when compiled with GCC 6.1.0. Strangely, the error is consistent, but does not happen with smaller sizes or slightly different comparison expressions. ...
S. K.'s user avatar
  • 433
-1 votes
1 answer
76 views

Wrong gcc behaviour with lambda

By compiling this: #include <iostream> #include <sstream> std::string makeList (std::string sep) { auto makeItem = [&] (std::string item) { static char count = '0'; ...
Misopeth's user avatar
6 votes
1 answer
1k views

GCC 6.x warning about lambda visibility

I am building a shared library that contains a bunch of lambdas, and some of those lambdas are created inside other lambdas. But, when I use -fvisibility=hidden and -Wall I get a warning about ...
DonOregano's user avatar
8 votes
1 answer
346 views

Why does this simple lambda consistently run faster inside an std::thread than inside the main function with gcc 4.9.2?

The following snippet takes a command line parameter that represents the number of threads to spawn to run a simple for loop concurrently. If the arguments passed is 0, no std::thread is spawned. On ...
blue's user avatar
  • 2,793
0 votes
2 answers
496 views

Unable to use std::bind with variadic template parameters

I'm working on implementing a wrapper for std::thread that will allow me retrieve arbitrary return values after the thread is finished executing. While I am using C++11, I am using an older ARM ...
zeus_masta_funk's user avatar
11 votes
1 answer
231 views

What is GCC doing to my static variable in a lambda?

Using GCC 6.1, the following program: #include <string> #include <vector> #include <iterator> #include <algorithm> #include <iostream> int main() { static const std:...
Daniel's user avatar
  • 8,401
8 votes
3 answers
294 views

C++ lambda not capturing variable on 2nd expansion in template?

I have some tortuous code in a template that uses @R. Martinho Fernandes's trick to loop unroll some packed parameters in a variadic template and invoke the same code on each argument in the argument ...
Ross Rogers's user avatar
  • 24.2k
4 votes
3 answers
7k views

error: function declared 'noreturn' should not return

At my workplace, we have a different internal name for noreturn attribute. Suppose it is INTERNAL_DONT_RETURN I am writing a member function of a class where I do something like INTERNAL_DONT_RETURN ...
Recker's user avatar
  • 1,975
5 votes
3 answers
1k views

Is it possible to explicitly specialize template to match lambda?

Suppose I have a header wrapper.h: template <typename Func> void wrapper(const Func func); and a file wrapper.cpp containing: #include "wrapper.h" template <typename Func> void wrapper(...
Alec Jacobson's user avatar
3 votes
1 answer
265 views

Lambda Syntax Incompatibility between MSVC and GCC

I have created a method with the following signature in a C++ header: template<class _Ty> class x { public: // ... template<class func_Ty> x *where(func_Ty &); } My ...
Nick Mertin's user avatar
  • 1,209
0 votes
1 answer
2k views

Undefined reference when using lambda

The following code produces undefined reference error on c++ (Debian 4.7.2-5) 4.7.2: #include <signal.h> class Lol { public: void foo() { struct sigaction sa; sa.sa_flags = ...
lstipakov's user avatar
  • 3,238
12 votes
2 answers
2k views

How can I show lambda functions on backtraces?

I'm writing a C++11 software and I'm using lambdas. When I print the backtrace with backtrace_symbols_fd all functions are demangled except of lambda. It's a bit obvious because they are anonymous ...
Luca Marturana's user avatar
11 votes
3 answers
4k views

Why does std::result_of not work with lambdas?

I managed to reduce my case to the following simplest piece of code: #include <type_traits> auto call(const auto& f) -> typename std::result_of<decltype(f)()>::type { return f();...
user2059893's user avatar
0 votes
1 answer
834 views

gcc/g++ internal error (c++ templated lambda)

i was just making a few changes to my program, when all of a sudden g++ complained with an internal compiler error. Clang however compiles it without any problems and also does not give any warnings, ...
Lazarus535's user avatar
  • 1,338
3 votes
1 answer
504 views

Is this lambda capture issue a gcc compiler bug?

Minimum working example: #include <iostream> #include <memory> #include <string> int main() { std::shared_ptr<std::string> i = std::make_shared<std::string>("foo"); ...
tom's user avatar
  • 507
8 votes
2 answers
2k views

Lambda expression in c++, OS X's clang vs GCC

A particular property of c++'s lambda expressions is to capture the variables in the scope in which they are declared. For example I can use a declared and initialized variable c in a lambda function ...
pier94's user avatar
  • 277
23 votes
1 answer
5k views

C++11 lambdas can access my private members. Why?

Consider this piece of code: class shy { private: int dont_touch; // Private member public: static const shy object; }; const shy shy::object = []{ shy obj; obj.dont_touch = 42; ...
Mark Garcia's user avatar
  • 17.7k
1 vote
1 answer
158 views

using template parameters in function arguments does not work gcc4.8

I have a function like this : template<typename Iterator> void sort2(Iterator it, std::function<bool(typename std::remove_pointer< typename ...
uchar's user avatar
  • 2,590
0 votes
1 answer
619 views

downgrading g++ after changing version

So previously i tried to compile a lambda expression in c++, my default compiler was gcc-4.4 and as you know it doesn't support lambda expressions, so i tried to install a newer version of gcc-4.7, ...
Reda's user avatar
  • 99
7 votes
1 answer
6k views

parameter packs not expanded with ‘...' -- another variadic template bug with gcc?

gcc's treatment of variadic templates is well known to be patchy (see for example this and this), but I wonder whether the following bug is already known (I cannot find it at bugzilla) or whether it ...
Walter's user avatar
  • 45.3k
1 vote
1 answer
2k views

Compiling with gcc fails if using lambda function for QObject::connect()

This Code compiles without any problems Qt5.2.0 MSVC2012: #include <QCoreApplication> #include <QObject> #include <QTimer> #include <QDebug> int main(int argc, char *argv[]) {...
avb's user avatar
  • 1,751
0 votes
2 answers
3k views

c++ lambda expressions variables in classes

I want to save lambda expressions variables (like in the fist code block). The problem is that then I use a classes (like the second code block) the compiler return me some errors. I don"t know how to ...
Heinrich's user avatar
  • 307
5 votes
2 answers
2k views

C++ Lambda: Access static method in lambda leads to error 'this was not captured for this lambda function'

Consider the following code: //this is what I want to call; I cannot modify its signature void some_library_method(void(*fp)(void)); class Singleton{ public: static Singleton *instance();...
muffel's user avatar
  • 7,340
3 votes
2 answers
2k views

Using variadic template arguments to resolve a lambda signature

While there's a lot of stuff floating out there about getting the return type of any templated callback function/method (including lambdas of course), I'm having an extremely hard time finding ...
mr.stobbe's user avatar
  • 612
2 votes
1 answer
275 views

Compiler error when using constexpr and lambda

I encountered a problem when using constexpr functions together with lambdas. The following code is a minimal version which reproduces the error: #include <iostream> constexpr unsigned bar(...
Danvil's user avatar
  • 23k
9 votes
4 answers
3k views

swap std::unique_ptr with lambda as deleter -- GCC

Can we use a lambda as a deleter with a std::unique_ptr ? Actualy, I did it with clang++ and it was happy to do so. I'm using std::swap to swap to std::unique_ptr<ObjType, decltyp(deleter)>; ...
Jeremy Cochoy's user avatar
7 votes
1 answer
4k views

GCC __attribute__((always_inline)) and lambdas, is this syntax correct?

I am using GCC 4.6 as part of the lpcxpresso ide for a Cortex embedded processor. I have very limited code size, especially when compiling in debug mode. Using attribute((always_inline)) has so far ...
odinthenerd's user avatar
  • 5,522
13 votes
1 answer
626 views

Undocumented GCC C++11 extension? Capturing arbitrary expressions in lambda capture lists

Strangely enough, GCC 4.7.2 seems to have no problem with the following code: template<typename T> T&& identity(T&& x1) { return std::forward<T>(x1); } int main(int, ...
Stephen Lin's user avatar
  • 5,530
2 votes
2 answers
1k views

undefined reference capturing static variable in lambda

I have a lambda inside of a function that is capturing with [&] and then using a local static variable inside the lambda. I'm not sure if this valid to begin with, but this compiles and links ...
JaredC's user avatar
  • 5,290
0 votes
1 answer
642 views

c++ In lambda function - error: invalid type argument in tbb::parallel_for

New to tbb and lambdas in c++ and having compiler errors on the following code: template <class ObjT, class Stepper> class GroupStepper : public Stepper { public: typedef boost::...
scmcduffee's user avatar
7 votes
1 answer
820 views

GCC bug or not : default std::function?

How to specify a default function as a parameter of a class member ? A current example derived from my code is : #include <iostream> #include <functional> template<typename T> ...
Vincent's user avatar
  • 60.2k
1 vote
0 answers
65 views

Compilation error with lambda capturing templated parameters [duplicate]

Possible Duplicate: Is there a way to pass template arguments to a function on an object when the object type is a template argument? I have been learning how to use lambdas in C++ lately when I ...
user avatar
4 votes
2 answers
383 views

Class with non-static lambda member can't use default template paramers?

This small test program: #include <functional> //template<class T> // <-- with this, gcc compiles ok template<class T=void> struct c{ std::function<int(...
Leonid Volnitsky's user avatar
1 vote
1 answer
279 views

Inline lambda expression causes compiler error

template <typename T, typename Y, typename... Args> class Bar { T& t; public: Bar(T& t) : t(t) { } }; template <typename T, typename... Args> void Foo(T &function) { ...
Zach Saw's user avatar
  • 4,378
6 votes
1 answer
4k views

C++11; Can non-static data member initializations access other data members?

I really like the idea of properties in C#, and as a little side project, I've been tinkering with the idea of implementing them in C++. I ran into this example https://stackoverflow.com/a/5924594/...
Bret Kuhns's user avatar
  • 4,084
13 votes
1 answer
4k views

GCC incorrectly captures global variables by reference in lambda functions?

GCC seems to incorrectly capture global variables by reference in lambda functions, even when they are specified as 'capture by value'. This code will compile and print "a = 9": #include <iostream&...
user1175938's user avatar
8 votes
1 answer
923 views

Last minute change in Lambda syntax or gcc bug?

I use the svn-version of the gcc-4.7.0 to check out some C++11 features, e.g. Lambda Expressions. Since a couple of weeks some of my old examples including Lambdas to not compile anymore. I wonder: ...
towi's user avatar
  • 22.2k
3 votes
3 answers
2k views

Why can't I declare a struct variable inside a lambda in c++0x?

Here's the code. #include<struct.h> #include<iostream> #include<functional> using namespace std; void LambdaTest(const function <struct dummy (void)>& f) { struct ...
rpg's user avatar
  • 975
2 votes
1 answer
403 views

Precendence rules and lambda expressions

I am trying to understand the difference in warning gives by gcc-4.3.2 and gcc-4.5.1. Given struct S { }; int main() { int** i; i = new int*[10] ; delete[] i; // [1a] i = new (int*[10]); ...
Benjamin Bannier's user avatar
32 votes
2 answers
10k views

Capturing reference variable by copy in C++0x lambda

According to the answers and comments for this question, when a reference variable is captured by value, the lambda object should make a copy of the referenced object, not the reference itself. ...
jakar's user avatar
  • 1,061
5 votes
2 answers
755 views

Elegant porting of lambda expressions in C++

Since lambda expressions require GCC version > 4.4: what is the most elegant or fastest (yet not too 'dirty') way of porting code containing a couple of lambda expressions with reference-bound ...
dcn's user avatar
  • 4,479
4 votes
2 answers
826 views

C++0x Lambda Support in GCC for the iPhone

Can anyone tell me if C++ lambda expressions will be supported by GCC for the iPhone in the future? Obviously Apple have their custom 'block' support so I wondered what this may eventually mean in ...
iam's user avatar
  • 1,713