permutations.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*!
  2. @file
  3. Forward declares `boost::hana::permutations`.
  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_FWD_PERMUTATIONS_HPP
  9. #define BOOST_HANA_FWD_PERMUTATIONS_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. namespace boost { namespace hana {
  13. //! Return a sequence of all the permutations of the given sequence.
  14. //! @ingroup group-Sequence
  15. //!
  16. //! Specifically, `permutations(xs)` is a sequence whose elements are
  17. //! permutations of the original sequence `xs`. The permutations are not
  18. //! guaranteed to be in any specific order. Also note that the number
  19. //! of permutations grows very rapidly as the length of the original
  20. //! sequence increases. The growth rate is `O(length(xs)!)`; with a
  21. //! sequence `xs` of length only 8, `permutations(xs)` contains over
  22. //! 40 000 elements!
  23. //!
  24. //!
  25. //! Example
  26. //! -------
  27. //! @include example/permutations.cpp
  28. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  29. constexpr auto permutations = [](auto&& xs) {
  30. return tag-dispatched;
  31. };
  32. #else
  33. template <typename S, typename = void>
  34. struct permutations_impl : permutations_impl<S, when<true>> { };
  35. struct permutations_t {
  36. template <typename Xs>
  37. constexpr auto operator()(Xs&& xs) const;
  38. };
  39. BOOST_HANA_INLINE_VARIABLE constexpr permutations_t permutations{};
  40. #endif
  41. }} // end namespace boost::hana
  42. #endif // !BOOST_HANA_FWD_PERMUTATIONS_HPP