- Это намеренно?
- Если нет, то что я делаю не так?
- Это определение не требуется для стандартных локальных функций повышения (поскольку исходный фрагмент кода есть), только для специализации GCC_LAMBDA.
- Это не требуется для C++98 (-std=c++98), только для C ++11.
- Похоже, это противоречит официальной документации по этой записи
- 'this_' was not declared in this scope
- 'this_' is not captured
Реализация файла gcc_lambda.hpp находится в ссылку.
#include "gcc_lambda.hpp"
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
#include
#include
struct v;
BOOST_TYPEOF_REGISTER_TYPE(v) // Register before `bind this_` below.
#if __cplusplus >= 201103L
#define this_ this // why do I need this line for C++11 and above?
#endif
struct v {
std::vector nums;
v(const std::vector& numbers): nums(numbers) {}
void change_sign_all(const std::vector& indices) {
std::for_each(indices.begin(), indices.end(),
GCC_LAMBDA(bind this_, int i) {
this_->nums.at(i) = -this_->nums.at(i);
} GCC_LAMBDA_END
);
}
};
int main(void)
{
std::vector n(3);
n[0] = 1; n[1] = 2; n[2] = 3;
std::vector i(2);
i[0] = 0; i[1] = 2; // Will change n[0] and n[2] but not n[1].
v vn(n);
vn.change_sign_all(i);
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... iler-error