Skip to content

Commit 910d8a7

Browse files
committed
allow for stdexec::type_info to be expanded in the future
1 parent 8acfcfb commit 910d8a7

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

.clangd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ CompileFlags:
4040
- "-Wno-unknown-cuda-version"
4141
- "--cuda-host-only"
4242
- "--cuda-path=/usr/local/cuda-12"
43+
Remove:
44+
- "-x"
45+
- "c++-header"
4346

4447
---
4548

@@ -54,7 +57,6 @@ CompileFlags:
5457
- "-ftemplate-backtrace-limit=0"
5558
- "-std=c++20"
5659
- "-DSTDEXEC_CLANGD_INVOKED"
57-
- "-stdlib=libc++"
5860
- "-Wno-unused-local-typedef"
5961
Remove:
6062
- "-stdpar*"

include/stdexec/__detail/__config.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,19 @@ namespace STDEXEC
602602
# define STDEXEC_NO_STDCPP_EXPLICIT_THIS_PARAMETER() 1
603603
#endif
604604

605+
#if defined(__cpp_rtti) && __cpp_rtti >= 1997'11L
606+
# define STDEXEC_NO_STDCPP_RTTI() 0
607+
#else
608+
# define STDEXEC_NO_STDCPP_RTTI() 1
609+
#endif
610+
611+
// MSVC always has typeid support, even when RTTI is disabled
612+
#if STDEXEC_NO_STDCPP_RTTI() && !STDEXEC_MSVC()
613+
# define STDEXEC_NO_STDCPP_TYPEID() 1
614+
#else
615+
# define STDEXEC_NO_STDCPP_TYPEID() 0
616+
#endif
617+
605618
// Perhaps the stdlib lacks support for concepts
606619
#if __has_include(<concepts>) && __cpp_lib_concepts >= 2020'02L
607620
# define STDEXEC_NO_STDCPP_CONCEPTS_HEADER() 0

include/stdexec/__detail/__parallel_scheduler_backend.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "__any_allocator.hpp"
2626
#include "__optional.hpp"
2727
#include "__queries.hpp"
28+
#include "__schedulers.hpp"
2829
#include "__typeinfo.hpp"
2930

3031
#include <exception>

include/stdexec/__detail/__typeinfo.hpp

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
#include <compare>
2525
#include <string_view>
26+
#include <typeinfo>
27+
28+
STDEXEC_PRAGMA_PUSH()
29+
STDEXEC_PRAGMA_IGNORE_GNU("-Wunused-private-field")
2630

2731
//////////////////////////////////////////////////////////////////////////////////////////
2832
// __type_info, __mtypeid, and __mtypeof
@@ -36,12 +40,14 @@ namespace STDEXEC
3640
constexpr __type_info(__type_info &&) = delete;
3741
constexpr __type_info &operator=(__type_info &&) = delete;
3842

39-
constexpr explicit __type_info(std::string_view __name) noexcept
43+
constexpr explicit __type_info(std::string_view __name,
44+
std::type_info const *__type = nullptr) noexcept
4045
: __name_(__name)
46+
, __type_(__type)
4147
{}
4248

4349
[[nodiscard]]
44-
constexpr std::string_view name() const noexcept
50+
constexpr auto name() const noexcept -> std::string_view
4551
{
4652
return __name_;
4753
}
@@ -52,17 +58,38 @@ namespace STDEXEC
5258
return this == &__other || __name_ == __other.__name_;
5359
}
5460

55-
constexpr auto
56-
operator<=>(__type_info const &) const noexcept -> std::strong_ordering = default;
61+
constexpr auto operator<=>(__type_info const &__other) const noexcept -> std::strong_ordering
62+
{
63+
return __name_ <=> __other.__name_;
64+
}
65+
66+
#if !STDEXEC_NO_STDCPP_TYPEID()
67+
[[nodiscard]]
68+
constexpr auto type() const noexcept -> std::type_info const &
69+
{
70+
return *__type_;
71+
}
72+
73+
[[nodiscard]]
74+
constexpr operator std::type_info const &() const noexcept
75+
{
76+
return *__type_;
77+
}
78+
#endif
5779

5880
private:
59-
std::string_view __name_;
81+
std::string_view const __name_;
82+
std::type_info const *const __type_ = nullptr; // used only if !STDEXEC_NO_STDCPP_TYPEID()
83+
void const *const __reserved_ = nullptr; // reserved for future use
6084
};
6185

6286
namespace __detail
6387
{
6488
template <class _Ty>
65-
inline constexpr __type_info __mtypeid_v{__mnameof<_Ty>};
89+
inline constexpr __type_info __mtypeid_v{
90+
__mnameof<_Ty> //
91+
STDEXEC_PP_WHEN(STDEXEC_PP_NOT(STDEXEC_NO_STDCPP_TYPEID()), , &typeid(_Ty)) //
92+
};
6693

6794
template <class _Ty>
6895
inline constexpr __type_info const &__mtypeid_v<_Ty const> = __mtypeid_v<_Ty>;
@@ -94,6 +121,20 @@ namespace STDEXEC
94121
return *__info_ <=> *other.__info_;
95122
}
96123

124+
#if !STDEXEC_NO_STDCPP_TYPEID()
125+
[[nodiscard]]
126+
constexpr auto type() const noexcept -> std::type_info const &
127+
{
128+
return (*__info_).type();
129+
}
130+
131+
[[nodiscard]]
132+
constexpr operator std::type_info const &() const noexcept
133+
{
134+
return (*__info_).type();
135+
}
136+
#endif
137+
97138
__type_info const *__info_;
98139
};
99140

@@ -139,3 +180,5 @@ namespace STDEXEC
139180
// Sanity check:
140181
static_assert(STDEXEC_IS_SAME(void, __mtypeof<__mtypeid<void>>));
141182
} // namespace STDEXEC
183+
184+
STDEXEC_PRAGMA_POP()

include/stdexec/__detail/__utility.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ namespace STDEXEC
312312
static_assert(std::derived_from<__value_type, _CvInterface>,
313313
"__polymorphic_downcast requires From to be a base class of To");
314314

315-
#if defined(__cpp_rtti) && __cpp_rtti >= 1997'11L
315+
#if !STDEXEC_NO_STDCPP_RTTI()
316316
STDEXEC_IF_NOT_CONSTEVAL
317317
{
318318
STDEXEC_ASSERT(dynamic_cast<__value_type*>(__from_ptr) != nullptr);

0 commit comments

Comments
 (0)