boostorg / boostorg/hof

Add a macro to reduce boilerplate with the factory pattern

Abierto
#161 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C++
Estrellas
509
Forks
94
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

An alternative to declaring functions using the `FIT_STATIC_LAMBDA_FUNCTION` is to use the factory pattern in C++14:

``` cpp
struct lambda_factor
{
auto operator*() const
{
return [] { ... };
}
};

FIT_STATIC_FUNCTION(lambda) = fit::indirect(lambda_factor{});
```

It might be possible to have a macro to reduce this boilerplate:

``` cpp
#define FIT_STATIC_FACTORY(name) \
struct name ## _factory { auto operator*() const; } \
FIT_STATIC_FUNCTION(name) = fit::indirect(name ## _factory{}); \
auto name ## _factory::operator*() const
```

Then it could be written as:

``` cpp
FIT_STATIC_FACTORY(lambda)
{
return [] { ... };
}
```

By making it a macro it could fallback on using a lambda in C++11, although this would require a semicolon at the end.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.