37#ifndef VIGRA_BASICS_HXX
38#define VIGRA_BASICS_HXX
42#include "metaprogramming.hxx"
45#include "mathutil.hxx"
58doxygen_overloaded_function(template <class T> std::string
asString(T t))
60#define VIGRA_AS_STRING(T) \
61inline std::string asString(T t) \
63 std::stringstream s; \
69VIGRA_AS_STRING(
signed char)
70VIGRA_AS_STRING(
unsigned char)
71VIGRA_AS_STRING(
signed short)
72VIGRA_AS_STRING(
unsigned short)
73VIGRA_AS_STRING(
signed long)
74VIGRA_AS_STRING(
unsigned long)
75VIGRA_AS_STRING(
signed long long)
76VIGRA_AS_STRING(
unsigned long long)
77VIGRA_AS_STRING(
signed int)
78VIGRA_AS_STRING(
unsigned int)
80VIGRA_AS_STRING(
double)
81VIGRA_AS_STRING(
long double)
82VIGRA_AS_STRING(
void *)
87std::string operator<<(std::string
const & s, T
const & t)
98 for(
unsigned int k=0; k<s.size(); ++k)
99 s[k] = (std::string::value_type)std::tolower(s[k]);
103inline std::string
tolower(
const char * s)
105 return tolower(std::string(s));
114 for(
unsigned int k=0; k<s.size(); ++k)
116 if(std::isspace(s[k]))
118 res += (std::string::value_type)std::tolower(s[k]);
135 FinallyImpl(T & destructor)
136 : destructor_(destructor)
149#define VIGRA_TOKEN_PASTE_IMPL(x, y) x##y
150#define VIGRA_TOKEN_PASTE(x, y) VIGRA_TOKEN_PASTE_IMPL(x, y)
152#define VIGRA_FINALLY_IMPL(destructor, counter) \
153 auto VIGRA_TOKEN_PASTE(_vigra_finally_impl_, counter) = [&]() { destructor; }; \
154 ::vigra::detail::FinallyImpl<decltype(VIGRA_TOKEN_PASTE(_vigra_finally_impl_, counter))> \
155 VIGRA_TOKEN_PASTE(_vigra_finally_, counter)(VIGRA_TOKEN_PASTE(_vigra_finally_impl_, counter))
207#define VIGRA_FINALLY(destructor) \
208 VIGRA_FINALLY_IMPL(destructor, __COUNTER__)
212template <
class T1,
class T2>
213ostream & operator<<(ostream & s, std::pair<T1, T2>
const & p)
215 s <<
"(" << p.first <<
", " << p.second <<
")";
225 template <
typename TPL,
size_t N,
typename FUNCTOR>
226 struct for_each_in_tuple_impl
228 typedef for_each_in_tuple_impl<TPL, N-1, FUNCTOR> ForEachRecursion;
230 void operator()(TPL && t, FUNCTOR && f)
const
232 ForEachRecursion()(std::forward<TPL>(t), std::forward<FUNCTOR>(f));
233 f(std::get<N-1>(std::forward<TPL>(t)));
237 template <
typename TPL,
typename FUNCTOR>
238 struct for_each_in_tuple_impl<TPL, 0, FUNCTOR>
240 void operator()(TPL &&, FUNCTOR &&)
const
281template <
typename TPL,
typename FUNCTOR>
284 typedef typename std::decay<TPL>::type UNQUALIFIED_TPL;
285 typedef detail::for_each_in_tuple_impl<TPL, std::tuple_size<UNQUALIFIED_TPL>::value, FUNCTOR> ForEachImpl;
287 ForEachImpl()(std::forward<TPL>(t), std::forward<FUNCTOR>(f));
std::string tolower(std::string s)
Definition utilities.hxx:96
std::string normalizeString(std::string const &s)
Definition utilities.hxx:110
std::string asString(T t)(...)
void for_each_in_tuple(TPL &&t, FUNCTOR &&f)
Definition utilities.hxx:282