IMP  2.0.1
The Integrative Modeling Platform
base/utility.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/utility.h \brief Various general useful functions for IMP.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPBASE_UTILITY_H
9 #define IMPBASE_UTILITY_H
10 
11 #include <IMP/base/base_config.h>
12 #include <boost/utility.hpp>
13 #include <cmath>
14 #include "base_macros.h"
15 #include <IMP/base/Vector.h>
16 #include <IMP/base/math.h>
17 
18 
19 IMPBASE_BEGIN_NAMESPACE
20 
21 
22 
23 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
24 template <class T>
25 inline T square(T t) IMP_NO_SIDEEFFECTS;
26 template <class T>
27 inline T cube(T t) IMP_NO_SIDEEFFECTS;
28 
29 
30 //! Compute the square of a number
31 template <class T>
32 inline T square(T t)
33 {
34  return t*t;
35 }
36 
37 //! Compute the cube of a number
38 template <class T>
39 inline T cube(T t)
40 {
41  return t*t*t;
42 }
43 
44 template <class T>
45 inline bool is_nan(const T& a) {
46  return isnan(a);
47 }
48 
49 //! A version of std::for_each which works with ranges
50 /** This is needed to apply the functor to a range which is a temporary
51  object, since you can't call both begin and end on it.
52  */
53 template <class Range, class Functor>
54 inline void for_each(const Range &r, const Functor &f) {
55  std::for_each(r.begin(), r.end(), f);
56 }
57 
58 template <class T>
59 inline int compare(const T &a, const T &b) {
60  return a.compare(b);
61 }
62 
63 /** Convert between different types of lists.
64  */
65 template <class Out, class In>
66 inline Out get_as(const In &in) {
67  return Out(in.begin(), in.end());
68 }
69 #endif
70 
71 /** Return a unique name produced from the string by replacing
72  %1% with a sequential number.*/
73 IMPBASEEXPORT
74 std::string get_unique_name(std::string templ);
75 
76 IMPBASE_END_NAMESPACE
77 
78 #endif /* IMPBASE_UTILITY_H */