1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2010-2010: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4    Distributed under the Boost Software License, Version 1.0.
5       (See accompanying file LICENCE.txt or copy at
6            http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_CONCEPT_CONTAINER_HPP_JOFA_100923
9 #define BOOST_ICL_CONCEPT_CONTAINER_HPP_JOFA_100923
10 
11 #include <boost/utility/enable_if.hpp>
12 #include <boost/mpl/and.hpp>
13 #include <boost/mpl/not.hpp>
14 #include <boost/icl/type_traits/is_container.hpp>
15 #include <boost/icl/type_traits/is_icl_container.hpp>
16 
17 namespace boost{ namespace icl
18 {
19 
20 //==============================================================================
21 //= Emptieness
22 //==============================================================================
23 
24 /** Tests if the container is empty.
25     Complexity: constant. */
26 template<class Type>
27 typename enable_if<is_container<Type>, bool>::type
is_empty(const Type & object)28 is_empty(const Type& object)
29 {
30     return object.begin()==object.end();
31 }
32 
33 
34 /** All content of the container is dropped.
35     Complexity: linear. */
36 template<class Type>
37 typename enable_if<is_container<Type>, void>::type
clear(Type & object)38 clear(Type& object)
39 {
40     object.erase(object.begin(), object.end());
41 }
42 
43 //==============================================================================
44 //= Size
45 //==============================================================================
46 
47 template<class Type>
48 typename enable_if<mpl::and_< is_container<Type>
49                             , mpl::not_<is_icl_container<Type> > >
50                   , std::size_t>::type
iterative_size(const Type & object)51 iterative_size(const Type& object)
52 {
53     return object.size();
54 }
55 
56 //==============================================================================
57 //= Swap
58 //==============================================================================
59 
60 template<class Type>
61 typename enable_if<is_container<Type>, void>::type
swap(Type & left,Type & right)62 swap(Type& left, Type& right)
63 {
64     left.swap(right);
65 }
66 
67 //==============================================================================
68 //= Iteration
69 //==============================================================================
70 
71 template<class Type>
72 typename enable_if<is_container<Type>, typename Type::iterator>::type
cyclic_prior(Type & object,typename Type::iterator it_)73 cyclic_prior(Type& object, typename Type::iterator it_)
74 { return it_ == object.begin() ? object.end() : --it_; }
75 
76 template<class Type>
77 typename enable_if<is_container<Type>, typename Type::const_iterator>::type
cyclic_prior(const Type & object,typename Type::const_iterator it_)78 cyclic_prior(const Type& object, typename Type::const_iterator it_)
79 { return it_ == object.begin() ? object.end() : --it_; }
80 
81 
82 
83 }} // namespace boost icl
84 
85 #endif
86 
87 
88