searchable.hpp 1.2 KB

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