functional.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include <utility>
  5. #include "opentelemetry/version.h"
  6. #define OPENTELEMETRY_RETURN(...) \
  7. noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) \
  8. { \
  9. return __VA_ARGS__; \
  10. }
  11. OPENTELEMETRY_BEGIN_NAMESPACE
  12. namespace nostd
  13. {
  14. namespace detail
  15. {
  16. struct equal_to
  17. {
  18. template <typename Lhs, typename Rhs>
  19. inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
  20. OPENTELEMETRY_RETURN(std::forward<Lhs>(lhs) == std::forward<Rhs>(rhs))
  21. };
  22. struct not_equal_to
  23. {
  24. template <typename Lhs, typename Rhs>
  25. inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
  26. OPENTELEMETRY_RETURN(std::forward<Lhs>(lhs) != std::forward<Rhs>(rhs))
  27. };
  28. struct less
  29. {
  30. template <typename Lhs, typename Rhs>
  31. inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
  32. OPENTELEMETRY_RETURN(std::forward<Lhs>(lhs) < std::forward<Rhs>(rhs))
  33. };
  34. struct greater
  35. {
  36. template <typename Lhs, typename Rhs>
  37. inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
  38. OPENTELEMETRY_RETURN(std::forward<Lhs>(lhs) > std::forward<Rhs>(rhs))
  39. };
  40. struct less_equal
  41. {
  42. template <typename Lhs, typename Rhs>
  43. inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
  44. OPENTELEMETRY_RETURN(std::forward<Lhs>(lhs) <= std::forward<Rhs>(rhs))
  45. };
  46. struct greater_equal
  47. {
  48. template <typename Lhs, typename Rhs>
  49. inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
  50. OPENTELEMETRY_RETURN(std::forward<Lhs>(lhs) >= std::forward<Rhs>(rhs))
  51. };
  52. } // namespace detail
  53. } // namespace nostd
  54. OPENTELEMETRY_END_NAMESPACE
  55. #undef OPENTELEMETRY_RETURN