Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
cpp14_inline.hpp File Reference

Go to the source code of this file.

Macro Definition Documentation

◆ ARENE_CPP14_INLINE_VARIABLE

#define ARENE_CPP14_INLINE_VARIABLE ( type,
name )
Value:
namespace { /* NOLINT(google-build-namespaces) explicitly want per-TU instantiations*/ \
/* NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables, bugprone-macro-parentheses) */ \
ARENE_MAYBE_UNUSED constexpr auto& name = ::arene::base::detail::cpp14_inline_static_const<type>::value; \
} \
#define ARENE_MAYBE_UNUSED
An alias for [[maybe_unused]] , or a no-op if the attribute is not supported.
Definition maybe_unused.hpp:24
#define ARENE_REQUIRE_SEMICOLON
Definition require_semicolon.hpp:15

Emulates C++17's inline variable declarations for function objects.

Parameters
typeThe type of the function object to instantiate
nameThe name the instantiated object should have in the containing namespace.

This macro is used to correctly declare the instantiation of function objects in a way compatible with both C++14 and >= C++17 contexts, inspired by Eric Niebler's original paper here: https://ericniebler.com/2014/10/21/customization-point-design-in-c11-and-beyond/

In a <= C++17 context, the type is simply declared as inline constexpr type name{} . In C++14 contexts, where inline variable declarations are not permitted, the same effect is achieved by indirecting through the arene::base::detail::cpp14_inline_static_const helper template. The usage looks like so: