Advertisement
Radfler

::equals

Apr 8th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <type_traits>
  2. #include <utility>
  3.  
  4. namespace equals_details {
  5.  
  6.     template<typename... Args>
  7.     constexpr bool equals(Args&&...);
  8.  
  9.     template<typename T, typename U>
  10.     constexpr bool equals(T&& lhs, U&& rhs) noexcept(noexcept(std::forward<T>(lhs) == std::forward<U>(rhs))) {
  11.         return std::forward<T>(lhs) == std::forward<U>(rhs);
  12.     }
  13.  
  14.     template<typename T, typename U, typename... Args>
  15.     constexpr bool equals(T&& lhs, U&& rhs, Args&&... args)
  16.  
  17.         noexcept(noexcept(std::forward<T>(lhs) == std::forward<U>(rhs)) &&
  18.                  noexcept(equals(std::forward<U>(rhs), std::forward<Args>(args)...))) {
  19.  
  20.         return std::forward<T>(lhs) == std::forward<U>(rhs) &&
  21.             equals(std::forward<T>(lhs), std::forward<Args>(args)...);
  22.  
  23.     }
  24.  
  25. }
  26.  
  27. // some information:
  28. // doesn't participate in overload resolution if (sizeof...(Args) < 2)
  29. // return: (a1 == a2 && a2 == a3 && ... && a(n - 1) == a(n)), where n = sizeof...(Args)
  30. // exceptions: noexcept(false) if any comparasion yields noexcept(false)
  31.  
  32. template<typename... Args>
  33. constexpr auto equals(Args&&... args) -> std::enable_if_t<sizeof...(Args) >= 2, bool> {
  34.  
  35.     return equals_details::equals(std::forward<Args>(args)...);
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement