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
|
#ifndef GENERS_IOISCONTAINER_HH_
#define GENERS_IOISCONTAINER_HH_
#include <string>
namespace gs {
// In the following template, enum "IsContainer" is evaluated to 1
// at compile time if T has T::value_type typedef
template <typename T>
class IOIsContainer {
private:
typedef char One;
typedef struct {
char a[2];
} Two;
template <typename C>
static One test(typename C::value_type const *);
template <typename C>
static Two test(...);
public:
enum { value = sizeof(IOIsContainer<T>::template test<T>(nullptr)) == 1 };
};
// Char strings get a special treatment
template <>
class IOIsContainer<std::string> {
public:
enum { value = 0 };
};
template <>
class IOIsContainer<const std::string> {
public:
enum { value = 0 };
};
template <>
class IOIsContainer<volatile std::string> {
public:
enum { value = 0 };
};
template <>
class IOIsContainer<const volatile std::string> {
public:
enum { value = 0 };
};
} // namespace gs
#endif // GENERS_IOISCONTAINER_HH_
|