MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMacros.h File Reference

Go to the source code of this file.

Macros

#define MR_STR(...)   MR_STR_(__VA_ARGS__)
 Those are generic helper macros that don't have their own headers.
 
#define MR_STR_(...)   #__VA_ARGS__
 
#define MR_IDENTITY(...)   __VA_ARGS__
 Returns the argument unchanged.
 
#define MR_END(...)   DETAIL_MR_END(__VA_ARGS__)
 A helper for writing preprocessor loops.
 
#define DETAIL_MR_END(...)   __VA_ARGS__##_END
 
#define MR_CONCAT(a, b)   MR_CONCAT_( a, b )
 Concat strings.
 
#define MR_CONCAT_(a, b)   a##b
 
#define MR_CONCAT3(a, b, c)   MR_CONCAT3_( a, b, c )
 
#define MR_CONCAT3_(a, b, c)   a##b##c
 
#define MR_HAS_REQUIRES   0
 
#define MR_REQUIRES_IF_SUPPORTED(...)
 
#define MR_SAME_TYPE_TEMPLATE_PARAM(target_, name_)   typename name_ = target_
 
#define MR_NO_UNIQUE_ADDRESS   [[no_unique_address]]
 
#define MR_LIFETIMEBOUND
 
#define MR_LIFETIME_CAPTURE_BY(x)
 
#define MR_THIS_LIFETIME_CAPTURE_BY(x)
 
#define MR_LIFETIMEBOUND_NESTED
 
#define MR_THIS_LIFETIMEBOUND_NESTED
 
#define MR_LIFETIME_CAPTURE_BY_NESTED(x)
 
#define MR_THIS_LIFETIME_CAPTURE_BY_NESTED(x)
 
#define MR_LEGACY_MSVC_PREPROCESSOR   0
 Are we using the old buggy MSVC preprocessor?
 
#define MR_TRIM_LEADING_COMMA(...)   DETAIL_MR_TRIM_LEADING_COMMA_(__VA_ARGS__)
 MR_TRIM_LEADING_COMMA(,a,b,c) returns a,b,c.
 
#define DETAIL_MR_TRIM_LEADING_COMMA_(x, ...)   DETAIL_MR_TRIM_LEADING_COMMA_EMPTY(x) __VA_ARGS__
 
#define DETAIL_MR_TRIM_LEADING_COMMA_EMPTY()
 

Macro Definition Documentation

◆ DETAIL_MR_END

#define DETAIL_MR_END ( ...)    __VA_ARGS__##_END

◆ DETAIL_MR_TRIM_LEADING_COMMA_

#define DETAIL_MR_TRIM_LEADING_COMMA_ ( x,
... )   DETAIL_MR_TRIM_LEADING_COMMA_EMPTY(x) __VA_ARGS__

◆ DETAIL_MR_TRIM_LEADING_COMMA_EMPTY

#define DETAIL_MR_TRIM_LEADING_COMMA_EMPTY ( )

◆ MR_CONCAT

#define MR_CONCAT ( a,
b )   MR_CONCAT_( a, b )

Concat strings.

◆ MR_CONCAT3

#define MR_CONCAT3 ( a,
b,
c )   MR_CONCAT3_( a, b, c )

◆ MR_CONCAT3_

#define MR_CONCAT3_ ( a,
b,
c )   a##b##c

◆ MR_CONCAT_

#define MR_CONCAT_ ( a,
b )   a##b

◆ MR_END

#define MR_END ( ...)    DETAIL_MR_END(__VA_ARGS__)

A helper for writing preprocessor loops.

◆ MR_HAS_REQUIRES

#define MR_HAS_REQUIRES   0

If the compiler supports requires, expands to requires(...). Otherwise to nothing. This is primarily useful for code that must be usable in Cuda, since everywhere else we're free to use C++20 and newer. While Clang 14 technically supports requires, we're getting a few weird issues with it (make a nested aggregate class, in the enclosing class make a MR::Vector of it, observe that std::default_initializable gets baked as false on it, disabling some member functions such as .resize()).

◆ MR_IDENTITY

#define MR_IDENTITY ( ...)    __VA_ARGS__

Returns the argument unchanged.

◆ MR_LEGACY_MSVC_PREPROCESSOR

#define MR_LEGACY_MSVC_PREPROCESSOR   0

Are we using the old buggy MSVC preprocessor?

◆ MR_LIFETIME_CAPTURE_BY

#define MR_LIFETIME_CAPTURE_BY ( x)

◆ MR_LIFETIME_CAPTURE_BY_NESTED

#define MR_LIFETIME_CAPTURE_BY_NESTED ( x)

◆ MR_LIFETIMEBOUND

#define MR_LIFETIMEBOUND

Here we define following macros: MR[_THIS]_LIFETIMEBOUND[_NESTED] MR[_THIS]_LIFETIME_CAPTURE_BY[_NESTED](x) Those attributes can be used to help Clang emit more warnings. We also use them in generated bindings to control keep-alive (object lifetime extension). At the time of writing, this is only used in C#. MR_LIFETIMEBOUND can be placed either on a function parameter (immediately after the parameter name), or on this by placing it after the method parameter list (after const if any). It indicates that the return value preserves a reference to this parameter (or to this). For this attribute, constructors are considered to return the object that they construct. MR_LIFETIME_CAPTURE_BY(x) is usable in the same places. x must either be the name of another parameter of the same function, or this. It indicates that the reference to the parameter (that has the attribute) is saved not in the return value, but instead in the specified parameter (the argument of the attribute, which could be this). In constructors, MR_LIFETIME_CAPTURE_BY(this) has the same effect as MR_LIFETIMEBOUND, since this and the returned object are considered to be the same thing. The NESTED variants, instead of preserving references to the parameter they're on, indicate that we only want to preserve references to whatever it refers to. This is ideal for e.g. copy/move constructors and .push_back(), which accept references and then make a copy of the target object, without preserving the reference itself. Clang doesn't understand the nested version (so it doesn't enable any warnings), so this is purely for the bindings. The THIS variants have to be used when the attribute is applied to this (i.e. placed after a method parameter list), as opposed to being applied to a function parameter. If there's no THIS variant, it means the normal variant works in that case, just use that. In particular: The non-NESTED MR_LIFETIMEBOUND doesn't have a THIS variant. The non-NESTED MR_LIFETIME_CAPTURE_BY only needs a THIS variant as long as we need to support Clang older than 20. Once we update Clang, the THIS variant can be merged into the non-THIS one (TODO do this). See Clang docs for more details: https:/// clang.llvm.org/docs/AttributeReference.html::lifetimebound https:/// clang.llvm.org/docs/AttributeReference.html::lifetime-capture-by

◆ MR_LIFETIMEBOUND_NESTED

#define MR_LIFETIMEBOUND_NESTED

◆ MR_NO_UNIQUE_ADDRESS

#define MR_NO_UNIQUE_ADDRESS   [[no_unique_address]]

◆ MR_REQUIRES_IF_SUPPORTED

#define MR_REQUIRES_IF_SUPPORTED ( ...)

◆ MR_SAME_TYPE_TEMPLATE_PARAM

#define MR_SAME_TYPE_TEMPLATE_PARAM ( target_,
name_ )   typename name_ = target_

◆ MR_STR

#define MR_STR ( ...)    MR_STR_(__VA_ARGS__)

Those are generic helper macros that don't have their own headers.

Convert to a string.

◆ MR_STR_

#define MR_STR_ ( ...)    #__VA_ARGS__

◆ MR_THIS_LIFETIME_CAPTURE_BY

#define MR_THIS_LIFETIME_CAPTURE_BY ( x)

◆ MR_THIS_LIFETIME_CAPTURE_BY_NESTED

#define MR_THIS_LIFETIME_CAPTURE_BY_NESTED ( x)

◆ MR_THIS_LIFETIMEBOUND_NESTED

#define MR_THIS_LIFETIMEBOUND_NESTED

◆ MR_TRIM_LEADING_COMMA

#define MR_TRIM_LEADING_COMMA ( ...)    DETAIL_MR_TRIM_LEADING_COMMA_(__VA_ARGS__)