1 /*!
2  * \file   include/TFEL/FSAlgorithm/equal.hxx
3  * \brief  this file implements the equal class.
4  * \author Thomas Helfer
5  * \date   30 Jun 2006
6  * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7  * reserved.
8  * This project is publicly released under either the GNU GPL Licence
9  * or the CECILL-A licence. A copy of thoses licences are delivered
10  * with the sources of TFEL. CEA or EDF may also distribute this
11  * project under specific licensing conditions.
12  */
13 
14 #ifndef LIB_TFEL_EQUAL_HXX
15 #define LIB_TFEL_EQUAL_HXX
16 
17 #include"TFEL/Config/TFELConfig.hxx"
18 
19 namespace tfel{
20 
21   namespace fsalgo{
22 
23     /*!
24      * \class equal
25      * \brief Equal returns true if the two ranges [first1, first1+N) and [first2, first2 + N) are identical when compared element-by-element, and otherwise returns false
26      * \param N number of element to be compared.
27      *
28      * This documentation is mostly inspired from:
29      * http://www.sgi.com/tech/stl/equal.html
30      *
31      * \see transform.cxx for some elementary tests.
32      *
33      * \author Thomas Helfer
34      * \date   30 Jun 2006
35      */
36     template<unsigned int N>
37     struct equal
38     {
39 
40       /*!
41        * \param  InputIterator  iterator for the first  sequence
42        * \param  InputIterator2 iterator for the second sequence
43        *
44        * \return true if all elements are equal
45        *
46        * \pre
47        * - InputIterator1 is a model of Input Iterator.
48        * - InputIterator2 is a model of Input Iterator.
49        * - InputIterator1's value type is a model of Equality Comparable.
50        * - InputIterator2's value type is a model of Equality Comparable.
51        * - InputIterator1's value type can be compared for equality with InputIterator2's value type.
52 
53        */
54       template<typename InputIterator,typename InputIterator2>
55       static TFEL_FSALGORITHM_INLINE
exetfel::fsalgo::equal56       bool exe(InputIterator p, InputIterator2 q)
57       {
58 	return (*p == *q)&&(equal<N-1>::exe(++p,++q));
59       }
60 
61       /*!
62        * \param  InputIterator  iterator for the first  sequence
63        * \param  InputIterator2 iterator for the second sequence
64        * \param  BinaryPredicate predicate used to make comparison
65        * \return true if all elements are one-by-one equal given the predicate used.
66        *
67        * \pre
68        * -  InputIterator1 is a model of Input Iterator.
69        * -  InputIterator2 is a model of Input Iterator.
70        * -  BinaryPredicate is a model of Binary Predicate.
71        * -  InputIterator1's value type is convertible to BinaryPredicate's first argument type.
72        * -  InputIterator2's value type is convertible to BinaryPredicate's second argument type.
73        */
74       template<typename InputIterator,typename InputIterator2,
75 	       typename BinaryPredicate>
76       static TFEL_FSALGORITHM_INLINE
exetfel::fsalgo::equal77       bool exe(InputIterator p, InputIterator2 q, BinaryPredicate binary_pred)
78       {
79 	return (binary_pred(*p,*q))&&(equal<N-1>::exe(++p,++q,binary_pred));
80       }
81 
82     };
83 
84     /*!
85      * \brief partial specialisation of struct equal to end recursion.
86      *
87      * \author Thomas Helfer
88      * \date   30 Jun 2006
89      */
90     template<>
91     struct equal<0u>
92     {
93 
94       /*!
95        * \return True
96        */
97       template<typename InputIterator,typename InputIterator2>
98       static TFEL_FSALGORITHM_INLINE
exetfel::fsalgo::equal99       bool exe(InputIterator, InputIterator2)
100       {
101 	return true;
102       }
103 
104       /*!
105        * \return True
106        */
107       template<typename InputIterator,typename InputIterator2,
108 	       typename BinaryPredicate>
109       static TFEL_FSALGORITHM_INLINE
exetfel::fsalgo::equal110       bool exe(InputIterator, InputIterator2, BinaryPredicate)
111       {
112 	return true;
113       }
114     };
115 
116   } // end of namespace fsalgo
117 
118 } // end of namespace tfel
119 
120 #endif /* LIB_TFEL_EQUAL_HXX */
121 
122