1 /// @ref gtx_range
2 /// @file glm/gtx/range.hpp
3 /// @author Joshua Moerman
4 ///
5 /// @defgroup gtx_range GLM_GTX_range
6 /// @ingroup gtx
7 ///
8 /// @brief Defines begin and end for vectors and matrices. Useful for range-based for loop.
9 /// The range is defined over the elements, not over columns or rows (e.g. mat4 has 16 elements).
10 ///
11 /// <glm/gtx/range.hpp> need to be included to use these functionalities.
12 
13 #pragma once
14 
15 // Dependencies
16 #include "../detail/setup.hpp"
17 
18 #if !GLM_HAS_RANGE_FOR
19 #	error "GLM_GTX_range requires C++11 suppport or 'range for'"
20 #endif
21 
22 #include "../gtc/type_ptr.hpp"
23 #include "../gtc/vec1.hpp"
24 
25 namespace glm
26 {
27 	/// @addtogroup gtx_range
28 	/// @{
29 
30 	template <typename T, precision P>
components(tvec1<T,P> const & v)31 	inline length_t components(tvec1<T, P> const & v)
32 	{
33 		return v.length();
34 	}
35 
36 	template <typename T, precision P>
components(tvec2<T,P> const & v)37 	inline length_t components(tvec2<T, P> const & v)
38 	{
39 		return v.length();
40 	}
41 
42 	template <typename T, precision P>
components(tvec3<T,P> const & v)43 	inline length_t components(tvec3<T, P> const & v)
44 	{
45 		return v.length();
46 	}
47 
48 	template <typename T, precision P>
components(tvec4<T,P> const & v)49 	inline length_t components(tvec4<T, P> const & v)
50 	{
51 		return v.length();
52 	}
53 
54 	template <typename genType>
components(genType const & m)55 	inline length_t components(genType const & m)
56 	{
57 		return m.length() * m[0].length();
58 	}
59 
60 	template <typename genType>
begin(genType const & v)61 	inline typename genType::value_type const * begin(genType const & v)
62 	{
63 		return value_ptr(v);
64 	}
65 
66 	template <typename genType>
end(genType const & v)67 	inline typename genType::value_type const * end(genType const & v)
68 	{
69 		return begin(v) + components(v);
70 	}
71 
72 	template <typename genType>
begin(genType & v)73 	inline typename genType::value_type * begin(genType& v)
74 	{
75 		return value_ptr(v);
76 	}
77 
78 	template <typename genType>
end(genType & v)79 	inline typename genType::value_type * end(genType& v)
80 	{
81 		return begin(v) + components(v);
82 	}
83 
84 	/// @}
85 }//namespace glm
86