Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / boost / range / detail / begin.hpp
1 // Boost.Range library
2 //
3 //  Copyright Thorsten Ottosen 2003-2004. Use, modification and
4 //  distribution is subject to the Boost Software License, Version
5 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // For more information, see http://www.boost.org/libs/range/
9 //
10
11 #ifndef BOOST_RANGE_DETAIL_BEGIN_HPP
12 #define BOOST_RANGE_DETAIL_BEGIN_HPP
13
14 #include <boost/config.hpp> // BOOST_MSVC
15 #include <boost/detail/workaround.hpp>
16 #include <boost/range/result_iterator.hpp>
17 #include <boost/range/detail/common.hpp>
18 #if BOOST_WORKAROUND(BOOST_MSVC, < 1310)
19 # include <boost/range/value_type.hpp>
20 #endif
21
22 namespace boost 
23 {
24     
25     namespace range_detail
26     {
27         template< typename T >
28         struct range_begin;
29
30         //////////////////////////////////////////////////////////////////////
31         // default
32         //////////////////////////////////////////////////////////////////////
33         
34         template<>
35         struct range_begin<std_container_>
36         {
37             template< typename C >
38             static BOOST_RANGE_DEDUCED_TYPENAME range_result_iterator<C>::type fun( C& c )
39             {
40                 return c.begin();
41             };
42         };
43                     
44         //////////////////////////////////////////////////////////////////////
45         // pair
46         //////////////////////////////////////////////////////////////////////
47         
48         template<>
49         struct range_begin<std_pair_>
50         {
51             template< typename P >
52             static BOOST_RANGE_DEDUCED_TYPENAME range_result_iterator<P>::type fun( const P& p )
53             {
54                 return p.first;
55             }
56         };
57  
58         //////////////////////////////////////////////////////////////////////
59         // array
60         //////////////////////////////////////////////////////////////////////
61         
62         template<>
63         struct range_begin<array_>
64         {
65         #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
66             template< typename T, std::size_t sz >
67             static T* fun( T BOOST_RANGE_ARRAY_REF()[sz] )
68             {
69                 return boost_range_array;
70             }
71         #else
72             template<typename T>
73             static BOOST_RANGE_DEDUCED_TYPENAME range_value<T>::type* fun(T& t)
74             {
75                 return t;
76             }
77         #endif
78         };
79
80         //////////////////////////////////////////////////////////////////////
81         // string
82         //////////////////////////////////////////////////////////////////////
83      
84         template<>
85         struct range_begin<char_ptr_>
86         {
87             static char* fun( char* s )
88             {
89                 return s;
90             }
91         };
92
93         template<>
94         struct range_begin<const_char_ptr_>
95         {
96             static const char* fun( const char* s )
97             {
98                 return s;
99             }
100         };
101         
102         template<>
103         struct range_begin<wchar_t_ptr_>
104         {
105             
106             static wchar_t* fun( wchar_t* s )
107             {
108                 return s;
109             }
110         };
111
112         template<>
113         struct range_begin<const_wchar_t_ptr_>
114         {
115             static const wchar_t* fun( const wchar_t* s )
116             {
117                 return s;
118             }
119         };
120
121     } // namespace 'range_detail'
122     
123     template< typename C >
124     inline BOOST_RANGE_DEDUCED_TYPENAME range_result_iterator<C>::type 
125     begin( C& c )
126     {
127         return range_detail::range_begin< BOOST_RANGE_DEDUCED_TYPENAME range_detail::range<C>::type >::fun( c );
128     }
129     
130 } // namespace 'boost'
131
132
133 #endif