at.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. @file
  3. Defines `boost::hana::at` and `boost::hana::at_c`.
  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_AT_HPP
  9. #define BOOST_HANA_AT_HPP
  10. #include <boost/hana/fwd/at.hpp>
  11. #include <boost/hana/concept/integral_constant.hpp>
  12. #include <boost/hana/concept/iterable.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/integral_constant.hpp>
  16. #include <cstddef>
  17. BOOST_HANA_NAMESPACE_BEGIN
  18. //! @cond
  19. template <typename Xs, typename N>
  20. constexpr decltype(auto) at_t::operator()(Xs&& xs, N const& n) const {
  21. using It = typename hana::tag_of<Xs>::type;
  22. using At = BOOST_HANA_DISPATCH_IF(at_impl<It>,
  23. hana::Iterable<It>::value
  24. );
  25. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  26. static_assert(hana::Iterable<It>::value,
  27. "hana::at(xs, n) requires 'xs' to be an Iterable");
  28. static_assert(hana::IntegralConstant<N>::value,
  29. "hana::at(xs, n) requires 'n' to be an IntegralConstant");
  30. #endif
  31. return At::apply(static_cast<Xs&&>(xs), n);
  32. }
  33. //! @endcond
  34. template <typename It, bool condition>
  35. struct at_impl<It, when<condition>> : default_ {
  36. template <typename ...Args>
  37. static constexpr auto apply(Args&& ...) = delete;
  38. };
  39. template <std::size_t n, typename Xs>
  40. constexpr decltype(auto) at_c(Xs&& xs) {
  41. return hana::at(static_cast<Xs&&>(xs), hana::size_t<n>{});
  42. }
  43. BOOST_HANA_NAMESPACE_END
  44. #endif // !BOOST_HANA_AT_HPP