forked from OctaForge/libostd
implement piecewise construction for Pair/CompressedPair
This commit is contained in:
parent
7f2e5f67d4
commit
211961cc31
|
@ -634,6 +634,59 @@ inline bool operator>=(Tuple<T...> const &x, Tuple<U...> const &y) {
|
||||||
template<typename ...T, typename A>
|
template<typename ...T, typename A>
|
||||||
constexpr bool UsesAllocator<Tuple<T...>, A> = true;
|
constexpr bool UsesAllocator<Tuple<T...>, A> = true;
|
||||||
|
|
||||||
|
/* piecewise pair stuff */
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
Pair<T, U>::Pair(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
):
|
||||||
|
first(forward<A1>(get<I1>(fa))...), second(forward<A2>(get<I2>(sa))...)
|
||||||
|
{}
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
template<typename T, typename U>
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase<T, U, 0>::CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
):
|
||||||
|
p_first(forward<A1>(get<I1>(fa))...),
|
||||||
|
p_second(forward<A2>(get<I2>(sa))...)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase<T, U, 1>::CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
):
|
||||||
|
T(forward<A1>(get<I1>(fa))...),
|
||||||
|
p_second(forward<A2>(get<I2>(sa))...)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase<T, U, 2>::CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
):
|
||||||
|
U(forward<A2>(get<I2>(sa))...),
|
||||||
|
p_first(forward<A1>(get<I1>(fa))...)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase<T, U, 3>::CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
):
|
||||||
|
T(forward<A1>(get<I1>(fa))...),
|
||||||
|
U(forward<A2>(get<I2>(sa))...)
|
||||||
|
{}
|
||||||
|
} /* namespace detail */
|
||||||
|
|
||||||
} /* namespace ostd */
|
} /* namespace ostd */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -94,6 +94,9 @@ namespace detail {
|
||||||
|
|
||||||
/* pair */
|
/* pair */
|
||||||
|
|
||||||
|
struct PiecewiseConstruct {};
|
||||||
|
constexpr PiecewiseConstruct piecewise_construct = {};
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
struct Pair {
|
struct Pair {
|
||||||
T first;
|
T first;
|
||||||
|
@ -120,6 +123,15 @@ struct Pair {
|
||||||
first(move(v.first)), second(move(v.second))
|
first(move(v.first)), second(move(v.second))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template<typename ...A1, typename ...A2>
|
||||||
|
Pair(PiecewiseConstruct pc, Tuple<A1...> fa, Tuple<A2...> sa):
|
||||||
|
Pair(
|
||||||
|
pc, fa, sa,
|
||||||
|
detail::MakeTupleIndices<sizeof...(A1)>(),
|
||||||
|
detail::MakeTupleIndices<sizeof...(A2)>()
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
Pair &operator=(Pair const &v) {
|
Pair &operator=(Pair const &v) {
|
||||||
first = v.first;
|
first = v.first;
|
||||||
second = v.second;
|
second = v.second;
|
||||||
|
@ -150,6 +162,13 @@ struct Pair {
|
||||||
detail::swap_adl(first, v.first);
|
detail::swap_adl(first, v.first);
|
||||||
detail::swap_adl(second, v.second);
|
detail::swap_adl(second, v.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
Pair(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -324,6 +343,12 @@ namespace detail {
|
||||||
p_first(forward<TT>(a)), p_second(forward<UU>(b))
|
p_first(forward<TT>(a)), p_second(forward<UU>(b))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
);
|
||||||
|
|
||||||
T &first() { return p_first; }
|
T &first() { return p_first; }
|
||||||
T const &first() const { return p_first; }
|
T const &first() const { return p_first; }
|
||||||
|
|
||||||
|
@ -345,6 +370,12 @@ namespace detail {
|
||||||
T(forward<TT>(a)), p_second(forward<UU>(b))
|
T(forward<TT>(a)), p_second(forward<UU>(b))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
);
|
||||||
|
|
||||||
T &first() { return *this; }
|
T &first() { return *this; }
|
||||||
T const &first() const { return *this; }
|
T const &first() const { return *this; }
|
||||||
|
|
||||||
|
@ -365,6 +396,12 @@ namespace detail {
|
||||||
U(forward<UU>(b)), p_first(forward<TT>(a))
|
U(forward<UU>(b)), p_first(forward<TT>(a))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
);
|
||||||
|
|
||||||
T &first() { return p_first; }
|
T &first() { return p_first; }
|
||||||
T const &first() const { return p_first; }
|
T const &first() const { return p_first; }
|
||||||
|
|
||||||
|
@ -383,6 +420,12 @@ namespace detail {
|
||||||
T(forward<TT>(a)), U(forward<UU>(b))
|
T(forward<TT>(a)), U(forward<UU>(b))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||||
|
CompressedPairBase(
|
||||||
|
PiecewiseConstruct, Tuple<A1...> &fa, Tuple<A2...> &sa,
|
||||||
|
detail::TupleIndices<I1...>, detail::TupleIndices<I2...>
|
||||||
|
);
|
||||||
|
|
||||||
T &first() { return *this; }
|
T &first() { return *this; }
|
||||||
T const &first() const { return *this; }
|
T const &first() const { return *this; }
|
||||||
|
|
||||||
|
@ -401,6 +444,15 @@ namespace detail {
|
||||||
Base(forward<TT>(a), forward<UU>(b))
|
Base(forward<TT>(a), forward<UU>(b))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template<typename ...A1, typename ...A2>
|
||||||
|
CompressedPair(PiecewiseConstruct pc, Tuple<A1...> fa, Tuple<A2...> sa):
|
||||||
|
Base(
|
||||||
|
pc, fa, sa,
|
||||||
|
detail::MakeTupleIndices<sizeof...(A1)>(),
|
||||||
|
detail::MakeTupleIndices<sizeof...(A2)>()
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
T &first() { return Base::first(); }
|
T &first() { return Base::first(); }
|
||||||
T const &first() const { return Base::first(); }
|
T const &first() const { return Base::first(); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue