🔥 conditional_cast
This commit is contained in:
		@@ -30,7 +30,7 @@
 | 
				
			|||||||
#                define SPDLOG_API __declspec(dllimport)
 | 
					#                define SPDLOG_API __declspec(dllimport)
 | 
				
			||||||
#            endif
 | 
					#            endif
 | 
				
			||||||
#        else // !defined(_WIN32)
 | 
					#        else // !defined(_WIN32)
 | 
				
			||||||
#            define SPDLOG_API __attribute__((visibility ("default")))
 | 
					#            define SPDLOG_API __attribute__((visibility("default")))
 | 
				
			||||||
#        endif
 | 
					#        endif
 | 
				
			||||||
#    else // !defined(SPDLOG_SHARED_LIB)
 | 
					#    else // !defined(SPDLOG_SHARED_LIB)
 | 
				
			||||||
#        define SPDLOG_API
 | 
					#        define SPDLOG_API
 | 
				
			||||||
@@ -320,13 +320,27 @@ struct file_event_handlers
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace details {
 | 
					namespace details {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
 | 
				
			||||||
 | 
					template<typename T, typename U, std::enable_if_t<!std::is_same<T, U>::value, int> = 0>
 | 
				
			||||||
 | 
					constexpr T conditional_static_cast(U value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return static_cast<T>(value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<typename T, typename U, std::enable_if_t<std::is_same<T, U>::value, int> = 0>
 | 
				
			||||||
 | 
					constexpr T conditional_static_cast(U value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// make_unique support for pre c++14
 | 
					// make_unique support for pre c++14
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if __cplusplus >= 201402L // C++14 and beyond
 | 
					#if __cplusplus >= 201402L // C++14 and beyond
 | 
				
			||||||
using std::make_unique;
 | 
					using std::make_unique;
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
template<typename T, typename... Args>
 | 
					template<typename T, typename... Args>
 | 
				
			||||||
std::unique_ptr<T> make_unique(Args &&... args)
 | 
					std::unique_ptr<T> make_unique(Args &&...args)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static_assert(!std::is_array<T>::value, "arrays not supported");
 | 
					    static_assert(!std::is_array<T>::value, "arrays not supported");
 | 
				
			||||||
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
 | 
					    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -405,9 +405,9 @@ SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
    return static_cast<int>(::GetCurrentProcessId());
 | 
					    return conditional_static_cast<int>(::GetCurrentProcessId());
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    return static_cast<int>(::getpid());
 | 
					    return conditional_static_cast<int>(::getpid());
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user