//Purpose: // Test if the code posted here: /* http://article.gmane.org/gmane.comp.lib.boost.devel/251897 */ // With headers: /* From: Louis Dionne Newsgroups: gmane.comp.lib.boost.devel Subject: Efficient tuple implementation Date: Sat, 7 Jun 2014 02:18:47 +0000 (UTC) Lines: 89 Approved: news@gmane.org Message-ID: */ // can be extended to have "tagged" tuples. //Result: // gcc4.8.1:fails compile // clang3.4:passes compile. // enum tag_enum { op_or , op_and }; template struct tag_t { tag_enum operator()()const { return Tag; } }; auto tuple_tagged = [](auto tag_v, auto ...xs) { return [=](auto access) { return access(tag_v, xs...); }; }; template struct operation_tagged ; template<> struct operation_tagged > { bool operation() { return false; } template bool operation(Head head, Tails... tails) { if(head) return head; else return operation(tails...); } template bool operator()(Xs... xs) { return operation(xs...); } }; template<> struct operation_tagged > { bool operation() { return true; } template bool operation(Head head, Tails... tails) { if(!head) return head; else return operation(tails...); } template bool operator()(Xs... xs) { return operation(xs...); } }; auto operation_apply = [](auto xs) { return xs ( [](auto tag_v, auto... operands) { operation_tagged operation_v; return operation_v(operands...); } ); }; #include int main() { auto or_all_true_input=tuple_tagged(tag_t(),true,true,true); auto or_all_true_output=operation_apply(or_all_true_input); std::cout<<"or_all_true_output="<(),true,false,true); auto or_one_false_output=operation_apply(or_one_false_input); std::cout<<"or_one_false_output="<(),false,false,false); auto or_all_false_output=operation_apply(or_all_false_input); std::cout<<"or_all_false_output="<(),true,true,true); auto and_all_true_output=operation_apply(and_all_true_input); std::cout<<"and_all_true_output="<