boostorg / boostorg/hof

Add a macro to reduce boilerplate with the factory pattern

Ouverte
#161 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
C++
Étoiles
509
Forks
94
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.