From 77c23ea0a9e27cd05eebb71d3a703884cb4cf0d8 Mon Sep 17 00:00:00 2001 From: Matt Kuruc Date: Wed, 1 Mar 2023 15:45:34 -0800 Subject: [PATCH] Remove preprocessor usage in macros in `pxr/base/tf` --- pxr/base/tf/enum.h | 7 ++----- pxr/base/tf/scopeDescription.h | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pxr/base/tf/enum.h b/pxr/base/tf/enum.h index 4854918b92..e81b498e10 100644 --- a/pxr/base/tf/enum.h +++ b/pxr/base/tf/enum.h @@ -37,7 +37,6 @@ #include "pxr/base/tf/api.h" #include -#include #include #include @@ -447,10 +446,8 @@ TF_API std::ostream& operator<<(std::ostream& out, const TfEnum & e); /// \ingroup group_tf_RuntimeTyping /// \hideinitializer #define TF_ADD_ENUM_NAME(VAL, ...) \ - TfEnum::_AddName(VAL, \ - TF_PP_STRINGIZE(VAL) \ - BOOST_PP_COMMA_IF(TF_NUM_ARGS(__VA_ARGS__)) \ - __VA_ARGS__) + TfEnum::_AddName(VAL, TF_PP_STRINGIZE(VAL), \ + std::string{__VA_ARGS__}); PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/base/tf/scopeDescription.h b/pxr/base/tf/scopeDescription.h index 34a0941fc9..f38e506d86 100644 --- a/pxr/base/tf/scopeDescription.h +++ b/pxr/base/tf/scopeDescription.h @@ -32,7 +32,6 @@ #include "pxr/base/tf/api.h" #include -#include #include #include @@ -133,10 +132,27 @@ TfGetThisThreadScopeDescriptionStack(); /// Macro that accepts either a single string, or printf-style arguments and /// creates a scope description local variable with the resulting string. -#define TF_DESCRIBE_SCOPE(fmt, ...) \ +#define TF_DESCRIBE_SCOPE(...) \ TfScopeDescription __scope_description__ \ - (BOOST_PP_IF(TF_NUM_ARGS(__VA_ARGS__), \ - TfStringPrintf(fmt, __VA_ARGS__), fmt), TF_CALL_CONTEXT) + (Tf_DescribeScopeFormat(__VA_ARGS__), TF_CALL_CONTEXT); \ + +template +inline std::string +Tf_DescribeScopeFormat(const char* fmt, Args&&... args) { + return TfStringPrintf(fmt, std::forward(args)...); +} + +// If there are no formatting arguments, the string can be forwarded to the +// scope description constructor. In C++17, consider if std::string_view could +// reduce the need for as many of these overloads +inline const char* +Tf_DescribeScopeFormat(const char* fmt) { return fmt; } + +inline std::string&& +Tf_DescribeScopeFormat(std::string&& fmt) { return std::move(fmt); } + +inline const std::string& +Tf_DescribeScopeFormat(const std::string& fmt) { return fmt; } PXR_NAMESPACE_CLOSE_SCOPE