Advertisement
punidota

Untitled

Jun 11th, 2016
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. #include <type_traits>
  4.  
  5. constexpr auto is_integer_range() -> bool;
  6.  
  7. template<typename T>
  8. constexpr auto is_integer_range(const T& range) ->
  9. decltype(range.first, range.second, std::is_integral<decltype(range.first)>::value,
  10. std::is_integral<decltype(range.second)>::value, true);
  11.  
  12. template<typename T>
  13. typename std::enable_if<std::is_integral<T>::value, bool>::type is_simple(const T& arg)
  14. {
  15. if (arg <= 0 || arg == 1) return false;
  16. for (int i = 2; i <= arg / 2; ++i)
  17. {
  18. if (arg % i == 0)
  19. {
  20. return false;
  21. }
  22. }
  23. return true;
  24. }
  25.  
  26. auto calculate() -> void
  27. {
  28. }
  29.  
  30. template<typename T, typename... Args>
  31. auto calculate(const T& arg, const Args&... args) ->
  32. decltype(is_integer_range(arg), void())
  33. {
  34. std::cout << "process range: " << arg.first << " " << arg.second << std::endl;
  35. for (typename T::first_type b = arg.first; b != arg.second; ++b)
  36. {
  37. if (is_simple(b))
  38. {
  39. std::cout << "Simple: " << b << std::endl;
  40. }
  41. }
  42. calculate(args...);
  43. }
  44.  
  45. int main()
  46. {
  47. calculate(std::make_pair(1, 100), std::make_pair(50, 150), std::make_pair(1, 10));
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement