/usr/include/bobcat/foreach is in libbobcat-dev 3.23.01-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #ifndef INCLUDED_BOBCAT_FOREACH_
#define INCLUDED_BOBCAT_FOREACH_
#include <bobcat/typetrait>
namespace FBB
{
template <bool derefenceable, typename Iter, typename Function>
struct FE3
{
inline void operator()(Iter begin, Iter end, Function &fun)
{
for ( ; begin != end; )
fun(begin++);
}
};
template <typename Iter, typename Function>
struct FE3<true, Iter, Function>
{
inline void operator()(Iter begin, Iter end, Function &fun)
{
for ( ; begin != end; )
fun(*begin++);
}
};
// Generic case: anything that's not specialized.
// In practice: not dereferenceable, object reference
template <bool derefenceable, typename Iter, typename Class, typename Member>
struct FE4
{
inline void operator()(Iter begin, Iter end, Class &obj, Member member)
{
for ( ; begin != end; )
(obj.*member)(begin++);
}
};
// Specialization: dereferenceable, object reference
template <typename Iter, typename Class, typename Member>
struct FE4<true, Iter, Class, Member>
{
inline void operator()(Iter begin, Iter end, Class &obj, Member member)
{
for ( ; begin != end; )
(obj.*member)(*begin++);
}
};
// Specialization: dereferenceable, object pointer
template <typename Iter, typename Class, typename Member>
struct FE4<true, Iter, Class *, Member>
{
inline void operator()(Iter begin, Iter end, Class *obj, Member member)
{
for ( ; begin != end; )
(obj->*member)(*begin++);
}
};
// Specialization: Not dereferenceable, object pointer
template <typename Iter, typename Class, typename Member>
struct FE4<false, Iter, Class *, Member>
{
inline void operator()(Iter begin, Iter end, Class *obj, Member member)
{
for ( ; begin != end; )
(obj->*member)(begin++);
}
};
template <typename Iter, typename Function>
void for_each( Iter begin, Iter end, Function function)
{
FE3<TypeTrait<Iter>::isDereferenceable, Iter, Function>()
(begin, end, function);
}
template<typename Iter, typename Object, typename Member>
inline void for_each(Iter begin, Iter const &end,
Object &object, Member member)
{
FE4<TypeTrait<Iter>::isDereferenceable, Iter, Object, Member>()
(begin, end, object, member);
}
template<typename Iter, typename Object, typename Member>
inline void for_each(Iter begin, Iter const &end,
Object *object, Member member)
{
FE4<TypeTrait<Iter>::isDereferenceable, Iter, Object *, Member>()
(begin, end, object, member);
}
} // FBB
#endif
|