From a2dfde6a63d23a279b11c3e575b847d292f6e788 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sat, 3 Dec 2022 16:29:39 +0800 Subject: [PATCH] upd: [imp] add nodiscard for fmt --- benchmark/benchmark_fmt.cpp | 8 ++++---- include/libimp/fmt.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmark/benchmark_fmt.cpp b/benchmark/benchmark_fmt.cpp index 0693203..5203c3f 100644 --- a/benchmark/benchmark_fmt.cpp +++ b/benchmark/benchmark_fmt.cpp @@ -11,7 +11,7 @@ namespace { void imp_fmt_string(benchmark::State &state) { for (auto _ : state) { - imp::fmt("hello world. hello world. hello world. hello world. hello world."); + std::ignore = imp::fmt("hello world. hello world. hello world. hello world. hello world."); } } @@ -23,7 +23,7 @@ void fmt_format_string(benchmark::State &state) { void imp_fmt_int(benchmark::State &state) { for (auto _ : state) { - imp::fmt(654321); + std::ignore = imp::fmt(654321); } } @@ -35,7 +35,7 @@ void fmt_format_int(benchmark::State &state) { void imp_fmt_float(benchmark::State &state) { for (auto _ : state) { - imp::fmt(654.321); + std::ignore = imp::fmt(654.321); } } @@ -47,7 +47,7 @@ void fmt_format_float(benchmark::State &state) { void imp_fmt_chrono(benchmark::State &state) { for (auto _ : state) { - imp::fmt(std::chrono::system_clock::now()); + std::ignore = imp::fmt(std::chrono::system_clock::now()); } } diff --git a/include/libimp/fmt.h b/include/libimp/fmt.h index 89dc7b7..26f37a3 100644 --- a/include/libimp/fmt.h +++ b/include/libimp/fmt.h @@ -52,12 +52,12 @@ auto spec(char const (&fstr)[N]) noexcept { /// @brief String formatting function. template -std::string fmt(A &&a) { +LIBIMP_NODISCARD std::string fmt(A &&a) { return fmt_to_string(std::forward(a)); } template -std::string fmt(A1 &&a1, A &&...args) { +LIBIMP_NODISCARD std::string fmt(A1 &&a1, A &&...args) { std::string joined(fmt(std::forward(a1))); LIBIMP_UNUSED auto unfold = { joined.append(fmt_to_string(std::forward(args)))...