Skip to content

Commit 6577aeb

Browse files
committed
cpp2util.h: UFCS macro auto-dereference so that you can write . in most cases vs *..
1 parent 5127dd3 commit 6577aeb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

include/cpp2util.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
// in our -pure-cpp2 "import std;" simulation mode... if you need this,
192192
// use mixed mode (not -pure-cpp2) and #include all the headers you need
193193
// including this one
194-
//
194+
//
195195
// #include <execution>
196196
#endif
197197

@@ -629,6 +629,8 @@ class out {
629629
[](auto&& obj, auto&& ...params) CPP2_FORCE_INLINE -> decltype(auto) { \
630630
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); }) { \
631631
return std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); \
632+
} else if constexpr (requires{ std::forward<decltype(*obj)>(*obj).FUNCNAME(std::forward<decltype(params)>(params)...); }) { \
633+
return std::forward<decltype(*obj)>(*obj).FUNCNAME(std::forward<decltype(params)>(params)...); \
632634
} else { \
633635
return FUNCNAME(std::forward<decltype(obj)>(obj), std::forward<decltype(params)>(params)...); \
634636
} \
@@ -638,6 +640,8 @@ class out {
638640
[](auto&& obj) CPP2_FORCE_INLINE -> decltype(auto) { \
639641
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(); }) { \
640642
return std::forward<decltype(obj)>(obj).FUNCNAME(); \
643+
} else if constexpr (requires{ std::forward<decltype(*obj)>(*obj).FUNCNAME(); }) { \
644+
return std::forward<decltype(*obj)>(*obj).FUNCNAME(); \
641645
} else { \
642646
return FUNCNAME(std::forward<decltype(obj)>(obj)); \
643647
} \
@@ -649,6 +653,8 @@ class out {
649653
[](auto&& obj, auto&& ...params) CPP2_FORCE_INLINE -> decltype(auto) { \
650654
if constexpr (requires{ std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(params)>(params)...); }) { \
651655
return std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(params)>(params)...); \
656+
} else if constexpr (requires{ std::forward<decltype(*obj)>(*obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(params)>(params)...); }) { \
657+
return std::forward<decltype(*obj)>(*obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(params)>(params)...); \
652658
} else { \
653659
return FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(obj)>(obj), std::forward<decltype(params)>(params)...); \
654660
} \
@@ -658,6 +664,8 @@ class out {
658664
[](auto&& obj) CPP2_FORCE_INLINE -> decltype(auto) { \
659665
if constexpr (requires{ std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (); }) { \
660666
return std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (); \
667+
} else if constexpr (requires{ std::forward<decltype(*obj)>(*obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (); }) { \
668+
return std::forward<decltype(*obj)>(*obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (); \
661669
} else { \
662670
return FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(obj)>(obj)); \
663671
} \
@@ -731,17 +739,17 @@ auto is( X const& ) -> bool {
731739

732740
template< typename C, typename X >
733741
requires (
734-
( std::is_base_of_v<X, C> ||
735-
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
742+
( std::is_base_of_v<X, C> ||
743+
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
736744
) && !std::is_same_v<C,X>)
737745
auto is( X const& x ) -> bool {
738746
return Dynamic_cast<C const*>(&x) != nullptr;
739747
}
740748

741749
template< typename C, typename X >
742750
requires (
743-
( std::is_base_of_v<X, C> ||
744-
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
751+
( std::is_base_of_v<X, C> ||
752+
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
745753
) && !std::is_same_v<C,X>)
746754
auto is( X const* x ) -> bool {
747755
return Dynamic_cast<C const*>(x) != nullptr;
@@ -1314,7 +1322,7 @@ inline auto to_string(std::string const& s) -> std::string const&
13141322

13151323
template<typename T>
13161324
inline auto to_string(T const& sv) -> std::string
1317-
requires (std::is_convertible_v<T, std::string_view>
1325+
requires (std::is_convertible_v<T, std::string_view>
13181326
&& !std::is_convertible_v<T, const char*>)
13191327
{
13201328
return std::string{sv};

0 commit comments

Comments
 (0)