1 #ifndef _GLOBALTRAITS_H_ 2 #define _GLOBALTRAITS_H_ 13 #include <boost/array.hpp> 14 #include <boost/call_traits.hpp> 15 #include <boost/type_traits.hpp> 16 #include <boost/utility/enable_if.hpp> 31 #define TIL_FOR_ALL_NUMERICAL_TYPES(macro) \ 37 macro (unsigned short); \ 39 macro (unsigned char); 51 template <
typename TCollection >
61 template <
class TContainer1,
class TContainer2,
typename TBinaryFunctor >
63 loop_cc(
const TContainer1 & c1, TContainer2 &res, TBinaryFunctor f)
66 typename TContainer1::const_iterator iC1 = c1.begin();
67 typename TContainer2::iterator iRes = res.begin();
68 for (; iC1 != c1.end(); ++iC1, ++iRes)
79 template <
typename TMap1,
typename TMap2,
typename TFunctor >
84 void operator()(
const TMap1 & map1,
const TMap2 & map2, TFunctor f)
86 typename TMap1::const_iterator i1 = map1.begin();
87 typename TMap2::const_iterator i2 = map2.begin();
91 if (i1->first < i2->first)
93 if (++i1 == map1.end())
return;
95 else if (i1->first > i2->first)
97 if (++i2 == map2.end())
return;
104 if (++i1 == map1.end())
return;
105 if (++i2 == map2.end())
return;
112 typedef typename boost::enable_if<is_map<typename naked_type<TMap1>::type > >::type CheckTMap1isMap;
113 typedef typename boost::enable_if<is_map<typename naked_type<TMap2>::type > >::type CheckTMap2isMap;
118 template <
typename TMap1,
typename TMap2,
typename TFunctor >
120 typename boost::enable_if<boost::is_empty<TFunctor> >::type
127 template <
typename TMap1,
typename TMap2,
typename TFunctor >
129 typename boost::disable_if<boost::is_empty<TFunctor> >::type
137 template <
typename TMap1,
typename TMap2,
typename TFunctor >
146 typename TMap1::const_iterator i1 = map1.begin();
147 typename TMap2::const_iterator i2 = map2.begin();
149 if (i1 == map1.end())
goto map1over_checkmap2;
150 if (i2 == map2.end())
goto map2over;
156 if (i1->first < i2->first)
162 f(*i1,
typename TMap2::mapped_type());
163 if (++i1 == map1.end())
167 else if (i1->first > i2->first)
171 f(
typename TMap1::mapped_type(), *i2);
172 if (++i2 == map2.end())
181 if (++i1 == map1.end())
185 goto map1over_checkmap2;
187 if (++i2 == map2.end())
196 if (i2 == map2.end())
return;
201 f(
typename TMap1::mapped_type(), *i2);
203 while (++i2 != map2.end());
209 f(*i1,
typename TMap2::mapped_type());
211 while (++i1 != map1.end());
245 template <
typename TMap1,
typename TMap2,
typename TFunctor >
247 typename boost::enable_if<boost::is_empty<TFunctor> >::type
254 template <
typename TMap1,
typename TMap2,
typename TFunctor >
256 typename boost::disable_if<boost::is_empty<TFunctor> >::type
265 template <
typename TMap1,
typename TMap2,
typename TFunctor >
274 typename TMap1::const_iterator i1 = map1.begin();
275 typename TMap2::const_iterator i2 = map2.begin();
281 if (i1->first < i2->first)
287 if (f(*i1,
typename TMap2::mapped_type()))
return;
288 if (++i1 == map1.end())
goto map1over;
290 else if (i1->first > i2->first)
294 f(
typename TMap1::mapped_type(), *i2);
295 if (++i2 == map2.end())
goto map2over;
302 if (++i1 == map1.end())
goto map1over_checkmap2;
303 if (++i2 == map2.end())
goto map2over;
310 if (++i2 == map2.end())
return;
315 f(
typename TMap1::mapped_type(), *i2);
317 while (++i2 != map2.end());
323 f(*i1,
typename TMap2::mapped_type());
325 while (++i1 != map1.end());
334 template <
typename T1,
typename T2,
typename T3 >
336 typename boost::enable_if_c<
337 std::numeric_limits<T1>::is_specialized &&
338 std::numeric_limits<T2>::is_specialized
345 template <
typename T >
347 typename boost::enable_if_c<std::numeric_limits<T>::is_specialized>::type
356 template <
typename T1,
typename T2,
typename T3 >
358 typename boost::enable_if_c<
359 std::numeric_limits<T1>::is_specialized &&
360 std::numeric_limits<T2>::is_specialized
367 template <
typename T1,
typename T2 >
368 typename boost::enable_if_c<is_container<T1>::value>::type
374 template <
typename T1,
typename T2,
typename T3 >
375 typename boost::enable_if_c<is_container<T1>::value>::type
376 mul(
const T1 & x,
const T2 & y, T3 & z)
381 template <
typename TContainer >
382 inline void resize(TContainer & c, std::size_t n)
387 template <
typename T, std::
size_t D >
392 throw std::length_error(
"boost::array can't be resized to a different size");
398 #endif //_GLOBALTRAITS_H_
Apply a functor to two sparse vectors only where they both have data.
Belongs to package Box Do not include directly, include til/Box.h instead.
void resize(numeric_array< T, D > &, std::size_t newSize) __attribute__((__deprecated__))
boost::enable_if< boost::is_empty< TFunctor > >::type loop_mapPairs(TMap1 &map1, TMap2 &map2, TFunctor f)
numeric_array< T, D > size(const Box< T, D > &box)
Return the size of a box.
boost::enable_if_c< std::numeric_limits< T1 >::is_specialized &&std::numeric_limits< T2 >::is_specialized >::type sub(T1 x, T2 y, T3 &z)
This file contains forward declarations of classes defined in the TIL library.
void operator()(TMap1 &map1, TMap2 &map2, TFunctor f)
std::size_t operator()(const TCollection &c)
void operator()(TMap1 &map1, TMap2 &map2, TFunctor f)
Apply a functor to a pair of sparse vectors where either one has data.
This file contains all the material a library user should need to use template expressions.
void loop_cc(const TContainer1 &c1, TContainer2 &res, TBinaryFunctor f)
void operator()(const TMap1 &map1, const TMap2 &map2, TFunctor f)
boost::enable_if_c< is_container< TContainer >::value &&!is_container< T >::value >::type loop(TContainer &c, T v, TBinaryFunctor f)
Apply a binary functor to a collection and a constant.
boost::enable_if< boost::is_empty< TFunctor > >::type loop_mapEach(TMap1 &map1, TMap2 &map2, TFunctor f)
boost::enable_if_c< std::numeric_limits< T1 >::is_specialized &&std::numeric_limits< T2 >::is_specialized >::type mul(T1 x, T2 y, T3 &z)