drop_into.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. @file
  3. Defines `boost::hana::detail::variadic::drop_into`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_DETAIL_VARIADIC_DROP_INTO_HPP
  9. #define BOOST_HANA_DETAIL_VARIADIC_DROP_INTO_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <cstddef>
  12. #include <utility>
  13. BOOST_HANA_NAMESPACE_BEGIN namespace detail { namespace variadic {
  14. template <std::size_t n, typename F, typename = std::make_index_sequence<n>>
  15. struct dropper;
  16. template <std::size_t n, typename F, std::size_t ...ignore>
  17. struct dropper<n, F, std::index_sequence<ignore...>> {
  18. F f;
  19. template <typename ...Rest>
  20. constexpr auto go(decltype(ignore, (void*)0)..., Rest ...rest) const
  21. { return f(*rest...); }
  22. template <typename ...Xs>
  23. constexpr auto operator()(Xs ...xs) const
  24. { return go(&xs...); }
  25. };
  26. template <std::size_t n>
  27. struct make_dropper {
  28. template <typename F>
  29. constexpr auto operator()(F f) const
  30. { return dropper<n, decltype(f)>{f}; }
  31. };
  32. template <std::size_t n>
  33. constexpr make_dropper<n> drop_into{};
  34. }} BOOST_HANA_NAMESPACE_END
  35. #endif // !BOOST_HANA_DETAIL_VARIADIC_DROP_INTO_HPP