Esempio n. 1
0
    // bind( Compare(), bind(select1st<elem_type>(), _1),  bind(identity<Key>(), _2) )
    struct p1 : public std::binary_function<elem_type,Key,bool>
    {
        bool operator()( elem_type const& x, Key const& y ) const { return Compare()( x.first, y ); }
    };

    // bind( Compare(), bind(select1st<elem_type>(), _1), bind(select1st<elem_type>(), _2) )
    struct p2 : public std::binary_function<elem_type,elem_type,bool>
    {
        bool operator()( elem_type const& x, elem_type const& y ) const { return Compare()( x.first, y.first ); }
    };

public:
    // Constructors
    CONTRUCTORS( BOOST_PP_ADD( MAX_MAP_SIZE, 1 ) )

    // key -> value access
    value_ref_type  operator[]( key_param_type key ) const
    {
#if BOOST_WORKAROUND(__SUNPRO_CC,BOOST_TESTED_AT(0x530))
        iterator it = std::lower_bound( m_map.begin(), m_map.end(), key, p1() );
#else
        iterator it = boost::detail::lower_bound( m_map.begin(), m_map.end(), key, p1() );
#endif
        return (it == m_map.end() || Compare()( key, it->first ) ) ? m_invalid_value : it->second;
    }

private:
    // Implementation
    void            init()                                                  { std::sort( m_map.begin(), m_map.end(), p2() ); }
Esempio n. 2
0
 *    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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

/*
 * Using boost preprocessor to reduce the burden of writing templates
 * 06/07/2012   Wei Song
 *
 */

#define n BOOST_PP_ITERATION()
template <typename R BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename T)>
void def(std::string const &name, R (*f)(BOOST_PP_ENUM_PARAMS(n,T)),
         policies const &p = policies())
{
    add_function(name,
                 boost::shared_ptr<details::callback_base>(
                     new details::BOOST_PP_CAT(callback,n)<R BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,T)>(f)), p);
}

// using the last arg as a client data, but must be pointer
template <typename R, BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n,1), typename T)>
void def(std::string const &name, R (*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n,1),T) *), BOOST_PP_CAT(T,n) *cData,
         policies const &p = policies()) {
    add_function(name,
                 boost::shared_ptr<details::callback_base>
                 (new details::BOOST_PP_CAT(BOOST_PP_CAT(callback,BOOST_PP_ADD(n,1)),_cd)<R, BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n,1),T)>(f)), p, (ClientData)(cData));
}
#undef n
// Copyright (C) 2004 Arkadiy Vertleyb
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)

#include <boost/typeof/encode_decode_params.hpp>

// member functions

template<class V, class T, class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)> 
struct encode_type_impl<V, R(T::*)(BOOST_PP_ENUM_PARAMS(n, P)) BOOST_TYPEOF_qualifier>
{
    typedef R BOOST_PP_CAT(P, n);
    typedef T BOOST_PP_CAT(P, BOOST_PP_INC(n));
    typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_ADD(n, 2), BOOST_TYPEOF_id + n) type;
};

template<class Iter>
struct decode_type_impl<boost::mpl::size_t<BOOST_TYPEOF_id + n>, Iter>
{
    typedef Iter iter0;
    BOOST_TYPEOF_DECODE_PARAMS(BOOST_PP_ADD(n, 2))
    template<class T> struct workaround{
        typedef BOOST_PP_CAT(p, n)(T::*type)(BOOST_PP_ENUM_PARAMS(n, p)) BOOST_TYPEOF_qualifier;
    };
    typedef typename workaround<BOOST_PP_CAT(p, BOOST_PP_INC(n))>::type type;
    typedef BOOST_PP_CAT(iter, BOOST_PP_ADD(n, 2)) iter;
};

// undef parameters

#undef BOOST_TYPEOF_id