-, , , , const, mutable .
, GCC, clang:
#include <type_traits>
int main(int argc, char* argv[]) {
int i = 0;
[j = i](){ static_assert(std::is_same<decltype(j), const int>::value, "!"); }();
}
, :
return [f = std::forward<F>(f)](auto&&... args) -> decltype(auto) {
return std::forward<decltype(f)>(f)(std::forward<decltype(args)>(args)...);
};
mutable, f . , f -, f decltype(f) .
mutable . :
#include <type_traits>
#include<utility>
struct S {};
template<typename T>
void f(T &&t) {
[t = std::forward<T>(t)]()mutable{ static_assert(std::is_same<decltype(t), S>::value, "!"); }();
}
int main() {
S s;
f(s);
}
, , , .
, const, mutable, f const ( , f main mutable).
( ):
return [f = std::forward<F>(f)](auto&&... args) mutable -> decltype(auto) {
return std::forward<F>(f)(std::forward<decltype(args)>(args)...);
};
, , const, - .
, , mutable.
.
- GCC. decltype(f) . . , , .