From aa3294f14e33ae5078fcdbedc9df241a674a9f2e Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Fri, 28 Sep 2007 06:17:36 +0000 Subject: add example to the documentation --- doc/CMakeLists.txt | 2 ++ doc/example.cpp | 28 ++++++++++++++++++++++++++++ doc/tutorial.cpp | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 doc/example.cpp (limited to 'doc') diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 919e4a44b..7b236a27f 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1 +1,3 @@ add_executable(tutorial tutorial.cpp) +add_executable(example example.cpp) + diff --git a/doc/example.cpp b/doc/example.cpp new file mode 100644 index 000000000..89f7820b1 --- /dev/null +++ b/doc/example.cpp @@ -0,0 +1,28 @@ +#include "../src/All" + +using namespace std; + +template +void foo(const EiObject& m) +{ + cout << "Here's m:" << endl << m << endl; +} + +template +EiScalarProduct +twice(const EiObject& m) +{ + return static_cast(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; +} diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp index d909779c5..1da3deb1d 100644 --- a/doc/tutorial.cpp +++ b/doc/tutorial.cpp @@ -43,7 +43,7 @@ int main(int, char **) << "overwritten _while_ the matrix product m * m is being computed." << 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 - << " m = eval(m * m);" << endl; + << " m = (m * m).eval();" << endl; m = m_save; m = (m * m).eval(); cout << "And m is now:" << endl << m << endl << "as was expected." << endl; -- cgit v1.2.3