keys.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. @file
  3. Defines `boost::hana::keys`.
  4. Copyright Louis Dionne 2013-2022
  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_KEYS_HPP
  9. #define BOOST_HANA_KEYS_HPP
  10. #include <boost/hana/fwd/keys.hpp>
  11. #include <boost/hana/accessors.hpp>
  12. #include <boost/hana/concept/struct.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/first.hpp>
  16. #include <boost/hana/transform.hpp>
  17. namespace boost { namespace hana {
  18. //! @cond
  19. template <typename Map>
  20. constexpr auto keys_t::operator()(Map&& map) const {
  21. return keys_impl<typename hana::tag_of<Map>::type>::apply(
  22. static_cast<Map&&>(map)
  23. );
  24. }
  25. //! @endcond
  26. template <typename T, bool condition>
  27. struct keys_impl<T, when<condition>> : default_ {
  28. template <typename ...Args>
  29. static constexpr auto apply(Args&& ...) = delete;
  30. };
  31. template <typename S>
  32. struct keys_impl<S, when<hana::Struct<S>::value>> {
  33. template <typename Object>
  34. static constexpr auto apply(Object const&) {
  35. return hana::transform(hana::accessors<S>(), hana::first);
  36. }
  37. };
  38. }} // end namespace boost::hana
  39. #endif // !BOOST_HANA_KEYS_HPP