Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picanumber/a6f09f713934f3a28fe1ff36e9170c07 to your computer and use it in GitHub Desktop.
Save picanumber/a6f09f713934f3a28fe1ff36e9170c07 to your computer and use it in GitHub Desktop.
How to provide custom structured bindings for the sorted view class
namespace std
{
// 1. provide tuple_element<I, sorted_view<...>>::type
template <std::size_t I, class... Types>
struct tuple_element<I, utl::sorted_view<Types...>>
{
using sorted_view_t = utl::sorted_view<Types...>;
using type = typename sorted_view_t::template tuple_element_t<I>;
};
// 2. provide tuple_size<sorted_view<...>>
template <class... Types>
struct tuple_size<utl::sorted_view<Types...>>
: public integral_constant<size_t, sizeof...(Types)>
{
};
}
namespace utl
{
// 3. provide a get<I>(sorted_view<...>) function
template <std::size_t I, class... Types>
auto get(sorted_view<Types...> const& sv)
{
return sv.template elem<I>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment