Skip to content

Commit

Permalink
Implement forward_like
Browse files Browse the repository at this point in the history
  • Loading branch information
lackhole committed Aug 11, 2024
1 parent d95b6e8 commit 5ebb4a4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/preview/__functional/bind_back.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "preview/__functional/invoke.h"
#include "preview/__type_traits/conjunction.h"
#include "preview/__type_traits/is_invocable.h"
#include "preview/__type_traits/copy_cvref.h"
#include "preview/__utility/forward_like.h"

namespace preview {
namespace detail {
Expand All @@ -23,11 +23,11 @@ class bind_partial_back : bind_partial<bind_partial_back<FD, BoundArgs...>, FD,

template<typename Self, typename... CallArgs>
struct bind_invocable
: is_invocable<copy_cvref_t<Self, FD>, CallArgs..., copy_cvref_t<Self, BoundArgs>...> {};
: is_invocable<forward_like_t<Self, FD>, CallArgs..., forward_like_t<Self, BoundArgs>...> {};

template<typename Self, typename... CallArgs>
struct bind_nothrow_invocable
: is_nothrow_invocable<copy_cvref_t<Self, FD>, CallArgs..., copy_cvref_t<Self, BoundArgs>...> {};
: is_nothrow_invocable<forward_like_t<Self, FD>, CallArgs..., forward_like_t<Self, BoundArgs>...> {};

template<typename F, typename BoundArgsTuple, std::size_t...I, typename... CallArgs>
static constexpr decltype(auto) call(F&& f, BoundArgsTuple&& tup, std::index_sequence<I...>, CallArgs&&... call_args)
Expand Down
6 changes: 3 additions & 3 deletions include/preview/__functional/bind_front.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "preview/__functional/invoke.h"
#include "preview/__type_traits/conjunction.h"
#include "preview/__type_traits/is_invocable.h"
#include "preview/__type_traits/copy_cvref.h"
#include "preview/__utility/forward_like.h"

namespace preview {
namespace detail {
Expand All @@ -22,11 +22,11 @@ class bind_partial_front : bind_partial<bind_partial_front<FD, BoundArgs...>, FD

template<typename Self, typename... CallArgs>
struct bind_invocable
: is_invocable<copy_cvref_t<Self, FD>, copy_cvref_t<Self, BoundArgs>..., CallArgs...> {};
: is_invocable<forward_like_t<Self, FD>, forward_like_t<Self, BoundArgs>..., CallArgs...> {};

template<typename Self, typename... CallArgs>
struct bind_nothrow_invocable
: is_nothrow_invocable<copy_cvref_t<Self, FD>, copy_cvref_t<Self, BoundArgs>..., CallArgs...> {};
: is_nothrow_invocable<forward_like_t<Self, FD>, forward_like_t<Self, BoundArgs>..., CallArgs...> {};

template<typename F, typename BoundArgsTuple, std::size_t...I, typename... CallArgs>
static constexpr decltype(auto) call(F&& f, BoundArgsTuple&& tup, std::index_sequence<I...>, CallArgs&&... call_args)
Expand Down
26 changes: 26 additions & 0 deletions include/preview/__utility/forward_like.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by yonggyulee on 2024. 8. 10.
//

#ifndef PREVIEW_UTILITY_FORWARD_LIKE_H_
#define PREVIEW_UTILITY_FORWARD_LIKE_H_

#include <type_traits>

#include "preview/__type_traits/copy_cvref.h"

namespace preview {

template<typename T, typename U>
constexpr auto&& forward_like(U&& x) noexcept {
using CU = copy_const_t<std::remove_reference_t<T>, std::remove_reference_t<U>>;
using RU = std::conditional_t<std::is_rvalue_reference<T>::value, std::remove_reference_t<CU>&&, CU&>;
return static_cast<RU>(x);
}

template<typename T, typename U>
using forward_like_t = decltype(preview::forward_like<T>(std::declval<U>()));

} // namespace preview

#endif // PREVIEW_UTILITY_FORWARD_LIKE_H_
1 change: 1 addition & 0 deletions include/preview/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "preview/__utility/cmp.h"
#include "preview/__utility/compressed_pair.h"
#include "preview/__utility/cxx20_rel_ops.h"
#include "preview/__utility/forward_like.h"
#include "preview/__utility/in_place.h"
#include "preview/__utility/in_range.h"
#include "preview/__utility/integer_sequence.h"
Expand Down

0 comments on commit 5ebb4a4

Please sign in to comment.