-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OrcLib: Text: Fmt: add specialization for Result
- Loading branch information
1 parent
b4e00ee
commit 2053818
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
// | ||
// Copyright © 2020 ANSSI. All Rights Reserved. | ||
// | ||
// Author(s): fabienfl (ANSSI) | ||
// | ||
|
||
#pragma once | ||
|
||
#include <fmt/format.h> | ||
#include <boost/outcome/outcome.hpp> | ||
|
||
template <typename T> | ||
struct fmt::formatter<boost::outcome_v2::std_result<T>> : public fmt::formatter<std::string_view> | ||
{ | ||
template <typename FormatContext> | ||
auto format(const boost::outcome_v2::std_result<T>& result, FormatContext& ctx) -> decltype(ctx.out()); | ||
}; | ||
|
||
template <typename T> | ||
struct fmt::formatter<boost::outcome_v2::std_result<T>, wchar_t> : public fmt::formatter<std::wstring_view, wchar_t> | ||
{ | ||
template <typename FormatContext> | ||
auto format(const boost::outcome_v2::std_result<T>& result, FormatContext& ctx) -> decltype(ctx.out()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
// | ||
// Copyright © 2020 ANSSI. All Rights Reserved. | ||
// | ||
// Author(s): fabienfl (ANSSI) | ||
// | ||
|
||
#pragma once | ||
|
||
#include "Output/Text/Fmt/Fwd/Result.h" | ||
|
||
#include "Utils/Result.h" | ||
|
||
template <typename T> | ||
template <typename FormatContext> | ||
auto fmt::formatter<Orc::Result<T>>::format(const Orc::Result<T>& result, FormatContext& ctx) -> decltype(ctx.out()) | ||
{ | ||
if (result.has_error()) | ||
{ | ||
const auto msg = fmt::format("{}", result.error()); | ||
return fmt::formatter<std::string_view>::format(msg, ctx); | ||
} | ||
|
||
return formatter<std::string_view>::format("Success", ctx); | ||
} | ||
|
||
template <typename T> | ||
template <typename FormatContext> | ||
auto fmt::formatter<Orc::Result<T>, wchar_t>::format(const Orc::Result<T>& result, FormatContext& ctx) | ||
-> decltype(ctx.out()) | ||
{ | ||
if (result.has_error()) | ||
{ | ||
const auto msg = fmt::format(L"{}", result.error()); | ||
return fmt::formatter<std::wstring_view, wchar_t>::format(msg, ctx); | ||
} | ||
|
||
return formatter<std::wstring_view, wchar_t>::format(L"Success", ctx); | ||
} |