front.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. @file
  3. Defines `boost::hana::front`.
  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_FRONT_HPP
  9. #define BOOST_HANA_FRONT_HPP
  10. #include <boost/hana/fwd/front.hpp>
  11. #include <boost/hana/at.hpp>
  12. #include <boost/hana/concept/iterable.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. BOOST_HANA_NAMESPACE_BEGIN
  16. //! @cond
  17. template <typename Xs>
  18. constexpr decltype(auto) front_t::operator()(Xs&& xs) const {
  19. using It = typename hana::tag_of<Xs>::type;
  20. using Front = BOOST_HANA_DISPATCH_IF(front_impl<It>,
  21. hana::Iterable<It>::value
  22. );
  23. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  24. static_assert(hana::Iterable<It>::value,
  25. "hana::front(xs) requires 'xs' to be an Iterable");
  26. #endif
  27. return Front::apply(static_cast<Xs&&>(xs));
  28. }
  29. //! @endcond
  30. template <typename It, bool condition>
  31. struct front_impl<It, when<condition>> : default_ {
  32. template <typename Xs>
  33. static constexpr decltype(auto) apply(Xs&& xs)
  34. { return hana::at_c<0>(static_cast<Xs&&>(xs)); }
  35. };
  36. BOOST_HANA_NAMESPACE_END
  37. #endif // !BOOST_HANA_FRONT_HPP