symmetric_difference.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*!
  2. @file
  3. Defines `boost::hana::symmetric_difference`.
  4. Copyright Louis Dionne 2013-2022
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_SYMMETRIC_DIFFERENCE_HPP
  9. #define BOOST_HANA_SYMMETRIC_DIFFERENCE_HPP
  10. #include <boost/hana/fwd/symmetric_difference.hpp>
  11. #include <boost/hana/config.hpp>
  12. #include <boost/hana/core/dispatch.hpp>
  13. #include <boost/hana/difference.hpp>
  14. #include <boost/hana/union.hpp>
  15. namespace boost { namespace hana {
  16. //! @cond
  17. template <typename Xs, typename Ys>
  18. constexpr auto symmetric_difference_t::operator()(Xs&& xs, Ys&& ys) const {
  19. using S = typename hana::tag_of<Xs>::type;
  20. using SymmetricDifference = BOOST_HANA_DISPATCH_IF(symmetric_difference_impl<S>,
  21. true
  22. );
  23. return SymmetricDifference::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
  24. }
  25. //! @endcond
  26. template <typename S, bool condition>
  27. struct symmetric_difference_impl<S, when<condition>> : default_ {
  28. template <typename Xs, typename Ys>
  29. static constexpr auto apply(Xs&& xs, Ys&& ys) {
  30. return hana::union_(
  31. hana::difference(xs, ys),
  32. hana::difference(ys, xs)
  33. );
  34. }
  35. };
  36. }} // end namespace boost::hana
  37. #endif // !BOOST_HANA_SYMMETRIC_DIFFERENCE_HPP