Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <type_traits>
- #include <utility>
- namespace equals_details {
- template<typename... Args>
- constexpr bool equals(Args&&...);
- template<typename T, typename U>
- constexpr bool equals(T&& lhs, U&& rhs) noexcept(noexcept(std::forward<T>(lhs) == std::forward<U>(rhs))) {
- return std::forward<T>(lhs) == std::forward<U>(rhs);
- }
- template<typename T, typename U, typename... Args>
- constexpr bool equals(T&& lhs, U&& rhs, Args&&... args)
- noexcept(noexcept(std::forward<T>(lhs) == std::forward<U>(rhs)) &&
- noexcept(equals(std::forward<U>(rhs), std::forward<Args>(args)...))) {
- return std::forward<T>(lhs) == std::forward<U>(rhs) &&
- equals(std::forward<T>(lhs), std::forward<Args>(args)...);
- }
- }
- // some information:
- // doesn't participate in overload resolution if (sizeof...(Args) < 2)
- // return: (a1 == a2 && a2 == a3 && ... && a(n - 1) == a(n)), where n = sizeof...(Args)
- // exceptions: noexcept(false) if any comparasion yields noexcept(false)
- template<typename... Args>
- constexpr auto equals(Args&&... args) -> std::enable_if_t<sizeof...(Args) >= 2, bool> {
- return equals_details::equals(std::forward<Args>(args)...);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement