// (C) Copyright 2008-2009 SDML (www.sdml.info) // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include using namespace origin; using std::cout; // TODO: We need these adaptors for standard containers. We could consider // moving them into the Origin.Core. namespace std { template inline bool empty(C const& c) { return c.empty(); } template inline typename C::size_type size(C const& c) { return c.size(); } template inline typename C::iterator begin(C& c) { return c.begin(); } template inline typename C::iterator end(C& c) { return c.end(); } template inline typename C::const_iterator begin(C const& c) { return c.begin(); } template inline typename C::const_iterator end(C const& c) { return c.end(); } } // ==== Fun with overloads ==== template < typename C, typename = typename concept_enabled>::type> void sort(C& c) { cout << "sort(C&)\n"; } template < typename C, typename Comp, typename = typename concept_enabled< Container, StrictWeakOrder::value_type> >::type> void sort(C& c, Comp comp) { cout << "sort(C&, Comp)\n"; } template < typename Iter, typename = typename concept_enabled>::type> void sort(Iter f, Iter l) { cout << "sort(Iter, Iter)\n"; } template < typename Iter, typename Comp, typename = typename concept_enabled< RandomAccessIterator, StrictWeakOrder::value_type> >::type> void sort(Iter f, Iter l, Comp comp) { cout << "sort(Iter, Iter, Comp)\n"; } int main() { { typedef std::vector C; BOOST_ASSERT(( concept_check>::value )); BOOST_ASSERT(( concept_check>::value )); typedef iterator_range R; BOOST_ASSERT(( concept_check>::value )); BOOST_ASSERT(( !concept_check>::value )); } { typedef std::vector C; typedef C::iterator Iter; C c = { 3, 2, 1 }; sort(c); sort(c, std::less()); Iter f = c.begin(), l = c.end(); sort(f, l); sort(f, l, std::greater()); } return 0; }