Chris@101: /* Copyright 2003-2013 Joaquin M Lopez Munoz. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Chris@16: * See http://www.boost.org/libs/multi_index for library home page. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_MULTI_INDEX_GLOBAL_FUN_HPP Chris@16: #define BOOST_MULTI_INDEX_GLOBAL_FUN_HPP Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include /* keep it first to prevent nasty warns in MSVC */ Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_NO_SFINAE) Chris@16: #include Chris@16: #endif Chris@16: Chris@16: namespace boost{ Chris@16: Chris@16: template class reference_wrapper; /* fwd decl. */ Chris@16: Chris@16: namespace multi_index{ Chris@16: Chris@16: namespace detail{ Chris@16: Chris@16: /* global_fun is a read-only key extractor from Value based on a given global Chris@16: * (or static member) function with signature: Chris@16: * Chris@16: * Type f([const] Value [&]); Chris@16: * Chris@16: * Additionally, global_fun and const_global_fun are overloaded to support Chris@16: * referece_wrappers of Value and "chained pointers" to Value's. By chained Chris@16: * pointer to T we mean a type P such that, given a p of Type P Chris@16: * *...n...*x is convertible to T&, for some n>=1. Chris@16: * Examples of chained pointers are raw and smart pointers, iterators and Chris@16: * arbitrary combinations of these (vg. T** or auto_ptr.) Chris@16: */ Chris@16: Chris@16: template Chris@16: struct const_ref_global_fun_base Chris@16: { Chris@16: typedef typename remove_reference::type result_type; Chris@16: Chris@16: template Chris@16: Chris@16: #if !defined(BOOST_NO_SFINAE) Chris@16: typename disable_if< Chris@16: is_convertible,Type>::type Chris@16: #else Chris@16: Type Chris@16: #endif Chris@16: Chris@16: operator()(const ChainedPtr& x)const Chris@16: { Chris@16: return operator()(*x); Chris@16: } Chris@16: Chris@16: Type operator()(Value x)const Chris@16: { Chris@16: return PtrToFunction(x); Chris@16: } Chris@16: Chris@16: Type operator()( Chris@16: const reference_wrapper< Chris@16: typename remove_reference::type>& x)const Chris@16: { Chris@16: return operator()(x.get()); Chris@16: } Chris@16: Chris@16: Type operator()( Chris@16: const reference_wrapper< Chris@16: typename remove_const< Chris@101: typename remove_reference::type>::type>& x)const Chris@16: { Chris@16: return operator()(x.get()); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct non_const_ref_global_fun_base Chris@16: { Chris@16: typedef typename remove_reference::type result_type; Chris@16: Chris@16: template Chris@16: Chris@16: #if !defined(BOOST_NO_SFINAE) Chris@16: typename disable_if< Chris@16: is_convertible,Type>::type Chris@16: #else Chris@16: Type Chris@16: #endif Chris@16: Chris@16: operator()(const ChainedPtr& x)const Chris@16: { Chris@16: return operator()(*x); Chris@16: } Chris@16: Chris@16: Type operator()(Value x)const Chris@16: { Chris@16: return PtrToFunction(x); Chris@16: } Chris@16: Chris@16: Type operator()( Chris@16: const reference_wrapper< Chris@16: typename remove_reference::type>& x)const Chris@16: { Chris@16: return operator()(x.get()); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct non_ref_global_fun_base Chris@16: { Chris@16: typedef typename remove_reference::type result_type; Chris@16: Chris@16: template Chris@16: Chris@16: #if !defined(BOOST_NO_SFINAE) Chris@16: typename disable_if< Chris@16: is_convertible,Type>::type Chris@16: #else Chris@16: Type Chris@16: #endif Chris@16: Chris@16: operator()(const ChainedPtr& x)const Chris@16: { Chris@16: return operator()(*x); Chris@16: } Chris@16: Chris@16: Type operator()(const Value& x)const Chris@16: { Chris@16: return PtrToFunction(x); Chris@16: } Chris@16: Chris@16: Type operator()(const reference_wrapper& x)const Chris@16: { Chris@16: return operator()(x.get()); Chris@16: } Chris@16: Chris@16: Type operator()( Chris@101: const reference_wrapper::type>& x)const Chris@16: { Chris@16: return operator()(x.get()); Chris@16: } Chris@16: }; Chris@16: Chris@16: } /* namespace multi_index::detail */ Chris@16: Chris@16: template Chris@16: struct global_fun: Chris@16: mpl::if_c< Chris@16: is_reference::value, Chris@16: typename mpl::if_c< Chris@16: is_const::type>::value, Chris@16: detail::const_ref_global_fun_base, Chris@16: detail::non_const_ref_global_fun_base Chris@16: >::type, Chris@16: detail::non_ref_global_fun_base Chris@16: >::type Chris@16: { Chris@16: }; Chris@16: Chris@16: } /* namespace multi_index */ Chris@16: Chris@16: } /* namespace boost */ Chris@16: Chris@16: #endif