📄 collection_traits_detail.hpp
字号:
traits_type::value_type value_type; typedef BOOST_STRING_TYPENAME traits_type::iterator iterator; typedef BOOST_STRING_TYPENAME traits_type::const_iterator const_iterator; typedef BOOST_STRING_TYPENAME traits_type::size_type size_type; typedef BOOST_STRING_TYPENAME traits_type::difference_type difference_type; BOOST_STATIC_CONSTANT( size_type, array_size = traits_type::array_size ); };#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION // array lenght resolving /* Lenght of string contained in a static array could be different from the size of the array. For string processing we need the lenght without terminating 0. Therefore, the lenght is calulated for char and wchar_t using char_traits, rather then simply returning the array size. */ template< typename T > struct array_length_selector { template< typename TraitsT > struct array_length { typedef BOOST_STRING_TYPENAME TraitsT::size_type size_type; BOOST_STATIC_CONSTANT( size_type, array_size=TraitsT::array_size ); template< typename A > static size_type length( const A& ) { return array_size; } template< typename A > static bool empty( const A& ) { return array_size==0; } }; }; // specialization for char template<> struct array_length_selector<char> { template< typename TraitsT > struct array_length { typedef BOOST_STRING_TYPENAME TraitsT::size_type size_type; template< typename A > static size_type length( const A& a ) { if ( a==0 ) return 0; else return std::char_traits<char>::length(a); } template< typename A > static bool empty( const A& a ) { return a==0 || a[0]==0; } }; }; // specialization for wchar_t template<> struct array_length_selector<wchar_t> { template< typename TraitsT > struct array_length { typedef BOOST_STRING_TYPENAME TraitsT::size_type size_type; template< typename A > static size_type length( const A& a ) { if ( a==0 ) return 0; else return std::char_traits<wchar_t>::length(a); } template< typename A > static bool empty( const A& a ) { return a==0 || a[0]==0; } }; }; template< typename T > struct array_container_traits { private: // resolve array traits typedef array_traits<T> traits_type; public: typedef BOOST_STRING_TYPENAME traits_type::value_type value_type; typedef BOOST_STRING_TYPENAME traits_type::iterator iterator; typedef BOOST_STRING_TYPENAME traits_type::const_iterator const_iterator; typedef BOOST_STRING_TYPENAME traits_type::size_type size_type; typedef BOOST_STRING_TYPENAME traits_type::difference_type difference_type; typedef BOOST_STRING_TYPENAME ::boost::mpl::if_< ::boost::is_const<T>, const_iterator, iterator >::type result_iterator; private: // resolve array size typedef BOOST_STRING_TYPENAME ::boost::remove_cv<value_type>::type char_type; typedef BOOST_STRING_TYPENAME array_length_selector<char_type>:: BOOST_NESTED_TEMPLATE array_length<traits_type> array_length_type; public: BOOST_STATIC_CONSTANT( size_type, array_size = traits_type::array_size ); // static operations template< typename A > static size_type size( const A& a ) { return array_length_type::length(a); } template< typename A > static bool empty( const A& a ) { return array_length_type::empty(a); } #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING template< typename A > static iterator begin( A& a ) { return a; } template< typename A > static const_iterator begin( const A& a ) { return a; } template< typename A > static iterator end( A& a ) { return a+array_length_type::length(a); } template< typename A > static const_iterator end( const A& a ) { return a+array_length_type::length(a); }#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING template< typename A > static result_iterator begin( A& a ) { return a; } template< typename A > static result_iterator end( A& a ) { return a+array_length_type::length(a); }#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING }; template<typename T> struct array_container_traits_selector { typedef array_container_traits<T> type; };// Pointer container traits --------------------------------------------------------------- template<typename T> struct pointer_container_traits { typedef BOOST_STRING_TYPENAME ::boost::remove_pointer<T>::type value_type; typedef BOOST_STRING_TYPENAME ::boost::remove_cv<value_type>::type char_type; typedef ::std::char_traits<char_type> char_traits; typedef value_type* iterator; typedef const value_type* const_iterator; typedef std::ptrdiff_t difference_type; typedef std::size_t size_type; typedef BOOST_STRING_TYPENAME ::boost::mpl::if_< ::boost::is_const<T>, const_iterator, iterator >::type result_iterator; // static operations template< typename P > static size_type size( const P& p ) { if ( p==0 ) return 0; else return char_traits::length(p); } template< typename P > static bool empty( const P& p ) { return p==0 || p[0]==0; }#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING template< typename P > static iterator begin( P& p ) { return p; } template< typename P > static const_iterator begin( const P& p ) { return p; } template< typename P > static iterator end( P& p ) { if ( p==0 ) return p; else return p+char_traits::length(p); } template< typename P > static const_iterator end( const P& p ) { if ( p==0 ) return p; else return p+char_traits::length(p); }#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING template< typename P > static result_iterator begin( P& p ) { return p; } template< typename P > static result_iterator end( P& p ) { if ( p==0 ) return p; else return p+char_traits::length(p); }#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING }; template<typename T> struct pointer_container_traits_selector { typedef pointer_container_traits<T> type; }; } // namespace detail } // namespace algorithm} // namespace boost#endif // BOOST_STRING_DETAIL_COLLECTION_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -