mirror of
https://github.com/boostorg/core.git
synced 2025-08-01 13:54:35 +02:00
Add snprintf macro
This commit is contained in:
@@ -185,14 +185,23 @@ template<class T> std::string array_template_name()
|
||||
# pragma warning( disable: 4996 )
|
||||
#endif
|
||||
|
||||
// Use snprintf if available as some compilers (clang 14.0) issue deprecation warnings for sprintf
|
||||
#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) )
|
||||
# define BOOST_CORE_SNPRINTF(buffer, format, arg) std::sprintf(buffer, format, arg)
|
||||
#else
|
||||
# define BOOST_CORE_SNPRINTF(buffer, format, arg) std::snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), format, arg)
|
||||
#endif
|
||||
|
||||
inline std::string tn_to_string( std::size_t n )
|
||||
{
|
||||
char buffer[ 32 ];
|
||||
std::sprintf( buffer, "%lu", static_cast< unsigned long >( n ) );
|
||||
BOOST_CORE_SNPRINTF( buffer, "%lu", static_cast< unsigned long >( n ) );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#undef BOOST_CORE_SNPRINTF
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user