
Indeed, it's readable. But I talked about 100 unit tests that vary a bit. Let's settle for 5. The STL way:
array<int, 1> log_constants = { a1 }; vector<int> cont; int n = n1; foreach(i, log_constants) int x = f1(i);
for(int j = 0; j < n;++j) { cont.push_front(x); } } array<int, 2> log_constants = { a2, b2 }; vector<int> cont; int n = n2; foreach(i, log_constants) int x = f2(i);
for(int j = 0; j < n;++j) { cont.push_front(x); } } array<int, 3> log_constants = { a3, b3, c3 }; vector<int> cont; int n = n3; foreach(i, log_constants) int x = f3(i);
for(int j = 0; j < n;++j) { cont.push_front(x); } } array<int, 4> log_constants = { a4, b4, c4, d4 }; vector<int> cont; int n = n4; foreach(i, log_constants) int x = f4(i);
for(int j = 0; j < n;++j) { cont.push_front(x); } } array<int, 5> log_constants = { a5, b5, c5, d5, e5 }; vector<int> cont; int n = n5; foreach(i, log_constants) int x = f5(i);
for(int j = 0; j < n;++j) { cont.push_front(x); } }
Assign v2 way:
csv( // 1 deque<int, push_front_>( _nil ) % ( _data = f1 ) % ( _repeat = n1 ), a1 ); csv( // 2 deque<int, push_front_>( _nil ) % ( _data = f2 ) % ( _repeat = n2 ), a2, b2 ); csv( // 3 deque<int, push_front_>( _nil ) % ( _data = f3 ) % ( _repeat = n3 ), a3, b3, c3 ); csv( // 4 deque<int, push_front_>( _nil ) % ( _data = f4 ) % ( _repeat = n4 ), a4, b4, c4, d4 ); csv( // 5 deque<int, push_front_>( _nil ) % ( _data = f5 ) % ( _repeat = n5 ), a5, b5, c5, d5, e5 );
Isn't this more clear, and less error prone? It is not that much, and not "crucial", but the claim of the library is just as modest:
Quick answer, I'll try to me give more feedback tomorrow: I don't work a lot with copy'n'paste. There's always a structure to be find somewhere, and this structure can be identified and formalized into a shorter program. Anyway, my main problem is that I cannot understand your code. If you were using standard facilities, like std::generate/transform/copy, I wouldn't need to start from scratch. I would need to study your documentation quite a lot to figure out what values your code generates. Thinking out loud, this would be easier to me (made up example): vector<int> v; std::generate_n(std::back_inserter(v), 10, assign::v2::fancy_generator(......)); or std::copy_n(assign::v2::fancy_iterator(...), 10, std::back_inseter(v)); It seems like your library can build complex generators/converters of some kind, but it's integration with the containers appears ad-hoc. The above would allow me to only focus on how to configure the generators, and use my old-time knowledge on how to use these with std::containers. - Christian