/*============================================================================= Copyright (c) 2001-2007 Joel de Guzman Copyright (c) 2001-2008 Hartmut Kaiser http://spirit.sourceforge.net/ Distributed under 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) =============================================================================*/ #if !defined(BOOST_SPIRIT_CONTAINER_FEB_06_2007_1001AM) #define BOOST_SPIRIT_CONTAINER_FEB_06_2007_1001AM #include #include // for boost::detail::iterator_traits namespace boost { namespace spirit { namespace container { /////////////////////////////////////////////////////////////////////////// // This file contains some container utils for stl containers. The // utilities provided also accept spirit's unused_type; all no-ops. // Compiler optimization will easily strip these away. /////////////////////////////////////////////////////////////////////////// namespace result_of { template struct value { typedef typename Container::value_type type; }; template <> struct value { typedef unused_type type; }; template <> struct value { typedef unused_type type; }; template struct iterator { typedef typename Container::iterator type; }; template struct iterator { typedef typename Container::const_iterator type; }; template <> struct iterator { typedef unused_type const* type; }; template <> struct iterator { typedef unused_type const* type; }; } /////////////////////////////////////////////////////////////////////////// template inline void push_back(Container& c, T const& val) { c.push_back(val); } template inline void push_back(Container&, unused_type) { } template inline void push_back(unused_type, T const&) { } inline void push_back(unused_type, unused_type) { } /////////////////////////////////////////////////////////////////////////// template inline typename result_of::iterator::type begin(Container& c) { return c.begin(); } template inline typename result_of::iterator::type begin(Container const& c) { return c.begin(); } inline unused_type const* begin(unused_type) { return &unused; } template inline typename result_of::iterator::type end(Container& c) { return c.end(); } template inline typename result_of::iterator::type end(Container const& c) { return c.end(); } inline unused_type const* end(unused_type) { return &unused; } /////////////////////////////////////////////////////////////////////////// template inline typename boost::detail::iterator_traits::value_type deref(Iterator& it) { return *it; } inline unused_type deref(unused_type*) { return unused; } inline unused_type deref(unused_type const*) { return unused; } /////////////////////////////////////////////////////////////////////////// template inline Iterator next(Iterator& it) { return ++it; } inline unused_type next(unused_type*) { return &unused; } inline unused_type next(unused_type const*) { return &unused; } /////////////////////////////////////////////////////////////////////////// template inline bool compare(Iterator const& it1, Iterator const& it2) { return it1 == it2; } inline bool compare(unused_type*, unused_type*) { return true; } }}} #endif