forked from boostorg/core
Add snprintf macro
This commit is contained in:
@@ -185,14 +185,23 @@ template<class T> std::string array_template_name()
|
|||||||
# pragma warning( disable: 4996 )
|
# pragma warning( disable: 4996 )
|
||||||
#endif
|
#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 )
|
inline std::string tn_to_string( std::size_t n )
|
||||||
{
|
{
|
||||||
char buffer[ 32 ];
|
char buffer[ 32 ];
|
||||||
std::sprintf( buffer, "%lu", static_cast< unsigned long >( n ) );
|
BOOST_CORE_SNPRINTF( buffer, "%lu", static_cast< unsigned long >( n ) );
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef BOOST_CORE_SNPRINTF
|
||||||
|
|
||||||
#if defined(BOOST_MSVC)
|
#if defined(BOOST_MSVC)
|
||||||
# pragma warning( pop )
|
# pragma warning( pop )
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user