/* IterableClassification(Test) - detecting iterability of a generic type Copyright (C) Lumiera.org 2010, Hermann Vosseler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************/ #include "lib/test/run.hpp" #include "proc/mobject/session/scope-query.hpp" #include "proc/mobject/session/effect.hpp" #include "lib/meta/duck-detector.hpp" #include "lib/util-foreach.hpp" #include "lib/itertools.hpp" #include "lib/lumitime.hpp" /////////////////////////////////////////////////////////////TODO draft #include /////////////////////////////////////////////////////////////TODO draft #include #include #include #include #include #include namespace lib { /////////////////////////////////////////////////////////////TODO draft template class can_STL_ForEach { struct is_iterable { META_DETECT_NESTED(iterator); META_DETECT_FUNCTION(typename X::iterator, begin,(void)); META_DETECT_FUNCTION(typename X::iterator, end ,(void)); enum { value = HasNested_iterator::value && HasFunSig_begin::value && HasFunSig_end::value }; }; struct is_const_iterable { META_DETECT_NESTED(const_iterator); META_DETECT_FUNCTION(typename X::const_iterator, begin,(void) const); META_DETECT_FUNCTION(typename X::const_iterator, end ,(void) const); enum { value = HasNested_const_iterator::value && HasFunSig_begin::value && HasFunSig_end::value }; }; public: enum { value = is_iterable::value || is_const_iterable::value }; }; template class can_IterForEach { META_DETECT_NESTED(value_type); META_DETECT_OPERATOR_DEREF(); META_DETECT_OPERATOR_INC(); public: enum{ value = boost::is_convertible::value && HasNested_value_type::value && HasOperator_deref::value && HasOperator_inc::value }; }; /////////////////////////////////////////////////////////////TODO draft namespace meta{ namespace test{ using lumiera::Time; using mobject::session::Effect; using mobject::session::ScopeQuery; using std::cout; using std::endl; namespace { // a custom test container.... struct TestSource { vector data_; TestSource(uint num); typedef vector::iterator sourceIter; typedef RangeIter iterator; iterator begin() ; iterator end() ; // note: a bare type definition is sufficient here.... }; }//(End) test containers #define SHOW_CHECK(_EXPR_) cout << STRINGIFY(_EXPR_) << "\t : " << (_EXPR_::value? "Yes":"No") << endl; /*********************************************************************************** * @test verify the (static) classification/detection of iterables. * Currently (1/10) we're able to detect the following * - a STL like container with \c begin() and \c end() * - a Lumiera Forward Iterator * This test just retrieves the results of a compile time execution * of the type detection; thus we just define types and then access * the generated meta function value. */ class IterableClassification_test : public Test { void run (Arg) { // define a bunch of STL containers typedef std::vector LongVector; typedef std::multiset