Chris@16: /*-----------------------------------------------------------------------------+ Chris@16: Copyright (c) 2009-2009: Joachim Faulhaber Chris@16: +------------------------------------------------------------------------------+ Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENCE.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt) Chris@16: +-----------------------------------------------------------------------------*/ Chris@16: #ifndef BOOST_ICL_DETAIL_MAPPED_REFERENCE_HPP_JOFA_091108 Chris@16: #define BOOST_ICL_DETAIL_MAPPED_REFERENCE_HPP_JOFA_091108 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost{namespace icl Chris@16: { Chris@16: Chris@16: template class mapped_reference; Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: struct is_mapped_reference_combinable{ Chris@16: typedef is_mapped_reference_combinable type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = false); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_mapped_reference_combinable > Chris@16: { Chris@16: typedef is_mapped_reference_combinable > type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_mapped_reference_combinable > Chris@16: { Chris@16: typedef is_mapped_reference_combinable > type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: struct is_mapped_reference_or_combinable{ Chris@16: typedef is_mapped_reference_or_combinable type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = is_mapped_reference_combinable::value); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_mapped_reference_or_combinable > Chris@16: { Chris@16: typedef is_mapped_reference_or_combinable > type; Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: class mapped_reference Chris@16: { Chris@16: private: Chris@16: mapped_reference& operator = (const mapped_reference&); Chris@16: public: Chris@16: typedef FirstT first_type; Chris@16: typedef SecondT second_type; Chris@16: typedef mapped_reference type; Chris@16: Chris@16: typedef typename Chris@16: mpl::if_, Chris@16: second_type&, Chris@16: const second_type&>::type second_reference_type; Chris@16: Chris@16: typedef std::pair< first_type, second_type> std_pair_type; Chris@16: typedef std::pair key_std_pair_type; Chris@16: Chris@16: const first_type& first ; Chris@16: second_reference_type second; Chris@16: Chris@16: mapped_reference(const FirstT& fst, second_reference_type snd) : first(fst), second(snd){} Chris@16: Chris@16: template Chris@16: mapped_reference(const mapped_reference& source): Chris@16: first(source.first), second(source.second){} Chris@16: Chris@16: template Chris@16: operator std::pair(){ return std::pair(first, second); } Chris@16: Chris@16: template Chris@16: typename enable_if, bool>::type Chris@16: operator == (const Comparand& right)const Chris@16: { return first == right.first && second == right.second; } Chris@16: Chris@16: template Chris@16: typename enable_if, bool>::type Chris@16: operator != (const Comparand& right)const Chris@16: { return !(*this == right); } Chris@16: Chris@16: template Chris@16: typename enable_if, bool>::type Chris@16: operator < (const Comparand& right)const Chris@16: { Chris@16: return first < right.first Chris@16: ||(!(right.first < first) && second < right.second); Chris@16: } Chris@16: Chris@16: template Chris@16: typename enable_if, bool>::type Chris@16: operator > (const Comparand& right)const Chris@16: { Chris@16: return first > right.first Chris@16: ||(!(right.first > first) && second > right.second); Chris@16: } Chris@16: Chris@16: template Chris@16: typename enable_if, bool>::type Chris@16: operator <= (const Comparand& right)const Chris@16: { Chris@16: return !(*this > right); Chris@16: } Chris@16: Chris@16: template Chris@16: typename enable_if, bool>::type Chris@16: operator >= (const Comparand& right)const Chris@16: { Chris@16: return !(*this < right); Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: inline typename enable_if, bool>::type Chris@16: operator == ( const StdPairT& left, Chris@16: const mapped_reference& right) Chris@16: { Chris@16: return right == left; Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename enable_if, bool>::type Chris@16: operator != ( const StdPairT& left, Chris@16: const mapped_reference& right) Chris@16: { Chris@16: return !(right == left); Chris@16: } Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: inline typename enable_if, bool>::type Chris@16: operator < ( const StdPairT& left, Chris@16: const mapped_reference& right) Chris@16: { Chris@16: return right > left; Chris@16: } Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: inline typename enable_if, bool>::type Chris@16: operator > ( const StdPairT& left, Chris@16: const mapped_reference& right) Chris@16: { Chris@16: return right < left; Chris@16: } Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: inline typename enable_if, bool>::type Chris@16: operator <= ( const StdPairT& left, Chris@16: const mapped_reference& right) Chris@16: { Chris@16: return !(right < left); Chris@16: } Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: inline typename enable_if, bool>::type Chris@16: operator >= ( const StdPairT& left, Chris@16: const mapped_reference& right) Chris@16: { Chris@16: return !(left < right); Chris@16: } Chris@16: Chris@16: //------------------------------------------------------------------------------ Chris@16: //------------------------------------------------------------------------------ Chris@16: template Chris@16: inline mapped_reference make_mapped_reference(const FirstT& left, SecondT& right) Chris@16: { return mapped_reference(left, right); } Chris@16: Chris@16: }} // namespace icl boost Chris@16: Chris@16: #endif // BOOST_ICL_DETAIL_MAPPED_REFERENCE_HPP_JOFA_091108