Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
Classes | Namespaces | Macros | Functions | Variables
cpp_lang_util.hpp File Reference
#include <type_traits>
Include dependency graph for cpp_lang_util.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  jau::has_builtin_bit_cast< Dummy_type >
 Convenience type trait for __has_builtin(__builtin_bit_cast). More...
 

Namespaces

 jau
 
 jau::impl
 

Macros

#define consteval_cxx20   constexpr
 consteval qualifier replacement for C++20 consteval. More...
 
#define constinit_cxx20   constexpr
 constinit qualifier replacement for C++20 constinit. More...
 
#define constexpr_cxx20   inline
 constexpr qualifier replacement for C++20 constexpr. More...
 
#define constexpr_non_literal_var   inline
 Used when designed to declare a function constexpr, but prohibited by its specific implementation. More...
 
#define constexpr_atomic   inline
 Used when designed to declare a function constexpr, but prohibited by its specific implementation. More...
 
#define __builtin_bit_cast(Dest_type, Value_arg)   0
 Dummy definition in the absence of this builtin function as required to have this compilation unit compile clean. More...
 

Functions

template<class Dummy_type >
constexpr bool jau::impl::has_builtin_bit_cast_impl (std::enable_if_t< has_builtin_bit_cast_v< Dummy_type >, bool >=true) noexcept
 
template<class Dummy_type >
constexpr bool jau::impl::has_builtin_bit_cast_impl (std::enable_if_t< !has_builtin_bit_cast_v< Dummy_type >, bool >=true) noexcept
 
constexpr bool jau::is_builtin_bit_cast_available () noexcept
 Query whether __builtin_bit_cast(Dest_type, arg) is available, using jau::has_builtin_bit_cast. More...
 
template<class Dest , class Source >
constexpr std::enable_if_t< sizeof(Dest)==sizeof(Source) &&std::is_trivially_copyable_v< Dest > &&std::is_trivially_copyable_v< Source >, Dest > jau::bit_cast (const Source &src) noexcept
 C++20 bit_cast<>(arg) implementation for C++17. More...
 
template<class Dest , class Source >
constexpr std::enable_if_t< sizeof(Dest)==sizeof(Source) &&std::is_pointer_v< Source > &&std::is_pointer_v< Dest >, Dest > jau::pointer_cast (const Source &src) noexcept
 A constexpr pointer cast implementation for C++17, inspired by C++20 bit_cast<>(arg). More...
 

Variables

template<typename Dummy_type >
constexpr bool jau::has_builtin_bit_cast_v = has_builtin_bit_cast<Dummy_type>::value
 Value access of has_builtin_bit_cast type trait for convenience . More...
 

Macro Definition Documentation

◆ __builtin_bit_cast

#define __builtin_bit_cast (   Dest_type,
  Value_arg 
)    0

Dummy definition in the absence of this builtin function as required to have this compilation unit compile clean.

Parameters
Dest_typethe target type
Value_argthe source value argument

Definition at line 204 of file cpp_lang_util.hpp.

◆ consteval_cxx20

#define consteval_cxx20   constexpr

consteval qualifier replacement for C++20 consteval.

A consteval specifier implies inline. At most one of the constexpr, consteval, and constinit specifiers is allowed to appear within the same sequence of declaration specifiers. ... An immediate function is a constexpr function, and must satisfy the requirements applicable to constexpr functions or constexpr constructors, as the case may be.

Evaluated using the alternative qualifier constexpr for C++ < 20, as it is almost contained within consteval but lacks the immediate function constraint.

Evaluated as consteval for C++20.

Definition at line 53 of file cpp_lang_util.hpp.

◆ constexpr_atomic

#define constexpr_atomic   inline

Used when designed to declare a function constexpr, but prohibited by its specific implementation.

Evaluated using the alternative qualifier inline for C++ < 20, as it is implied for constexpr functions or static member variables, see constexpr_cxx20.

Here it uses thread-safety related measures like atomic storage or mutex locks, which are non-literal variables and hence prohibit the use of constexpr.

See also
constexpr_cxx20
constexpr_non_literal_var

Definition at line 133 of file cpp_lang_util.hpp.

◆ constexpr_cxx20

#define constexpr_cxx20   inline

constexpr qualifier replacement for C++20 constexpr.

A constexpr specifier used in a function or static member variable (since C++17) declaration implies inline.

Evaluated using the alternative qualifier inline for C++ < 20, as it is implied for constexpr functions or static member variables, see above.

Evaluated as constexpr for C++20, i.e. std::string literals, virtual functions, etc.

Definition at line 96 of file cpp_lang_util.hpp.

◆ constexpr_non_literal_var

#define constexpr_non_literal_var   inline

Used when designed to declare a function constexpr, but prohibited by its specific implementation.

Evaluated using the alternative qualifier inline for C++ < 20, as it is implied for constexpr functions or static member variables, see constexpr_cxx20.

Here it but uses non-literal variables, such as std::lock_guard etc. As these can't be evaluated at compile time, the standard does not allow using constexpr here.

Empty until standard defines otherwise.

See also
constexpr_cxx20

Definition at line 116 of file cpp_lang_util.hpp.

◆ constinit_cxx20

#define constinit_cxx20   constexpr

constinit qualifier replacement for C++20 constinit.

constinit cannot be used together with constexpr or consteval. When the declared variable is a reference, constinit is equivalent to constexpr. When the declared variable is an object, constexpr mandates that the object must have static initialization and constant destruction and makes the object const-qualified, however, constinit does not mandate constant destruction and const-qualification.

Evaluated using the alternative qualifier constexpr for C++ < 20, as it is almost contained within constinit but lacks the loosening of not mandating constant destruction and const-qualification.
FIXME: Due to the above, this replacement might not be suitable: TBD!

Evaluated as constinit for C++20.

Definition at line 77 of file cpp_lang_util.hpp.