[go: up one dir, main page]

Menu

[5a71d8]: / algo / test.cpp  Maximize  Restore  History

Download this file

104 lines (74 with data), 1.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#include <iostream>
struct no_key_tag {};
struct key_tag: public no_key_tag {};
struct structure_has_key
{
};
struct with_key: public structure_has_key
{
typedef int key_type;
key_type _key;
int data;
key_type key() { return _key; };
};
struct without_key
{
int data;
};
template <typename _Tp>
struct container_iterator
{
typedef _Tp value_type;
};
template<typename _Tp>
bool has_key()
{
return false;
}
template<>
bool has_key< structure_has_key * >()
{
return true;
}
template<>
bool has_key< container_iterator< structure_has_key> >()
{
return true;
}
template<typename _Iter>
struct iterator_traits
{
// typedef _Iter::value_type value_type;
};
/*
template<typename _Tp>
struct iterator_traits<_Tp>
{
typedef _Tp value_type;
};
*/
template <typename _Iter>
void _some_algorithm_with_use_of_keys(_Iter first, _Iter last)
{
std::cout << "Use keys"<<std::endl;
}
template <typename _Iter>
void _some_algorithm_without_use_of_keys(_Iter first, _Iter last)
{
std::cout << "Don't use keys" << std::endl;
}
template <typename _Iter>
void some_algorithm(_Iter first, _Iter last)
{
// some_algorithm(first,last, key_present(first) );
if(has_key<_Iter>())
_some_algorithm_with_use_of_keys(first,last);
else
_some_algorithm_without_use_of_keys(first,last);
}
int main()
{
with_key * f, * l;
some_algorithm(f,l);
return 0;
}