Added a bunch of voodoo to appease the bugs in visual studio. Also added

promotions to the global operator* overloads for the vector.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402737
This commit is contained in:
Davis King 2008-12-19 16:29:59 +00:00
parent 5348ed7f95
commit 1f8cd9c371
2 changed files with 80 additions and 20 deletions

View File

@ -52,6 +52,23 @@ namespace dlib
typedef double type;
};
// ----------------------------------------------------------------------------------------
// This insanity here is to work around a bug in visual studio 8. These two rebind
// structures are actually declared at a few points in this file because just having the
// one declaration here isn't enough for visual studio. It takes the three spread around
// to avoid all its bugs.
template <typename T, long N>
struct vc_rebind
{
typedef vector<T,N> type;
};
template <typename T, typename U, long N>
struct vc_rebind_promote
{
typedef vector<typename promote<T,U>::type,N> type;
};
// ----------------------------------------------------------------------------------------
template <typename T, typename U, typename enabled = void>
@ -175,6 +192,18 @@ namespace dlib
!*/
// This insanity here is to work around a bug in visual studio 8.
template <typename T, long N>
struct vc_rebind
{
typedef vector<T,N> type;
};
template <typename T, typename U, long N>
struct vc_rebind_promote
{
typedef vector<typename promote<T,U>::type,N> type;
};
public:
typedef T type;
@ -312,7 +341,7 @@ namespace dlib
// ---------------------------------------
vector<double,3> normalize (
typename vc_rebind<double,3>::type normalize (
) const
{
const double tmp = std::sqrt((double)(x()*x() + y()*y() + z()*z()));
@ -392,7 +421,7 @@ namespace dlib
// ---------------------------------------
template <typename U, long N>
vector<typename promote<T,U>::type,3> cross (
typename vc_rebind_promote<T,U,3>::type cross (
const vector<U,N>& rhs
) const
{
@ -456,7 +485,7 @@ namespace dlib
// ---------------------------------------
template <typename U, long N>
vector<typename promote<T,U>::type,3> operator + (
typename vc_rebind_promote<T,U,3>::type operator + (
const vector<U,N>& rhs
) const
{
@ -476,7 +505,7 @@ namespace dlib
// ---------------------------------------
template <typename U, long N>
vector<typename promote<T,U>::type,3> operator - (
typename vc_rebind_promote<T,U,3>::type operator - (
const vector<U,N>& rhs
) const
{
@ -496,7 +525,7 @@ namespace dlib
// ---------------------------------------
template <typename U>
vector<typename promote<T,U>::type,3> operator / (
typename vc_rebind_promote<T,U,3>::type operator / (
const U& val
) const
{
@ -555,6 +584,19 @@ namespace dlib
- z() == 0
!*/
// This insanity here is to work around a bug in visual studio 8.
template <typename T, long N>
struct vc_rebind
{
typedef vector<T,N> type;
};
template <typename T, typename U, long N>
struct vc_rebind_promote
{
typedef vector<typename promote<T,U>::type,N> type;
};
public:
typedef T type;
@ -685,7 +727,8 @@ namespace dlib
// ---------------------------------------
vector<double,2> normalize (
typename vc_rebind<double,2>::type normalize (
) const
{
const double tmp = std::sqrt((double)(x()*x() + y()*y()));
@ -809,7 +852,7 @@ namespace dlib
// ---------------------------------------
template <typename U, long N>
vector<typename promote<T,U>::type,N> operator + (
typename vc_rebind_promote<T,U,N>::type operator + (
const vector<U,N>& rhs
) const
{
@ -829,7 +872,7 @@ namespace dlib
// ---------------------------------------
template <typename U, long N>
vector<typename promote<T,U>::type,N> operator - (
typename vc_rebind_promote<T,U,N>::type operator - (
const vector<U,N>& rhs
) const
{
@ -840,7 +883,7 @@ namespace dlib
// ---------------------------------------
template <typename U>
vector<typename promote<T,U>::type,2> operator / (
typename vc_rebind_promote<T,U,2>::type operator / (
const U& val
) const
{
@ -899,7 +942,7 @@ namespace dlib
// ---------------------------------------
template <typename U, long N>
vector<typename promote<T,U>::type,3> cross (
typename vc_rebind_promote<T,U,3>::type cross (
const vector<U,N>& rhs
) const
{
@ -921,45 +964,49 @@ namespace dlib
template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,2> >::type operator* (
inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,2>::type >::type operator* (
const vector<T,2>& v,
const U& s
)
{
return vector<T,2>(v.x()*s, v.y()*s);
typedef typename vc_rebind_promote<T,U,2>::type ret_type;
return ret_type(v.x()*s, v.y()*s);
}
// ----------------------------------------------------------------------------------------
template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,2> >::type operator* (
inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,2>::type >::type operator* (
const U& s,
const vector<T,2>& v
)
{
return vector<T,2>(v.x()*s, v.y()*s);
typedef typename vc_rebind_promote<T,U,2>::type ret_type;
return ret_type(v.x()*s, v.y()*s);
}
// ----------------------------------------------------------------------------------------
template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,3> >::type operator* (
inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,3>::type >::type operator* (
const vector<T,3>& v,
const U& s
)
{
return vector<T,3>(v.x()*s, v.y()*s, v.z()*s);
typedef typename vc_rebind_promote<T,U,3>::type ret_type;
return ret_type(v.x()*s, v.y()*s, v.z()*s);
}
// ----------------------------------------------------------------------------------------
template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,3> >::type operator* (
inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,3>::type >::type operator* (
const U& s,
const vector<T,3>& v
)
{
return vector<T,3>(v.x()*s, v.y()*s, v.z()*s);
typedef typename vc_rebind_promote<T,U,3>::type ret_type;
return ret_type(v.x()*s, v.y()*s, v.z()*s);
}
// ----------------------------------------------------------------------------------------

View File

@ -202,6 +202,19 @@ namespace
DLIB_CASSERT(vd3.y() == 4*2 + 5*3 + 6*4,"");
DLIB_CASSERT(vd3.z() == 7*2 + 8*3 + 9*4,"");
(vd3*2).dot(vd3);
(vd2*2).dot(vd3);
(vd3*2).dot(vd2);
(vd2*2).dot(vd2);
(2*vd3*2).dot(vd3);
(2*vd2*2).dot(vd3);
(2*vd3*2).dot(vd2);
(2*vd2*2).dot(vd2);
(vd2 + vd3).dot(vd2);
(vd2 - vd3).dot(vd2);
(vd2/2).dot(vd2);
(vd3/2).dot(vd2);
}
}