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_IDENTITY_HPP Chris@16: #define BOOST_MULTI_INDEX_IDENTITY_HPP Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: 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: /* identity is a do-nothing key extractor that returns the [const] Type& Chris@16: * object passed. Chris@16: * Additionally, identity is overloaded to support referece_wrappers Chris@16: * of Type and "chained pointers" to Type's. By chained pointer to Type we Chris@16: * mean a type P such that, given a p of type P Chris@16: * *...n...*x is convertible to Type&, for some n>=1. Chris@16: * Examples of chained pointers are raw and smart pointers, iterators and Chris@16: * arbitrary combinations of these (vg. Type** or auto_ptr.) Chris@16: */ Chris@16: Chris@16: template Chris@16: struct const_identity_base Chris@16: { Chris@16: typedef Type result_type; Chris@16: Chris@16: template Chris@16: Chris@16: #if !defined(BOOST_NO_SFINAE) Chris@16: typename disable_if,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()(Type& x)const Chris@16: { Chris@16: return x; Chris@16: } Chris@16: Chris@16: Type& operator()(const reference_wrapper& x)const Chris@16: { Chris@16: return x.get(); Chris@16: } Chris@16: Chris@16: Type& operator()( Chris@101: const reference_wrapper::type>& x)const Chris@16: { Chris@16: return x.get(); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct non_const_identity_base Chris@16: { Chris@16: typedef Type result_type; Chris@16: Chris@16: /* templatized for pointer-like types */ 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@101: const Type& operator()(const Type& x)const Chris@16: { Chris@16: return x; Chris@16: } Chris@16: Chris@16: Type& operator()(Type& x)const Chris@16: { Chris@16: return x; Chris@16: } Chris@16: Chris@101: const Type& operator()(const reference_wrapper& x)const Chris@16: { Chris@16: return x.get(); Chris@16: } Chris@16: Chris@16: Type& operator()(const reference_wrapper& x)const Chris@16: { Chris@16: return x.get(); Chris@16: } Chris@16: }; Chris@16: Chris@16: } /* namespace multi_index::detail */ Chris@16: Chris@16: template Chris@16: struct identity: Chris@16: mpl::if_c< Chris@16: is_const::value, Chris@16: detail::const_identity_base,detail::non_const_identity_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