mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-20 20:04:26 +08:00
add example to the documentation
This commit is contained in:
parent
835e0c9f67
commit
aa3294f14e
@ -1 +1,3 @@
|
|||||||
add_executable(tutorial tutorial.cpp)
|
add_executable(tutorial tutorial.cpp)
|
||||||
|
add_executable(example example.cpp)
|
||||||
|
|
||||||
|
28
doc/example.cpp
Normal file
28
doc/example.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "../src/All"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
void foo(const EiObject<Scalar, Derived>& m)
|
||||||
|
{
|
||||||
|
cout << "Here's m:" << endl << m << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Scalar, typename Derived>
|
||||||
|
EiScalarProduct<Derived>
|
||||||
|
twice(const EiObject<Scalar, Derived>& m)
|
||||||
|
{
|
||||||
|
return static_cast<Scalar>(2) * m;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int, char**)
|
||||||
|
{
|
||||||
|
EiMatrix2d m;
|
||||||
|
m(0,0)= 1;
|
||||||
|
m(1,0)= 2;
|
||||||
|
m(0,1)= 3;
|
||||||
|
m(1,1)= 4;
|
||||||
|
foo(m);
|
||||||
|
foo(twice(m));
|
||||||
|
return 0;
|
||||||
|
}
|
@ -43,7 +43,7 @@ int main(int, char **)
|
|||||||
<< "overwritten _while_ the matrix product m * m is being computed." << endl
|
<< "overwritten _while_ the matrix product m * m is being computed." << endl
|
||||||
<< "This is the counterpart of eliminating temporary objects!" << endl
|
<< "This is the counterpart of eliminating temporary objects!" << endl
|
||||||
<< "Anyway, if you want to store m * m into m, you can do this:" << endl
|
<< "Anyway, if you want to store m * m into m, you can do this:" << endl
|
||||||
<< " m = eval(m * m);" << endl;
|
<< " m = (m * m).eval();" << endl;
|
||||||
m = m_save;
|
m = m_save;
|
||||||
m = (m * m).eval();
|
m = (m * m).eval();
|
||||||
cout << "And m is now:" << endl << m << endl << "as was expected." << endl;
|
cout << "And m is now:" << endl << m << endl << "as was expected." << endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user