Skip to content

Commit

Permalink
Replace 'std::result_of' by 'std::invoke_result' where possible
Browse files Browse the repository at this point in the history
C++17 deprecated 'std::result_of' in favour of 'std::invoke_result' and will ban it outright in C++20.

- Replace all uses of 'internal::result_of' in {fmt} by 'internal::invoke_result'.
- Import name 'std::invoke_result' into fmt's internal namespace when compiling C++17 mode.
- Implement 'internal::invoke_result' in terms of 'std::result_of' when compiling in modes C++11 or C++14.

Signed-off-by: Daniela Engert <[email protected]>
  • Loading branch information
DanielaE committed Feb 3, 2019
1 parent 7fbbfed commit c08ee68
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,17 @@ namespace internal {
template <typename T>
typename std::add_rvalue_reference<T>::type declval() FMT_NOEXCEPT;

template <typename> struct result_of;

template <typename F, typename... Args> struct result_of<F(Args...)> {
// A workaround for gcc 4.4 that doesn't allow F to be a reference.
typedef typename std::result_of<typename std::remove_reference<F>::type(
Args...)>::type type;
};
#if (__cplusplus >= 201703L || \
(defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && \
__cpp_lib_is_invocable >= 201703L
using std::invoke_result;
#else
template <typename> struct invoke_result;
// A workaround for gcc 4.4 that doesn't allow F to be a reference.
template <typename F, typename... Args>
struct invoke_result<F(Args...)>
: std::result_of<typename std::remove_reference<F>::type(Args...)> {};
#endif

// Casts nonnegative integer to unsigned.
template <typename Int>
Expand Down Expand Up @@ -847,7 +851,7 @@ template <typename Context> class basic_format_arg {
const T& value);

template <typename Visitor, typename Ctx>
friend FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
friend FMT_CONSTEXPR typename internal::invoke_result<Visitor(int)>::type
visit_format_arg(Visitor&& vis, const basic_format_arg<Ctx>& arg);

friend class basic_format_args<Context>;
Expand Down Expand Up @@ -888,7 +892,7 @@ struct monostate {};
\endrst
*/
template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type visit_format_arg(
FMT_CONSTEXPR typename internal::invoke_result<Visitor(int)>::type visit_format_arg(
Visitor&& vis, const basic_format_arg<Context>& arg) {
typedef typename Context::char_type char_type;
switch (arg.type_) {
Expand Down Expand Up @@ -927,7 +931,7 @@ FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type visit_format_arg(
}

template <typename Visitor, typename Context>
FMT_DEPRECATED FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
FMT_DEPRECATED FMT_CONSTEXPR typename internal::invoke_result<Visitor(int)>::type
visit(Visitor&& vis, const basic_format_arg<Context>& arg) {
return visit_format_arg(std::forward<Visitor>(vis), arg);
}
Expand Down

0 comments on commit c08ee68

Please sign in to comment.