iterable.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*!
  2. @file
  3. Defines operators for Iterables.
  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_OPERATORS_ITERABLE_HPP
  9. #define BOOST_HANA_DETAIL_OPERATORS_ITERABLE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/fwd/at.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  13. template <typename Derived>
  14. struct iterable_operators {
  15. template <typename N>
  16. constexpr decltype(auto) operator[](N&& n) & {
  17. return hana::at(static_cast<Derived&>(*this),
  18. static_cast<N&&>(n));
  19. }
  20. template <typename N>
  21. constexpr decltype(auto) operator[](N&& n) const& {
  22. return hana::at(static_cast<Derived const&>(*this),
  23. static_cast<N&&>(n));
  24. }
  25. template <typename N>
  26. constexpr decltype(auto) operator[](N&& n) && {
  27. return hana::at(static_cast<Derived&&>(*this),
  28. static_cast<N&&>(n));
  29. }
  30. };
  31. } BOOST_HANA_NAMESPACE_END
  32. #endif // !BOOST_HANA_DETAIL_OPERATORS_ITERABLE_HPP