map_view_base.hpp
字号:
template< class CompatibleKey > const data_type_ & at(const CompatibleKey& k) const { typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support:: const_iterator_type_by<Tag,BimapType>::type const_iterator; const_iterator iter = derived().find(k); if( iter == derived().end() ) { ::boost::throw_exception( std::out_of_range("bimap<>: invalid key") ); } return iter->second; } template< class CompatibleKey > data_type_ & operator[](const CompatibleKey& k) { typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support:: iterator_type_by<Tag,BimapType>::type iterator; typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support:: value_type_by<Tag,BimapType>::type value_type; iterator iter = derived().find(k); if( iter == derived().end() ) { iter = derived().insert( value_type(k,data_type_()) ).first; } return iter->second; } protected: typedef mutable_data_unique_map_view_access mutable_data_unique_map_view_access_; private: // Curiously Recurring Template interface. Derived& derived() { return *static_cast<Derived*>(this); } Derived const& derived() const { return *static_cast<Derived const*>(this); }};template< class Derived, class Tag, class BimapType>class non_mutable_data_unique_map_view_access{ typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support:: data_type_by<Tag,BimapType>::type data_type_; public: template< class CompatibleKey > const data_type_ & at(const CompatibleKey& k) const { typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support:: const_iterator_type_by<Tag,BimapType>::type const_iterator; const_iterator iter = derived().find(k); if( iter == derived().end() ) { ::boost::throw_exception( std::out_of_range("bimap<>: invalid key") ); } return iter->second; } template< class CompatibleKey > data_type_ & operator[](const CompatibleKey& k) { BOOST_BIMAP_STATIC_ERROR( OPERATOR_BRACKET_IS_NOT_SUPPORTED, (Derived)); } protected: typedef non_mutable_data_unique_map_view_access non_mutable_data_unique_map_view_access_; private: // Curiously Recurring Template interface. Derived& derived() { return *static_cast<Derived*>(this); } Derived const& derived() const { return *static_cast<Derived const*>(this); }};template< class Derived, class Tag, class BimapType>struct unique_map_view_access{ private: typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support:: value_type_by<Tag,BimapType>::type value_type; public: typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_ < typename ::boost::is_const< BOOST_DEDUCED_TYPENAME value_type::second_type >::type, non_mutable_data_unique_map_view_access<Derived,Tag,BimapType>, mutable_data_unique_map_view_access<Derived,Tag,BimapType> >::type type;};// Map views specialize the following structs to provide to the bimap class// the extra side typedefs (i.e. left_local_iterator for unordered_maps, // right_range_type for maps)template< class MapView >struct left_map_view_extra_typedefs {};template< class MapView >struct right_map_view_extra_typedefs {};} // namespace detail// This function is already part of Boost.Lambda.// They may be moved to Boost.Utility.template <class T> inline const T& make_const(const T& t) { return t; }} // namespace bimaps} // namespace boost// The following macros avoids code duplication in map views// Maybe this can be changed in the future using a scheme similar to// the one used with map_view_base./*===========================================================================*/#define BOOST_BIMAP_MAP_VIEW_RANGE_IMPLEMENTATION(BASE) \ \typedef std::pair< \ BOOST_DEDUCED_TYPENAME base_::iterator, \ BOOST_DEDUCED_TYPENAME base_::iterator> range_type; \ \typedef std::pair< \ BOOST_DEDUCED_TYPENAME base_::const_iterator, \ BOOST_DEDUCED_TYPENAME base_::const_iterator> const_range_type; \ \ \template< class LowerBounder, class UpperBounder> \range_type range(LowerBounder lower,UpperBounder upper) \{ \ std::pair< \ \ BOOST_DEDUCED_TYPENAME BASE::base_type::iterator, \ BOOST_DEDUCED_TYPENAME BASE::base_type::iterator \ \ > r( this->base().range(lower,upper) ); \ \ return range_type( \ this->template functor< \ BOOST_DEDUCED_TYPENAME BASE::iterator_from_base \ >() ( r.first ), \ this->template functor< \ BOOST_DEDUCED_TYPENAME BASE::iterator_from_base \ >() ( r.second ) \ ); \} \ \template< class LowerBounder, class UpperBounder> \const_range_type range(LowerBounder lower,UpperBounder upper) const \{ \ std::pair< \ \ BOOST_DEDUCED_TYPENAME BASE::base_type::const_iterator, \ BOOST_DEDUCED_TYPENAME BASE::base_type::const_iterator \ \ > r( this->base().range(lower,upper) ); \ \ return const_range_type( \ this->template functor< \ BOOST_DEDUCED_TYPENAME BASE::iterator_from_base \ >() ( r.first ), \ this->template functor< \ BOOST_DEDUCED_TYPENAME BASE::iterator_from_base \ >() ( r.second ) \ ); \}/*===========================================================================*//*===========================================================================*/#define BOOST_BIMAP_VIEW_ASSIGN_IMPLEMENTATION(BASE) \ \template< class InputIterator > \void assign(InputIterator first,InputIterator last) \{ \ this->clear(); \ this->insert(this->end(),first,last); \} \ \void assign(BOOST_DEDUCED_TYPENAME BASE::size_type n, \ const BOOST_DEDUCED_TYPENAME BASE::value_type& v) \{ \ this->clear(); \ for(BOOST_DEDUCED_TYPENAME BASE::size_type i = 0 ; i < n ; ++n) \ { \ this->push_back(v); \ } \}/*===========================================================================*//*===========================================================================*/#define BOOST_BIMAP_VIEW_FRONT_BACK_IMPLEMENTATION(BASE) \ \BOOST_DEDUCED_TYPENAME BASE::reference front() \{ \ return this->template functor< \ BOOST_DEDUCED_TYPENAME base_::value_from_base>() \ ( \ const_cast \ < \ BOOST_DEDUCED_TYPENAME BASE::base_type::value_type & \ \ > ( this->base().front() ) \ ); \} \ \BOOST_DEDUCED_TYPENAME BASE::reference back() \{ \ return this->template functor< \ BOOST_DEDUCED_TYPENAME base_::value_from_base>() \ ( \ const_cast \ < \ BOOST_DEDUCED_TYPENAME BASE::base_type::value_type & \ \ >( this->base().back() ) \ ); \} \ \BOOST_DEDUCED_TYPENAME BASE::const_reference front() const \{ \ return this->template functor< \ BOOST_DEDUCED_TYPENAME BASE::value_from_base>() \ ( \ this->base().front() \ ); \} \ \BOOST_DEDUCED_TYPENAME BASE::const_reference back() const \{ \ return this->template functor< \ BOOST_DEDUCED_TYPENAME BASE::value_from_base>() \ ( \ this->base().back() \ ); \}/*===========================================================================*/#endif // BOOST_BIMAP_DETAIL_MAP_VIEW_BASE_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -