Skip to content

Commit 105926c

Browse files
committed
use std::source_location where possible to get a type's pretty name
1 parent 835bc0d commit 105926c

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

include/stdexec/__detail/__meta.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <cassert>
2424
#include <compare>
2525
#include <cstddef>
26+
#include <source_location> // IWYU pragma: keep for std::source_location::current
2627
#include <string_view>
2728
#include <type_traits>
2829

@@ -815,23 +816,27 @@ namespace STDEXEC {
815816
return __sv.substr(__start, __len);
816817
}
817818

818-
template <class T>
819+
template <class _Ty>
819820
[[nodiscard]]
820821
consteval std::string_view __get_pretty_name_helper() noexcept {
822+
#if STDEXEC_EDG()
821823
return __detail::__find_pretty_name(std::string_view{STDEXEC_PRETTY_FUNCTION()});
824+
#else
825+
return __detail::__find_pretty_name(std::source_location::current().function_name());
826+
#endif
822827
}
823828

824-
template <class T>
829+
template <class _Ty>
825830
[[nodiscard]]
826831
consteval std::string_view __get_pretty_name() noexcept {
827-
return __detail::__get_pretty_name_helper<typename __xyzzy<T>::__plugh>();
832+
return __detail::__get_pretty_name_helper<typename __xyzzy<_Ty>::__plugh>();
828833
}
829834
} // namespace __detail
830835

831836
////////////////////////////////////////////////////////////////////////////////////////////
832-
// __mnameof: get the pretty name of a type T as a string_view at compile time
833-
template <class T>
834-
inline constexpr std::string_view __mnameof = __detail::__get_pretty_name<__demangle_t<T>>();
837+
// __mnameof: get the pretty name of a type _Ty as a string_view at compile time
838+
template <class _Ty>
839+
inline constexpr std::string_view __mnameof = __detail::__get_pretty_name<__demangle_t<_Ty>>();
835840

836841
static_assert(__mnameof<int> == "int");
837842

@@ -841,13 +846,13 @@ namespace STDEXEC {
841846
concept __has_id = requires { typename _Ty::__id; };
842847

843848
//! Identity mapping `_Ty` to itself.
844-
//! That is, `__same_as<T, typename _Id<T>::__t>`.
849+
//! That is, `__same_as<_Ty, typename _Id<_Ty>::__t>`.
845850
template <class _Ty>
846851
struct _Id {
847852
using __t = _Ty;
848853

849854
// Uncomment the line below to find any code that likely misuses the
850-
// ADL isolation mechanism. In particular, '__id<T>' when T is a
855+
// ADL isolation mechanism. In particular, '__id<_Ty>' when _Ty is a
851856
// reference is a likely misuse. The static_assert below will trigger
852857
// when the type passed to the __id alias template is a reference to
853858
// a type that is setup to use ADL isolation.

include/stdexec/__detail/__typeinfo.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <string_view>
2626

2727
//////////////////////////////////////////////////////////////////////////////////////////
28-
// __type_info and TYPEID
28+
// __type_info, __mtypeid, and __mtypeof
2929

3030
namespace STDEXEC {
3131
//////////////////////////////////////////////////////////////////////////////////////////
@@ -39,8 +39,8 @@ namespace STDEXEC {
3939
}
4040

4141
[[nodiscard]]
42-
constexpr const char *name() const noexcept {
43-
return __name_.data();
42+
constexpr std::string_view name() const noexcept {
43+
return __name_;
4444
}
4545

4646
auto operator==(const __type_info &) const noexcept -> bool = default;
@@ -50,6 +50,14 @@ namespace STDEXEC {
5050
std::string_view __name_;
5151
};
5252

53+
namespace __detail {
54+
template <class _Ty>
55+
inline constexpr __type_info __mtypeid_v{__mnameof<_Ty>};
56+
57+
template <class _Ty>
58+
inline constexpr const __type_info &__mtypeid_v<_Ty const> = __mtypeid_v<_Ty>;
59+
} // namespace __detail
60+
5361
//////////////////////////////////////////////////////////////////////////////////////////
5462
// __type_index
5563
struct __type_index {
@@ -58,8 +66,8 @@ namespace STDEXEC {
5866
}
5967

6068
[[nodiscard]]
61-
constexpr char const *name() const noexcept {
62-
return __info_->name();
69+
constexpr std::string_view name() const noexcept {
70+
return (*__info_).name();
6371
}
6472

6573
[[nodiscard]]
@@ -76,12 +84,6 @@ namespace STDEXEC {
7684
};
7785

7886
namespace __detail {
79-
template <class _Ty>
80-
inline constexpr __type_info __mtypeid_v{__mnameof<_Ty>};
81-
82-
template <class _Ty>
83-
inline constexpr const __type_info &__mtypeid_v<_Ty const> = __mtypeid_v<_Ty>;
84-
8587
STDEXEC_PRAGMA_PUSH()
8688
STDEXEC_PRAGMA_IGNORE_GNU("-Wnon-template-friend")
8789
STDEXEC_PRAGMA_IGNORE_EDG(probable_guiding_friend)

0 commit comments

Comments
 (0)