Skip to content

Commit 66f25a0

Browse files
authored
Merge pull request intel#139 from elbeno/unambiguous-tuple
🐛 Fix possible ambiguity in tuple indexing
2 parents 5e3a178 + 3be1ad9 commit 66f25a0

File tree

2 files changed

+9
-54
lines changed

2 files changed

+9
-54
lines changed

include/stdx/tuple.hpp

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ template <auto I, typename... Ts> constexpr auto index_out_of_bounds() {
5353
} // namespace error
5454

5555
namespace detail {
56-
template <std::size_t, typename...> struct element;
57-
58-
template <typename T>
59-
concept derivable = std::is_class_v<T>;
60-
template <typename T>
61-
concept nonderivable = not std::is_class_v<T>;
62-
63-
template <std::size_t Index, nonderivable T, typename... Ts>
64-
struct element<Index, T, Ts...> {
56+
template <std::size_t Index, typename T, typename... Ts> struct element {
6557
#if __has_builtin(__type_pack_element)
6658
using type = T;
6759
#else
@@ -117,51 +109,6 @@ struct element<Index, T, Ts...> {
117109
element const &) = default;
118110
};
119111

120-
template <std::size_t Index, derivable T, typename... Ts>
121-
struct element<Index, T, Ts...> : T {
122-
#if __has_builtin(__type_pack_element)
123-
using type = T;
124-
#else
125-
constexpr static auto ugly_Value(index_constant<Index>) -> T;
126-
127-
[[nodiscard]] constexpr auto
128-
ugly_iGet_clvr(index_constant<Index>) const & noexcept -> T const & {
129-
return *this;
130-
}
131-
[[nodiscard]] constexpr auto
132-
ugly_iGet_lvr(index_constant<Index>) & noexcept -> T & {
133-
return *this;
134-
}
135-
[[nodiscard]] constexpr auto
136-
ugly_iGet_rvr(index_constant<Index>) && noexcept -> T && {
137-
return std::move(*this);
138-
}
139-
#endif
140-
141-
template <typename U>
142-
requires(std::is_same_v<U, T> or ... or std::is_same_v<U, Ts>)
143-
[[nodiscard]] constexpr auto
144-
ugly_tGet_clvr(tag_constant<U> *) const & noexcept -> T const & {
145-
return *this;
146-
}
147-
template <typename U>
148-
requires(std::is_same_v<U, T> or ... or std::is_same_v<U, Ts>)
149-
[[nodiscard]] constexpr auto
150-
ugly_tGet_lvr(tag_constant<U> *) & noexcept -> T & {
151-
return *this;
152-
}
153-
template <typename U>
154-
requires(std::is_same_v<U, T> or ... or std::is_same_v<U, Ts>)
155-
[[nodiscard]] constexpr auto
156-
ugly_tGet_rvr(tag_constant<U> *) && noexcept -> T && {
157-
return std::move(*this);
158-
}
159-
160-
constexpr auto ugly_Value_clvr() const & -> T const & { return *this; }
161-
constexpr auto ugly_Value_lvr() & -> T & { return *this; }
162-
constexpr auto ugly_Value_rvr() && -> T && { return std::move(*this); }
163-
};
164-
165112
template <typename Op, typename Value> struct fold_helper {
166113
Op op;
167114
Value value;

test/tuple.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,11 @@ TEST_CASE("one_of", "[tuple]") {
442442
static_assert(stdx::one_of{1, 2, 3} == stdx::one_of{3, 4, 5});
443443
static_assert(stdx::one_of{1, 2, 3} != stdx::one_of{4, 5, 6});
444444
}
445+
446+
TEST_CASE("indexing unambiguously", "[tuple]") {
447+
using namespace stdx::literals;
448+
449+
constexpr auto t = stdx::tuple{42, stdx::tuple{17}};
450+
static_assert(t[0_idx] == 42);
451+
static_assert(t[1_idx][0_idx] == 17);
452+
}

0 commit comments

Comments
 (0)