General Purpose library for Freestanding C++ and POSIX systems
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

76 satır
2.0 KiB

  1. #pragma once
  2. #include "gp/algorithm/tmp_manip.hpp"
  3. #include "gp/range.hpp"
  4. namespace gp{
  5. template<typename T>
  6. typename gp::remove_reference<T>::type&& move(T&& value)
  7. {
  8. return (typename gp::remove_reference<T>::type&&)value;
  9. }
  10. template<typename T>
  11. constexpr T&& forward(typename gp::remove_reference<T>::type& t) noexcept
  12. {
  13. return static_cast<T&&>(t);
  14. }
  15. template<typename T>
  16. constexpr T&& forward(typename gp::remove_reference<T>::type&& t) noexcept
  17. {
  18. static_assert(!std::is_lvalue_reference_v<T>,"bad forward of rvalue as lvalue");
  19. return static_cast<T&&>(t);
  20. }
  21. template<typename T>
  22. constexpr void swap(
  23. T& lhs,
  24. T& rhs
  25. )
  26. {
  27. auto tmp = lhs;
  28. lhs = rhs;
  29. rhs = tmp;
  30. }
  31. template<typename T>
  32. constexpr void swap(
  33. T&& lhs,
  34. T&& rhs
  35. )
  36. {
  37. auto tmp = lhs;
  38. lhs = rhs;
  39. rhs = tmp;
  40. }
  41. template<typename range_in, typename range_out>
  42. nameless_range<typename range_out::associated_iterator> move(range_in src, range_out dest)
  43. {
  44. if(src.size()>dest.size())
  45. return nameless_range<typename range_out::associated_iterator>(dest.begin(), dest.end());
  46. auto in = src.begin();
  47. auto in_close = src.end();
  48. auto out = dest.begin();
  49. while(in != in_close)
  50. {
  51. *(out++) = gp::move(*(in++));
  52. }
  53. return nameless_range<typename range_out::associated_iterator>{out, dest.end()};
  54. }
  55. template<typename range_in, typename range_out>
  56. nameless_range<typename gp::remove_reference<range_out>::type::associated_iterator> move_uninitialized(range_in&& src, range_out&& dest)
  57. {
  58. using T = typename gp::remove_reference<decltype(*dest.begin())>::type;
  59. if(src.size()>dest.size())
  60. return nameless_range<typename gp::remove_reference<range_out>::type::associated_iterator>(dest.begin(), dest.end());
  61. auto in = src.begin();
  62. auto in_close = src.end();
  63. auto out = dest.begin();
  64. while(in != in_close)
  65. {
  66. new(&*(out++)) T{gp::move(*(in++))};
  67. }
  68. return nameless_range<typename gp::remove_reference<range_out>::type::associated_iterator>{out, dest.end()};
  69. }
  70. }