Skip to content

Commit

Permalink
Add pair support for haskell
Browse files Browse the repository at this point in the history
Summary: added `Convert` specializations between `std::pair` and `HsTuple`

Reviewed By: ahilger

Differential Revision: D66491864

fbshipit-source-id: 880632f259ad012552a3b99431fe733c15f1c8fb
  • Loading branch information
Dan Deng authored and facebook-github-bot committed Nov 27, 2024
1 parent 25e05aa commit 253f688
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions common/util/cpp/HsStdTuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ HS_STRUCT HsStdTuple {
return std::move(data_.tup);
}

template <
typename T = HsStdTuple<Ts...>,
typename = std::enable_if_t<std::tuple_size_v<T> == 2>>
auto toStdPair()&& {
return std::make_pair(
std::move(std::get<0>(data_.tup)), std::move(std::get<1>(data_.tup)));
}

static constexpr auto tuple_size = std::tuple_size_v<std::tuple<Ts...>>;

private:
Expand All @@ -176,3 +184,12 @@ HS_STRUCT HsStdTuple {
}
}
};

namespace std {

template <typename... Ts>
struct tuple_size<HsStdTuple<Ts...>> {
static constexpr size_t value = sizeof...(Ts);
};

} // namespace std

0 comments on commit 253f688

Please sign in to comment.