All Questions
45 questions
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(),
...
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 ...
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) ...
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.
...
-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';
...
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 ...
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 ...
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 ...
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:...
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 ...
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 ...
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(...
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 ...
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 = ...
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 ...
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();...
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, ...
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");
...
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 ...
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; ...
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 ...
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, ...
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 ...
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[])
{...
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 ...
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();...
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 ...
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(...
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)>; ...
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 ...
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, ...
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 ...
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::...
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> ...
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 ...
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(...
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) { ...
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/...
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&...
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:
...
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 ...
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]); ...
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. ...
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 ...
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 ...