Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Guard async(n,f,args) async from instantiation of async(num_groups,nu…

…m_threads,f,args) case
  • Loading branch information...
commit 215c35f60665e5cbafbcaa8b0cd497c69bf12e25 1 parent 0f5de6c
@jaredhoberock authored
Showing with 75 additions and 19 deletions.
  1. +75 −19 src/thread_group/detail/async_cpp03.hpp
View
94 src/thread_group/detail/async_cpp03.hpp
@@ -1,63 +1,119 @@
#pragma once
#include <cstddef>
+#include <tr1/type_traits>
#include "schedule_cpp03.hpp"
#include "parallel_for_async_cpp03.hpp"
namespace test
{
-//template<typename Function, typename... Args>
-// typename detail::enable_if_signature<
-// Function(Args...)
-// >::type
-// async(std::size_t num_groups, std::size_t num_threads, Function&& f, Args&&... args)
-//{
-// return detail::parallel_for_async(num_groups, num_threads, std::forward<Function>(f), std::forward<Args>(args)...);
-//} // end async()
+namespace async_detail
+{
+
+template<bool condition, typename Result = void>
+ struct enable_if
+{
+ typedef Result type;
+};
+
+template<typename Result>
+ struct enable_if<false,Result>
+{};
+
+template<typename T>
+ struct disable_if_integral
+ : enable_if<!std::tr1::is_integral<T>::value>
+{};
+
+
+}
+
template<typename Function>
- void async(std::size_t num_threads, Function f)
+ void async(std::size_t num_groups, std::size_t num_threads, Function f)
+{
+ std::tr1::tuple<> args;
+ return detail::parallel_for_async(num_groups, num_threads, f, args);
+} // end async()
+
+template<typename Function, typename Arg1>
+ void async(std::size_t num_groups, std::size_t num_threads, Function f, Arg1 arg1)
+{
+ std::tr1::tuple<Arg1> args(arg1);
+ return detail::parallel_for_async(num_groups, num_threads, f, args);
+} // end async()
+
+template<typename Function, typename Arg1, typename Arg2>
+ void async(std::size_t num_groups, std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2)
+{
+ std::tr1::tuple<Arg1,Arg2> args(arg1,arg2);
+ return detail::parallel_for_async(num_groups, num_threads, f, args);
+} // end async()
+
+template<typename Function, typename Arg1, typename Arg2, typename Arg3>
+ void async(std::size_t num_groups, std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3)
+{
+ std::tr1::tuple<Arg1,Arg2,Arg3> args(arg1,arg2,arg3);
+ return detail::parallel_for_async(num_groups, num_threads, f, args);
+} // end async()
+
+template<typename Function, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ void async(std::size_t num_groups, std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
+{
+ std::tr1::tuple<Arg1,Arg2,Arg3,Arg4> args(arg1,arg2,arg3,arg4);
+ return detail::parallel_for_async(num_groups, num_threads, f, args);
+} // end async()
+
+
+template<typename Function>
+ typename async_detail::disable_if_integral<Function>::type
+ async(std::size_t num_threads, Function f)
{
std::tr1::tuple<> args;
std::pair<std::size_t,std::size_t> schedule = detail::schedule_async(num_threads, f, args);
- return detail::parallel_for_async(schedule.first, schedule.second, f, args);
+ return async(schedule.first, schedule.second, f);
}
template<typename Function, typename Arg1>
- void async(std::size_t num_threads, Function f, Arg1 arg1)
+ typename async_detail::disable_if_integral<Function>::type
+ async(std::size_t num_threads, Function f, Arg1 arg1)
{
std::tr1::tuple<Arg1> args(arg1);
std::pair<std::size_t,std::size_t> schedule = detail::schedule_async(num_threads, f, args);
- return detail::parallel_for_async(schedule.first, schedule.second, f, args);
+ return async(schedule.first, schedule.second, f, arg1);
}
template<typename Function, typename Arg1, typename Arg2>
- void async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2)
+ typename async_detail::disable_if_integral<Function>::type
+ async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2)
{
std::tr1::tuple<Arg1,Arg2> args(arg1,arg2);
std::pair<std::size_t,std::size_t> schedule = detail::schedule_async(num_threads, f, args);
- return detail::parallel_for_async(schedule.first, schedule.second, f, args);
+ return async(schedule.first, schedule.second, f, arg1, arg2);
}
template<typename Function, typename Arg1, typename Arg2, typename Arg3>
- void async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3)
+ typename async_detail::disable_if_integral<Function>::type
+ async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3)
{
std::tr1::tuple<Arg1,Arg2,Arg3> args(arg1,arg2,arg3);
std::pair<std::size_t,std::size_t> schedule = detail::schedule_async(num_threads, f, args);
- return detail::parallel_for_async(schedule.first, schedule.second, f, args);
+ return async(schedule.first, schedule.second, f, arg1, arg2, arg3);
}
template<typename Function, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- void async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
+ typename async_detail::disable_if_integral<Function>::type
+ async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
{
std::tr1::tuple<Arg1,Arg2,Arg3,Arg4> args(arg1,arg2,arg3,arg4);
std::pair<std::size_t,std::size_t> schedule = detail::schedule_async(num_threads, f, args);
- return detail::parallel_for_async(schedule.first, schedule.second, f, args);
+ return async(schedule.first, schedule.second, f, arg1, arg2, arg3, arg4);
}
template<typename Function, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
- void async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
+ typename async_detail::disable_if_integral<Function>::type
+ async(std::size_t num_threads, Function f, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
{
std::tr1::tuple<Arg1,Arg2,Arg3,Arg4,Arg5> args(arg1,arg2,arg3,arg4,arg5);
std::pair<std::size_t,std::size_t> schedule = detail::schedule_async(num_threads, f, args);
Please sign in to comment.
Something went wrong with that request. Please try again.