diff options
author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2009-08-22 09:40:53 +0000 |
---|---|---|
committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2009-08-22 09:40:53 +0000 |
commit | 4e6cebbb431222a5d8fa3bc62d5de44c93c8a93e (patch) | |
tree | 3800e20f0eaaa0b9dd88d8fafa21e18e747ca01b /core/opt_traits.hpp | |
parent | 42ef6e5280c71ea770bf5a1a9bfb570d62b3c48e (diff) | |
download | opt-utilities-4e6cebbb431222a5d8fa3bc62d5de44c93c8a93e.tar.bz2 |
git-svn-id: file:///home/svn/opt_utilities@48 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'core/opt_traits.hpp')
-rw-r--r-- | core/opt_traits.hpp | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/core/opt_traits.hpp b/core/opt_traits.hpp index b8426e0..7c2638a 100644 --- a/core/opt_traits.hpp +++ b/core/opt_traits.hpp @@ -1,22 +1,41 @@ +/** + \file opt_traits.hpp + */ + #ifndef ARRAY_OPERATION #define ARRAY_OPERATION #include <cstddef> namespace opt_utilities { - /////////Useful function/////////////////////////////////// + /** + Get the size of an array object + \param x the array object + \return the size of the array object + */ template <typename T> inline size_t get_size(const T& x) { return x.size(); } + /** + Trait class, in which the types of elements in an array are defined + \tparam the type of the array object + */ template <typename T> class element_type_trait { public: + /** + Default definition of element_type + */ typedef typename T::value_type element_type; }; + + /** + The return type trait of some certain data types. + */ template <typename T> class return_type_trait { @@ -26,6 +45,14 @@ namespace opt_utilities typedef const T& const_reference_type; }; + + /** + Help function to get the i-th element from an array + \tparam T the type of the array object + \param x the array object + \param i the order of the element + \return the fetched element value, const reference + */ template <typename T> inline typename return_type_trait<typename element_type_trait<T>::element_type>:: @@ -33,14 +60,16 @@ namespace opt_utilities { return x[i]; } - /* - template <typename T> - inline typename element_type_trait<T>::element_type& get_element(T& x,size_t i) - { - return x[i]; - } - */ + + /** + set ths i-th element by a given value + \tparam T the type of the array object + \tparam Tx the type of the element + \param x the array object + \param i the order of the element + \param v the value of the element to be set + */ template<typename T,typename TX> inline void set_element(T& x,size_t i, const TX& v) @@ -48,12 +77,28 @@ namespace opt_utilities x[i]=v; } + + /** + resize an array object + \tparam T the type of the array + \param x the array object + \param s the new size + */ template <typename T> inline void resize(T& x,size_t s) { x.resize(s); } + + /** + Assignment operator of two array objects + \tparam Tl the type of left-hand array + \tparam Tr the type of right-hand array + \param lhs the left-hand array + \param rhs the right-hand array + \return the reference of the left-hand array + */ template <typename Tl,typename Tr> inline Tl& opt_eq(Tl& lhs,const Tr& rhs) { |