libsigc++: Lambdas

libsigc++ 2.4.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

Modules | Classes | Functions
Lambdas

libsigc++ ships with basic lambda functionality and the sigc::group adaptor, which uses lambdas to transform a functor's parameter list. More...

## Modules
| group()
| sigc::group() alters an arbitrary functor by rebuilding its arguments from one or more lambda expressions.

## Classes
struct | sigc::lambda< T_type >
| Lambda type. More...
struct | sigc::lambda_base
| A hint to the compiler. More...
struct | sigc::lambda_group1< T_functor, T_type1 >
| lambda_group1 wraps a functor and rebuilds its arguments from 1 lambda expressions. More...
struct | sigc::lambda_group2< T_functor, T_type1, T_type2 >
| lambda_group2 wraps a functor and rebuilds its arguments from 2 lambda expressions. More...
struct | sigc::lambda_group3< T_functor, T_type1, T_type2, T_type3 >
| lambda_group3 wraps a functor and rebuilds its arguments from 3 lambda expressions. More...
struct | sigc::unwrap_lambda_type< T_type >
| Deduces the type of the object stored in an object of the passed lambda type. More...
struct | sigc::unwrap_lambda_type< lambda< T_type > >
| Deduces the type of the object stored in an object of the passed lambda type. More...

## Functions
template<class T_functor , class T_type1 >
lambda< lambda_group1 < T_functor, typename unwrap_reference< T_type1 > ::type > > | sigc::group (const T_functor& _A_func, T_type1 _A_1)
| Alters an arbitrary functor by rebuilding its arguments from 1 lambda expressions. More...
template<class T_functor , class T_type1 , class T_type2 >
lambda< lambda_group2 < T_functor, typename unwrap_reference< T_type1 > ::type, typename unwrap_reference< T_type2 > ::type > > | sigc::group (const T_functor& _A_func, T_type1 _A_1, T_type2 _A_2)
| Alters an arbitrary functor by rebuilding its arguments from 2 lambda expressions. More...
template<class T_functor , class T_type1 , class T_type2 , class T_type3 >
lambda< lambda_group3 < T_functor, typename unwrap_reference< T_type1 > ::type, typename unwrap_reference< T_type2 > ::type, typename unwrap_reference< T_type3 > ::type > > | sigc::group (const T_functor& _A_func, T_type1 _A_1, T_type2 _A_2, T_type3 _A_3)
| Alters an arbitrary functor by rebuilding its arguments from 3 lambda expressions. More...
template<class T_type >
T_type& | sigc::unwrap_lambda_value (T_type& a)
| Gets the object stored inside a lambda object. More...
template<class T_type >
const T_type& | sigc::unwrap_lambda_value (const T_type& a)
| Gets the object stored inside a lambda object. More...
template<class T_type >
const T_type& | sigc::unwrap_lambda_value (const lambda< T_type >& a)
| Gets the object stored inside a lambda object. More...
template<class T_type >
lambda< T_type& > | sigc::var (T_type& v)
| Converts a reference into a lambda object. More...
template<class T_type >
lambda< const T_type& > | sigc::var (const T_type& v)
| Converts a constant reference into a lambda object. More...

## Detailed Description

libsigc++ ships with basic lambda functionality and the sigc::group adaptor, which uses lambdas to transform a functor's parameter list.

The lambda selectors sigc::_1, sigc::_2, ..., sigc::_7 are used to select the first, second, ..., seventh argument from a list.

Examples:
  std::cout << sigc::_1(10,20,30); // returns 10
  std::cout << sigc::_2(10,20,30); // returns 20

Operators are defined so that, for example, lambda selectors can be used as placeholders in arithmetic expressions.

Examples:
  std::cout << (sigc::_1 + 5)(3); // returns (3 + 5)
  std::cout << (sigc::_1 * sigc::_2)(7,10); // returns (7 * 10)

If your compiler supports C++11 lambda expressions, they are often a good alternative to libsigc++'s lambda expressions. The following examples are equivalent to the previous ones.

[] (int x, int, int) -> int { return x; }(10,20,30); // returns 10
[] (int, int y, int) -> int { return y; }(10,20,30); // returns 20
[] (int x) -> int { return x + 5; }(3); // returns (3 + 5)
[] (int x, int y) -> int { return x * y; }(7,10); // returns (7 * 10)

Deprecated:
  Use C++11 lambda expressions or std::bind() instead.

## Function Documentation

template <class T_functor , class T_type1 >

lambda<lambda_group1<T_functor, typename unwrap_reference<T_type1>::type> > sigc::group | ( | const T_functor & | _A_func,
|  | T_type1 | _A_1
| ) |  |

Alters an arbitrary functor by rebuilding its arguments from 1 lambda expressions.

Deprecated:
  Use C++11 lambda expressions or std::bind() instead.

template <class T_functor , class T_type1 , class T_type2 >

lambda<lambda_group2<T_functor, typename unwrap_reference<T_type1>::type, typename unwrap_reference<T_type2>::type> > sigc::group | ( | const T_functor & | _A_func,
|  | T_type1 | _A_1,
|  | T_type2 | _A_2
| ) |  |

Alters an arbitrary functor by rebuilding its arguments from 2 lambda expressions.

Deprecated:
  Use C++11 lambda expressions or std::bind() instead.

template <class T_functor , class T_type1 , class T_type2 , class T_type3 >

lambda<lambda_group3<T_functor, typename unwrap_reference<T_type1>::type, typename unwrap_reference<T_type2>::type, typename unwrap_reference<T_type3>::type> > sigc::group | ( | const T_functor & | _A_func,
|  | T_type1 | _A_1,
|  | T_type2 | _A_2,
|  | T_type3 | _A_3
| ) |  |

Alters an arbitrary functor by rebuilding its arguments from 3 lambda expressions.

Deprecated:
  Use C++11 lambda expressions or std::bind() instead.

template <class T_type >

T_type& sigc::unwrap_lambda_value | ( | T_type & | a | ) |

Gets the object stored inside a lambda object.

Returns the object passed as argument, if it is not of type lambda.

Deprecated:
  Use C++11 lambda expressions instead of libsigc++ lambdas.

template <class T_type >

const T_type& sigc::unwrap_lambda_value | ( | const T_type & | a | ) |

Gets the object stored inside a lambda object.

Returns the object passed as argument, if it is not of type lambda.

Deprecated:
  Use C++11 lambda expressions instead of libsigc++ lambdas.

template <class T_type >

const T_type& sigc::unwrap_lambda_value | ( | const lambda< T_type > & | a | ) |

Gets the object stored inside a lambda object.

Deprecated:
  Use C++11 lambda expressions instead of libsigc++ lambdas.

template <class T_type >

lambda<T_type&> sigc::var | ( | T_type & | v | ) |

Converts a reference into a lambda object.

sigc::var creates a 0-ary functor, returning the value of a referenced variable.

Example:
  int main(int argc, char* argv)
  {
  int data;
  sigc::signal<int> readValue;
  readValue.connect(sigc::var(data));
  data = 3;
  std::cout << readValue() << std::endl; //Prints 3.
  data = 5;
  std::cout << readValue() << std::endl; //Prints 5.
  }

If your compiler supports C++11 lambda expressions, and you use the macro SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE, you can replace

readValue.connect(sigc::var(data));

in the example by

readValue.connect([&data] () -> int { return data; });

Deprecated:
  Use C++11 lambda expressions instead of libsigc++ lambdas.

template <class T_type >

lambda<const T_type&> sigc::var | ( | const T_type & | v | ) |

Converts a constant reference into a lambda object.

Deprecated:
  Use C++11 lambda expressions instead of libsigc++ lambdas.