accessors.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. @file
  3. Defines `boost::hana::accessors`.
  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_ACCESSORS_HPP
  9. #define BOOST_HANA_ACCESSORS_HPP
  10. #include <boost/hana/fwd/accessors.hpp>
  11. #include <boost/hana/concept/struct.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/dispatch.hpp>
  14. BOOST_HANA_NAMESPACE_BEGIN
  15. template <typename S>
  16. struct accessors_t {
  17. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  18. static_assert(hana::Struct<S>::value,
  19. "hana::accessors<S> requires 'S' to be a Struct");
  20. #endif
  21. constexpr decltype(auto) operator()() const {
  22. using Accessors = BOOST_HANA_DISPATCH_IF(accessors_impl<S>,
  23. hana::Struct<S>::value
  24. );
  25. return Accessors::apply();
  26. }
  27. };
  28. template <typename S, bool condition>
  29. struct accessors_impl<S, when<condition>> : default_ {
  30. template <typename ...Args>
  31. static constexpr auto apply(Args&& ...) = delete;
  32. };
  33. namespace struct_detail {
  34. template <typename ...>
  35. struct is_valid { static constexpr bool value = true; };
  36. }
  37. template <typename S>
  38. struct accessors_impl<S, when<
  39. struct_detail::is_valid<typename S::hana_accessors_impl>::value
  40. >>
  41. : S::hana_accessors_impl
  42. { };
  43. BOOST_HANA_NAMESPACE_END
  44. #endif // !BOOST_HANA_ACCESSORS_HPP