Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++26 reference_wrapper #61

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions include/preview/__compare/synth_three_way.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by yonggyulee on 2024. 10. 17.
//

#ifndef PREVIEW_COMPARE_SYNTH_THREE_WAY_H_
#define PREVIEW_COMPARE_SYNTH_THREE_WAY_H_

#include <type_traits>

#include "preview/__concepts/boolean_testable.h"
#include "preview/__type_traits/conjunction.h"
#include "preview/__utility/cxx20_rel_ops.h"

namespace preview {
namespace detail {

template<typename T, typename U,
bool = /* false */ conjunction_v<
rel_ops::is_less_than_comparable<const T&, const U&>,
rel_ops::is_less_equal_than_comparable<const U&, const T&>
>
>
struct synth_three_way_possible : std::false_type {};

template<typename T, typename U>
struct synth_three_way_possible<T, U, true>
: conjunction<
boolean_testable<decltype(std::declval<const T&>() < std::declval<const U&>())>,
boolean_testable<decltype(std::declval<const U&>() < std::declval<const T&>())>
> {};

} // namespace detail
} // namespace preview

#endif // PREVIEW_COMPARE_SYNTH_THREE_WAY_H_
37 changes: 11 additions & 26 deletions include/preview/__concepts/boolean_testable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,29 @@
namespace preview {
namespace detail {

template<typename B>
struct boolean_testable_impl : convertible_to<B, bool> {};
template<typename T>
struct boolean_testable_impl : convertible_to<T, bool> {};

template<typename T, typename = void>
struct is_explicitly_negatable : std::false_type {};
template<typename T>
struct is_explicitly_negatable<T, void_t<decltype(!std::declval<T>())> > : std::true_type {};

template<
typename B,
bool =
conjunction<
is_explicitly_negatable<std::add_lvalue_reference_t<std::remove_reference_t<B>>>,
is_explicitly_negatable<std::add_rvalue_reference_t<std::remove_reference_t<B>>>
>::value
>
template<typename T, bool = /* false */ is_explicitly_negatable<T>::value>
struct boolean_testable_stage_2 : std::false_type {};
template<typename T>
struct boolean_testable_stage_2<T, true> : boolean_testable_impl<decltype(!std::declval<T>())> {};

template<typename B>
struct boolean_testable_stage_2<B, true>
: conjunction<
boolean_testable_impl<decltype(!std::declval< std::add_lvalue_reference_t<std::remove_reference_t<B>> >())>,
boolean_testable_impl<decltype(!std::declval< std::add_rvalue_reference_t<std::remove_reference_t<B>> >())>
> {};

template<
typename B,
bool = conjunction<boolean_testable_impl<B>, is_referencable<B>>::value
>
template<typename T, bool = /* false */ boolean_testable_impl<T>::value>
struct boolean_testable_stage_1 : std::false_type {};

template<typename B>
struct boolean_testable_stage_1<B, true> : boolean_testable_stage_2<B> {};
template<typename T>
struct boolean_testable_stage_1<T, true> : boolean_testable_stage_2<T> {};

} // namespace detail

template<typename B>
struct boolean_testable : detail::boolean_testable_stage_1<B> {};
// TODO: concept
template<typename T>
struct boolean_testable : detail::boolean_testable_stage_1<T> {};

} // namespace preview

Expand Down
21 changes: 21 additions & 0 deletions include/preview/__functional/is_reference_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by yonggyulee on 2024. 10. 17.
//

#ifndef PREVIEW_FUNCTIONAL_IS_REFERENCE_WRAPPER_H_
#define PREVIEW_FUNCTIONAL_IS_REFERENCE_WRAPPER_H_

#include <functional>
#include <type_traits>

namespace preview {

template<typename T>
struct is_reference_wrapper : std::false_type {};

template<typename T>
struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};

} // namespace preview

#endif // PREVIEW_FUNCTIONAL_IS_REFERENCE_WRAPPER_H_
Loading
Loading