diff options
author | Julian Eisel <julian@blender.org> | 2022-04-26 16:13:58 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-04-26 16:47:19 +0300 |
commit | 5c5ec837b3a565da8647444b807091a78df40fd9 (patch) | |
tree | 26dc541d2b7e5e40f467ab6dd57e279800330990 /source/blender/blenlib/BLI_utildefines.h | |
parent | 96bdd65e740e669eceb18258dbc4b27d268d10aa (diff) |
Utils: Add macro for C++ default arguments in C headers
This macro allows defining a default argument for when the translation
unit is compiled in C++. Otherwise (in C), the argument has to be passed
explicitly.
A couple of benefits:
* Default arguments are a nice quality-of-life feature in C++. It's
annoying if these can't be used in C++ files, just because the header
with the function declaration still needs to be C compatible.
* Adds useful information to the API declaration. E.g. that an argument
can be nullptr.
* Should help us to move to using default arguments more, helping
readability (arguably)
Used in D14653.
Reviewed By: LazyDodo
Differential Revision: https://developer.blender.org/D14654
Diffstat (limited to 'source/blender/blenlib/BLI_utildefines.h')
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 51f0d3f486a..b8407a5453f 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -812,6 +812,16 @@ extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); # define ENUM_OPERATORS(_type, _max) #endif +/** + * Utility so function declarations in C headers can use C++ default arguments. The default is then + * available when included in a C++ file, otherwise the argument has to be set explicitly. + */ +#ifdef __cplusplus +# define CPP_ARG_DEFAULT(default_value) = default_value +#else +# define CPP_ARG_DEFAULT(default_value) +#endif + /** \} */ /* -------------------------------------------------------------------- */ |