1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#ifndef INCLUDED_BOBCAT_REPEAT_
#define INCLUDED_BOBCAT_REPEAT_
#include <bobcat/typetrait>
namespace FBB
{
template <bool type>
struct Repeat__;
template <>
struct Repeat__<false>
{
template <typename Fun, typename ...Params>
static void call(Fun fun, Params &&...params)
{
fun(std::forward<Params>(params)...);
}
};
template <>
struct Repeat__<true>
{
template <typename Class, typename Member, typename ...Params>
static void call(Class &obj, Member member, Params &&...params)
{
(obj.*member)(std::forward<Params>(params)...);
}
template <typename Class, typename Member, typename ...Params>
static void call(Class const &obj, Member member, Params &&...params)
{
(obj.*member)(std::forward<Params>(params)...);
}
};
template <typename Counter, typename First, typename ...Params>
inline void repeat(Counter counter, First &&first, Params &&...params)
{
for (; counter; --counter)
Repeat__<TypeTrait<First>::isClass>::call(
std::forward<First>(first),
std::forward<Params>(params)...);
}
} // FBB
#endif
|