Commit a92de57e authored by Davis King's avatar Davis King

Made it so you can write statements like mymat = m = 0;

That is, chain the = operator when using a literal assignment on
matrix objects.
parent 9fa63ad8
...@@ -1592,7 +1592,7 @@ namespace dlib ...@@ -1592,7 +1592,7 @@ namespace dlib
*/ */
literal_assign_helper(const literal_assign_helper& item) : m(item.m), r(item.r), c(item.c), has_been_used(false) {} literal_assign_helper(const literal_assign_helper& item) : m(item.m), r(item.r), c(item.c), has_been_used(false) {}
literal_assign_helper(matrix* m_): m(m_), r(0), c(0),has_been_used(false) {next();} explicit literal_assign_helper(matrix* m_): m(m_), r(0), c(0),has_been_used(false) {next();}
~literal_assign_helper() ~literal_assign_helper()
{ {
DLIB_CASSERT(!has_been_used || r == m->nr(), DLIB_CASSERT(!has_been_used || r == m->nr(),
...@@ -1620,6 +1620,8 @@ namespace dlib ...@@ -1620,6 +1620,8 @@ namespace dlib
private: private:
friend class matrix;
void next ( void next (
) const ) const
{ {
...@@ -1639,6 +1641,14 @@ namespace dlib ...@@ -1639,6 +1641,14 @@ namespace dlib
public: public:
matrix& operator = (
const literal_assign_helper& val
)
{
*this = *val.m;
return *this;
}
const literal_assign_helper operator = ( const literal_assign_helper operator = (
const T& val const T& val
) )
......
...@@ -1303,6 +1303,22 @@ namespace ...@@ -1303,6 +1303,22 @@ namespace
DLIB_TEST(is_finite(m)); DLIB_TEST(is_finite(m));
} }
{
matrix<int> m(4,1), mm;
mm = (m = 1,2,3,4);
DLIB_TEST(m(0) == 1);
DLIB_TEST(m(1) == 2);
DLIB_TEST(m(2) == 3);
DLIB_TEST(m(3) == 4);
DLIB_TEST(mm == m);
DLIB_TEST(mm(0) == 1);
DLIB_TEST(mm(1) == 2);
DLIB_TEST(mm(2) == 3);
DLIB_TEST(mm(3) == 4);
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment