tuple.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // sol2
  2. // The MIT License (MIT)
  3. // Copyright (c) 2013-2022 Rapptz, ThePhD and contributors
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. // this software and associated documentation files (the "Software"), to deal in
  6. // the Software without restriction, including without limitation the rights to
  7. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. // the Software, and to permit persons to whom the Software is furnished to do so,
  9. // subject to the following conditions:
  10. // The above copyright notice and this permission notice shall be included in all
  11. // copies or substantial portions of the Software.
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. #ifndef SOL_TUPLE_HPP
  19. #define SOL_TUPLE_HPP
  20. #include <sol/forward.hpp>
  21. #include <sol/base_traits.hpp>
  22. #include <tuple>
  23. #include <cstddef>
  24. namespace sol {
  25. namespace detail {
  26. using swallow = std::initializer_list<int>;
  27. } // namespace detail
  28. namespace meta {
  29. template <typename T>
  30. using is_tuple = is_specialization_of<T, std::tuple>;
  31. template <typename T>
  32. constexpr inline bool is_tuple_v = is_tuple<T>::value;
  33. namespace detail {
  34. template <typename... Args>
  35. struct tuple_types_ {
  36. typedef types<Args...> type;
  37. };
  38. template <typename... Args>
  39. struct tuple_types_<std::tuple<Args...>> {
  40. typedef types<Args...> type;
  41. };
  42. } // namespace detail
  43. template <typename... Args>
  44. using tuple_types = typename detail::tuple_types_<Args...>::type;
  45. template <typename Arg>
  46. struct pop_front_type;
  47. template <typename Arg>
  48. using pop_front_type_t = typename pop_front_type<Arg>::type;
  49. template <typename... Args>
  50. struct pop_front_type<types<Args...>> {
  51. typedef void front_type;
  52. typedef types<Args...> type;
  53. };
  54. template <typename Arg, typename... Args>
  55. struct pop_front_type<types<Arg, Args...>> {
  56. typedef Arg front_type;
  57. typedef types<Args...> type;
  58. };
  59. template <std::size_t N, typename Tuple>
  60. using tuple_element = std::tuple_element<N, std::remove_reference_t<Tuple>>;
  61. template <std::size_t N, typename Tuple>
  62. using tuple_element_t = std::tuple_element_t<N, std::remove_reference_t<Tuple>>;
  63. template <std::size_t N, typename Tuple>
  64. using unqualified_tuple_element = unqualified<tuple_element_t<N, Tuple>>;
  65. template <std::size_t N, typename Tuple>
  66. using unqualified_tuple_element_t = unqualified_t<tuple_element_t<N, Tuple>>;
  67. } // namespace meta
  68. } // namespace sol
  69. #endif // SOL_TUPLE_HPP