/*============================================================================== Copyright (c) 2005-2010 Joel de Guzman Copyright (c) 2010 Thomas Heller 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) ==============================================================================*/ #include #include #include #include #include #include namespace phoenix = boost::phoenix; using phoenix::actor; using phoenix::function; using phoenix::arg_names::arg1; struct size_impl { // result_of protocol: template struct result; template struct result { // Note, remove reference here, because Container can be anything typedef typename boost::remove_reference::type container_type; // The result will be size_type typedef typename container_type::size_type type; }; template typename result::type operator()(Container const& container) const { return container.size(); } }; template struct container_actor : actor { typedef actor base_type; typedef container_actor that_type; container_actor( base_type const& base = base_type() ) : base_type( base ) {} typename phoenix::expression::function::type const begin() const { return phoenix::begin(*this); } typename phoenix::expression::function::type const end() const { return phoenix::end(*this); } typename phoenix::expression::function::type const size() const { function const f = size_impl(); return f(*this); } typename phoenix::expression::function::type const max_size() const { return phoenix::max_size(*this); } typename phoenix::expression::function::type const empty() const { return phoenix::empty(*this); } template typename phoenix::expression::function::type const swap(actor const& expr) const { return phoenix::swap(*this, expr); } }; template container_actor const container( actor const& expr ) { return expr; } int main() { container_actor::type> const con1; std::vector v; v.push_back(0); v.push_back(1); v.push_back(2); v.push_back(3); std::cout << (container(arg1).size())(v) << " == " << v.size() << "\n"; std::cout << (con1.size())(v) << " == " << v.size() << "\n"; }