|
This code seems to do the trick. It may be better to use decltype(auto) as the return type from get() to avoid making a copy when doing structured binding.
namespace std {
|
template <>
|
struct tuple_size<mongo::BSONElement> : std::integral_constant<size_t, 2> {};
|
template <size_t I>
|
struct tuple_element<I, mongo::BSONElement>
|
: std::tuple_element<I, std::pair<mongo::StringData, mongo::BSONElement>> {};
|
} // namespace std
|
|
namespace mongo {
|
template <size_t I>
|
auto get(const BSONElement& elem) {
|
static_assert(I <= 1);
|
if constexpr (I == 0) {
|
return elem.fieldNameStringData();
|
} else if constexpr (I == 1) {
|
return elem;
|
}
|
}
|
} // namespace mongo
|
|
|