Skip to content

Commit b454890

Browse files
committed
Forward-declare tuple in utility.h and define it in tuple.h
This is to: 1. Fix compile error due to duplicate definition, and 2. Reflect how it is the real C++ standard library.
1 parent ad1ddf1 commit b454890

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
namespace std {
2-
template <class... Types> class tuple {};
2+
// Definition
3+
template <typename... T1> class tuple {};
4+
35
template <class... Types> std::tuple<Types...> make_tuple(Types &&...args);
46
struct ignore_t {
57
template <typename T>
68
constexpr // required since C++14
7-
void
8-
operator=(T &&) const noexcept {}
9+
void operator=(T &&) const noexcept {}
910
};
1011
inline const std::ignore_t ignore; // 'const' only until C++17
1112
} // namespace std

cpp/common/test/includes/standard-library/utility.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
99

1010
template <class T> void swap(T &a, T &b) noexcept;
1111

12-
template<class... Types>
13-
struct tuple {};
12+
// Forward declaration only - defined in <tuple>
13+
template <typename... T1> class tuple;
1414

1515
template <class T, class U> struct pair : tuple<T, U> {
16-
T first;
17-
U second;
18-
pair(T t, U u);
16+
T first;
17+
U second;
18+
pair(T t, U u);
1919
};
2020
template <class T, class U> std::pair<T, U> make_pair(T &&x, U &&y);
2121

22-
template<size_t N, class T, class U>
22+
template <size_t N, class T, class U>
2323
constexpr auto get(const std::pair<T, U> &p) noexcept {
24-
if constexpr (N == 0) {
25-
return p.first;
26-
} else if constexpr (N == 1) {
27-
return p.second;
28-
} else {
29-
static_assert(N < 2, "Index out of bounds for pair");
30-
}
24+
if constexpr (N == 0) {
25+
return p.first;
26+
} else if constexpr (N == 1) {
27+
return p.second;
28+
} else {
29+
static_assert(N < 2, "Index out of bounds for pair");
30+
}
3131
}
32-
} // namespace std
32+
} // namespace std

0 commit comments

Comments
 (0)