tinympl  0.2
mini MPL library for C++11
lexicographical_compare.hpp
1 // Copyright (C) 2013, Ennio Barbaro.
2 //
3 // Use, modification, and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://sbabbi.github.io/tinympl for documentation.
8 //
9 // You are welcome to contact the author at:
10 // enniobarbaro@gmail.com
11 //
12 
13 #ifndef TINYMPL_LEXICOGRAPHICAL_COMPARE_HPP
14 #define TINYMPL_LEXICOGRAPHICAL_COMPARE_HPP
15 
16 #include <tinympl/as_sequence.hpp>
17 #include <tinympl/sequence.hpp>
18 #include <tinympl/less.hpp>
19 #include <type_traits>
20 
21 namespace tinympl {
22 
34 template<class SequenceA,
35  class SequenceB,
36  template<class ...> class Comparator = less>
38  lexicographical_compare<as_sequence_t<SequenceA>,
39  as_sequence_t<SequenceB>,
40  Comparator> {};
41 
42 template<class AHead,
43  class ... ATail,
44  class BHead,
45  class ... BTail,
46  template<class ...> class Comparator>
48  sequence<AHead, ATail...>,
49  sequence<BHead, BTail...>,
50  Comparator> :
51  std::integral_constant < int,
52  ( Comparator<AHead, BHead>::type::value ?
53  -1 :
54  Comparator<BHead, AHead>::type::value ?
55  1 :
56  lexicographical_compare <
57  sequence<ATail...>,
58  sequence<BTail...>,
59  Comparator >::value
60  ) > {};
61 
62 template<class ... As, template<class ...> class Comparator>
63 struct lexicographical_compare< sequence<As...>, sequence<>, Comparator> :
64  std::integral_constant<int, 1> {};
65 
66 template<class ... Bs, template<class ...> class Comparator>
67 struct lexicographical_compare< sequence<>, sequence<Bs...>, Comparator> :
68  std::integral_constant < int, -1 > {};
69 
70 template<template<class ...> class Comparator>
71 struct lexicographical_compare< sequence<>, sequence<>, Comparator> :
72  std::integral_constant<int, 0> {};
73 
74 } // namespace tinympl
75 
76 #endif // TINYMPL_LEXICOGRAPHICAL_COMPARE_HPP
Compares two sequences using the given comparator.
Definition: lexicographical_compare.hpp:37
The main sequence type.
Definition: sequence.hpp:28