00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_NUM_ROWS_INCLUDE
00013 #define MTL_NUM_ROWS_INCLUDE
00014
00015 #include <vector>
00016
00017 namespace mtl {
00018
00019 namespace traits {
00020
00022 template <typename Collection>
00023 struct num_rows {};
00024
00026 template <typename Value>
00027 struct num_rows< std::vector<Value> >
00028 {
00029 typedef std::size_t type;
00030 type operator()(const std::vector<Value>& v) { return v.size(); }
00031 };
00032
00034 template <typename Value, unsigned Size>
00035 struct num_rows<Value[Size]>
00036 {
00037 typedef std::size_t type;
00038 type operator()(const Value[Size]) { return Size; }
00039 };
00040
00042 template <typename Value, unsigned Rows, unsigned Cols>
00043 struct num_rows<Value[Rows][Cols]>
00044 {
00045 typedef std::size_t type;
00046 type operator()(const Value[Rows][Cols]) { return Rows; }
00047 };
00048 }
00049
00050
00052 template <typename Collection>
00053 typename traits::num_rows<Collection>::type
00054 inline num_rows(const Collection& c)
00055 {
00056 return traits::num_rows<Collection>()(c);
00057 }
00058
00059
00060 }
00061
00062 #endif // MTL_NUM_ROWS_INCLUDE