TPIE

2362a60
is_simple_iterator.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2013, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #include <vector>
21 #include <string>
22 
23 namespace tpie {
24 
25 template <bool> struct is_simple_iterator_enable_if { };
26 template <> struct is_simple_iterator_enable_if<true> {typedef void type;};
27 
35 template <typename T>
37 private:
38  template <typename TT>
39  static char magic(typename std::vector<typename TT::value_type>::iterator*);
40  template <typename TT>
41  static char magic(typename std::vector<typename TT::value_type>::const_iterator*);
42  template <typename TT>
43  static char magic(typename std::basic_string<char>::iterator*);
44  template <typename TT>
45  static char magic(typename std::basic_string<char>::const_iterator*);
46  template <typename TT>
47  static char magic(TT *, typename is_simple_iterator_enable_if<TT::is_simple_iterator>::type *_=0);
48  template <typename TT>
49  static long magic(...);
50 public:
51  static bool const value=sizeof(magic<T>((T*)0))==sizeof(char);
52 };
53 
54 } //namespace tpie
Checks if an iterator is simple.