3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-01 03:33:50 +01:00
dft_tools/test/triqs/clef/chain_call.cpp
Olivier Parcollet 2c542647fd clef : new version using lvalues and moving rvalues
- change : all objects are by default
  stored now by reference, not by copy any more.
  Unless the trait force_copy_in_expr is true.
- rvalue refs are moved into the tree
- simplifies a lot the writing of lazy method, objects.
- added a macro for methods
- tests ok. Further check needed to control absence of copies...
- improved documentation
2013-09-08 15:04:12 +02:00

50 lines
1.0 KiB
C++

#include "./common.hpp"
#include <vector>
struct F2_vec {
std::vector<F2> vec;
F2_vec(size_t siz=0): vec (siz) {}
F2_vec(F2_vec const & x): vec(x.vec) {}
F2 const & operator()(size_t i) const { return vec[i];}
TRIQS_CLEF_IMPLEMENT_LAZY_CALL(F2_vec);
template<typename Fnt>
friend void triqs_clef_auto_assign (F2_vec const & x, Fnt f) {
for (size_t i=0; i< x.vec.size(); ++i) triqs_clef_auto_assign(x.vec[i], f(i));
}
friend std::ostream & operator<<(std::ostream & out, F2_vec const & x) { return out<<"F2_vec";}
};
triqs::clef::placeholder <4> i_;
using namespace triqs::clef;
int main() {
F2_vec V(3);
//double x=1,y=2;
{
auto expr = V(i_)(x_,y_);
std::cout<<"expr = "<< expr<< std::endl;
TEST( tql::eval(expr, x_=2,y_=3, i_=0));
TEST( tql::eval(expr, x_=2));
TEST( tql::eval(expr, x_=2,i_=1));
TEST( tql::eval(expr, x_=2,y_=3));
TEST( tql::eval( tql::eval(expr, x_=2,y_=3) , i_=0) );
std::cout<<"-------------"<<std::endl;
}
{
// test assign
V(i_)(x_,y_) << x_ + i_; // + 10*y_ + 100*i_;
}
}