Skip to content

Commit

Permalink
Merge pull request #2320 from nvmkuruc/tfnoboostpp
Browse files Browse the repository at this point in the history
Remove preprocessor usage in macros in `pxr/base/tf`

(Internal change: 2282463)
  • Loading branch information
pixar-oss committed Jun 23, 2023
2 parents f9e9477 + 77c23ea commit 68755eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
7 changes: 2 additions & 5 deletions pxr/base/tf/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "pxr/base/tf/safeTypeCompare.h"
#include "pxr/base/tf/api.h"

#include <boost/preprocessor/punctuation/comma_if.hpp>

#include <iosfwd>
#include <string>
Expand Down Expand Up @@ -470,10 +469,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

Expand Down
24 changes: 20 additions & 4 deletions pxr/base/tf/scopeDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "pxr/base/tf/api.h"

#include <boost/optional.hpp>
#include <boost/preprocessor/if.hpp>

#include <vector>
#include <string>
Expand Down Expand Up @@ -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 <typename... Args>
inline std::string
Tf_DescribeScopeFormat(const char* fmt, Args&&... args) {
return TfStringPrintf(fmt, std::forward<Args>(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

Expand Down

0 comments on commit 68755eb

Please sign in to comment.