Last active
January 12, 2017 10:56
-
-
Save picanumber/a6f09f713934f3a28fe1ff36e9170c07 to your computer and use it in GitHub Desktop.
How to provide custom structured bindings for the sorted view class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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