Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <utility>
- #include <type_traits>
- constexpr auto is_integer_range() -> bool;
- template<typename T>
- constexpr auto is_integer_range(const T& range) ->
- decltype(range.first, range.second, std::is_integral<decltype(range.first)>::value,
- std::is_integral<decltype(range.second)>::value, true);
- template<typename T>
- typename std::enable_if<std::is_integral<T>::value, bool>::type is_simple(const T& arg)
- {
- if (arg <= 0 || arg == 1) return false;
- for (int i = 2; i <= arg / 2; ++i)
- {
- if (arg % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- auto calculate() -> void
- {
- }
- template<typename T, typename... Args>
- auto calculate(const T& arg, const Args&... args) ->
- decltype(is_integer_range(arg), void())
- {
- std::cout << "process range: " << arg.first << " " << arg.second << std::endl;
- for (typename T::first_type b = arg.first; b != arg.second; ++b)
- {
- if (is_simple(b))
- {
- std::cout << "Simple: " << b << std::endl;
- }
- }
- calculate(args...);
- }
- int main()
- {
- calculate(std::make_pair(1, 100), std::make_pair(50, 150), std::make_pair(1, 10));
- }
Add Comment
Please, Sign In to add comment