fix: error C2535 for vs2015

This commit is contained in:
mutouyun 2022-11-19 22:33:59 +08:00
parent 093597ca66
commit 16c16ad3d0
5 changed files with 24 additions and 23 deletions

View File

@ -6,14 +6,14 @@
namespace {
void BM_imp_log_no_output(benchmark::State& state) {
imp::log::gripper log {__func__, {}};
imp::log::grip log {__func__, {}};
for (auto _ : state) {
log.debug("hello log.");
}
}
void BM_imp_log_gripper(benchmark::State& state) {
imp::log::gripper log {__func__, {}};
imp::log::grip log {__func__, {}};
for (auto _ : state) {
log.info("hello log.");
}

View File

@ -53,15 +53,11 @@ template <typename T>
class has_fn_output {
static std::integral_constant<out_type, out_none> check(...);
template <typename U>
static auto check(U *u)
-> decltype(u->output(log::level::trace, std::declval<std::string>()),
std::integral_constant<out_type, out_string>{});
template <typename U, typename = decltype(u->output(log::level::trace, std::declval<std::string>()))>
static std::integral_constant<out_type, out_string> check(U *u);
template <typename U>
static auto check(U *u)
-> decltype(u->output(log::level::trace, std::declval<log::context>()),
std::integral_constant<out_type, out_context>{});
template <typename U, typename = decltype(u->output(std::declval<log::context>()))>
static std::integral_constant<out_type, out_context> check(U *u);
public:
using type = decltype(check(static_cast<T *>(nullptr)));
@ -129,20 +125,25 @@ public:
void output(context) noexcept;
};
/// @brief Standard console output.
class LIBIMP_EXPORT std_t {
public:
void output(log::level, std::string &&) noexcept;
};
/// @brief Standard console output object.
LIBIMP_EXPORT extern std_t std_out;
class gripper {
/**
* @brief Log information grips.
*/
class grip {
printer printer_;
char const *func_;
level level_limit_;
template <typename Fmt, typename... A>
gripper &output(log::level l, Fmt &&ft, A &&... args) noexcept {
grip &output(log::level l, Fmt &&ft, A &&... args) noexcept {
if (!printer_ || (enum_cast(l) < enum_cast(level_limit_))) {
return *this;
}
@ -163,33 +164,33 @@ class gripper {
}
public:
gripper(char const *func, printer printer = std_out, level level_limit = level::info) noexcept
grip(char const *func, printer printer = std_out, level level_limit = level::info) noexcept
: printer_ (printer)
, func_ (func)
, level_limit_(level_limit) {}
template <typename Fmt, typename... A>
gripper &trace(Fmt &&ft, A &&... args) noexcept {
grip &trace(Fmt &&ft, A &&... args) noexcept {
return output(log::level::trace, std::forward<Fmt>(ft), std::forward<A>(args)...);
}
template <typename Fmt, typename... A>
gripper &debug(Fmt &&ft, A &&... args) noexcept {
grip &debug(Fmt &&ft, A &&... args) noexcept {
return output(log::level::debug, std::forward<Fmt>(ft), std::forward<A>(args)...);
}
template <typename Fmt, typename... A>
gripper &info(Fmt &&ft, A &&... args) noexcept {
grip &info(Fmt &&ft, A &&... args) noexcept {
return output(log::level::info, std::forward<Fmt>(ft), std::forward<A>(args)...);
}
template <typename Fmt, typename... A>
gripper &warning(Fmt &&ft, A &&... args) noexcept {
grip &warning(Fmt &&ft, A &&... args) noexcept {
return output(log::level::warning, std::forward<Fmt>(ft), std::forward<A>(args)...);
}
template <typename Fmt, typename... A>
gripper &error(Fmt &&ft, A &&... args) noexcept {
grip &error(Fmt &&ft, A &&... args) noexcept {
return output(log::level::error, std::forward<Fmt>(ft), std::forward<A>(args)...);
}
template <typename Fmt, typename... A>
gripper &failed(Fmt &&ft, A &&... args) noexcept {
grip &failed(Fmt &&ft, A &&... args) noexcept {
return output(log::level::failed, std::forward<Fmt>(ft), std::forward<A>(args)...);
}
};
@ -197,4 +198,4 @@ public:
} // namespace log
LIBIMP_NAMESPACE_END_
#define LIBIMP_LOG_(...) ::LIBIMP_::log::gripper log {__func__, __VA_ARGS__}
#define LIBIMP_LOG_(...) ::LIBIMP_::log::grip log {__func__, __VA_ARGS__}

View File

@ -28,7 +28,7 @@ inline LPSECURITY_ATTRIBUTES get_sa() {
initiator() {
using namespace ::LIBIMP_;
log::gripper log {"get_sa"};
log::grip log {"get_sa"};
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
log.error("failed: InitializeSecurityDescriptor(SECURITY_DESCRIPTOR_REVISION). error = {}", sys::error());
return;

View File

@ -13,7 +13,7 @@ namespace {
/**
* @brief Check that bytes is not 0 and that the alignment is a power of two.
*/
bool verify_args(::LIBIMP_::log::gripper &log, std::size_t bytes, std::size_t alignment) noexcept {
bool verify_args(::LIBIMP_::log::grip &log, std::size_t bytes, std::size_t alignment) noexcept {
if (bytes == 0) {
return false;
}

View File

@ -74,7 +74,7 @@ TEST(log, log_printer) {
TEST(log, gripper) {
{
imp::log::gripper log {__func__};
imp::log::grip log {__func__};
log.info("hello");
}
{