Guest User

Untitled

a guest
Oct 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <array>
  2. #include <algorithm>
  3. #include <sprout/algorithm/sort.hpp>
  4. template <class Container>
  5. constexpr auto compute_length(Container &&container)
  6. {
  7. auto itr1 = container.cbegin();
  8. auto itr2 = itr1 + 1;
  9. auto itr3 = itr2 + 1;
  10.  
  11. while(itr3 != container.cend())
  12. {
  13. if (*itr1 < *itr2 + *itr3)
  14. return *itr1 + *itr2 + *itr3;
  15. ++itr1;
  16. ++itr2;
  17. ++itr3;
  18. }
  19. return 0;
  20. }
  21.  
  22. int main()
  23. {
  24. constexpr std::array a = {2, 3, 4, 5, 10};
  25. // constexpr std::array a = {4, 5, 10, 20};
  26. constexpr auto b = sprout::sort(a, [](auto i, auto j){return i > j;});
  27. constexpr auto ans = compute_length(std::move(b));
  28. static_assert(ans == 12);
  29. // static_assert(ans == 0);
  30. return 0;
  31. }
Add Comment
Please, Sign In to add comment