tuple.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // (C) Copyright John Maddock 2010.
  2. // (C) Copyright Matt Borland 2024.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_MATH_TUPLE_HPP_INCLUDED
  7. #define BOOST_MATH_TUPLE_HPP_INCLUDED
  8. #include <boost/math/tools/config.hpp>
  9. #ifdef BOOST_MATH_ENABLE_CUDA
  10. #include <boost/math/tools/type_traits.hpp>
  11. #include <cuda/std/utility>
  12. #include <cuda/std/tuple>
  13. namespace boost {
  14. namespace math {
  15. using cuda::std::pair;
  16. using cuda::std::tuple;
  17. using cuda::std::make_pair;
  18. using cuda::std::tie;
  19. using cuda::std::get;
  20. using cuda::std::tuple_size;
  21. using cuda::std::tuple_element;
  22. namespace detail {
  23. template <typename T>
  24. BOOST_MATH_GPU_ENABLED T&& forward(boost::math::remove_reference_t<T>& arg) noexcept
  25. {
  26. return static_cast<T&&>(arg);
  27. }
  28. template <typename T>
  29. BOOST_MATH_GPU_ENABLED T&& forward(boost::math::remove_reference_t<T>&& arg) noexcept
  30. {
  31. static_assert(!boost::math::is_lvalue_reference<T>::value, "Cannot forward an rvalue as an lvalue.");
  32. return static_cast<T&&>(arg);
  33. }
  34. } // namespace detail
  35. template <typename T, typename... Ts>
  36. BOOST_MATH_GPU_ENABLED auto make_tuple(T&& t, Ts&&... ts)
  37. {
  38. return cuda::std::tuple<boost::math::decay_t<T>, boost::math::decay_t<Ts>...>(
  39. boost::math::detail::forward<T>(t), boost::math::detail::forward<Ts>(ts)...
  40. );
  41. }
  42. } // namespace math
  43. } // namespace boost
  44. #else
  45. #include <tuple>
  46. namespace boost {
  47. namespace math {
  48. using ::std::tuple;
  49. using ::std::pair;
  50. // [6.1.3.2] Tuple creation functions
  51. using ::std::ignore;
  52. using ::std::make_tuple;
  53. using ::std::tie;
  54. using ::std::get;
  55. // [6.1.3.3] Tuple helper classes
  56. using ::std::tuple_size;
  57. using ::std::tuple_element;
  58. // Pair helpers
  59. using ::std::make_pair;
  60. } // namespace math
  61. } // namespace boost
  62. #endif // BOOST_MATH_ENABLE_CUDA
  63. #endif