cld 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/LICENSE +27 -0
  2. data/Manifest +106 -0
  3. data/README.rdoc +173 -0
  4. data/Rakefile +15 -0
  5. data/base/basictypes.h +348 -0
  6. data/base/build_config.h +115 -0
  7. data/base/casts.h +156 -0
  8. data/base/commandlineflags.h +443 -0
  9. data/base/crash.h +41 -0
  10. data/base/dynamic_annotations.h +358 -0
  11. data/base/global_strip_options.h +59 -0
  12. data/base/log_severity.h +46 -0
  13. data/base/logging.h +1403 -0
  14. data/base/macros.h +243 -0
  15. data/base/port.h +54 -0
  16. data/base/scoped_ptr.h +428 -0
  17. data/base/stl_decl.h +0 -0
  18. data/base/stl_decl_msvc.h +107 -0
  19. data/base/string_util.h +29 -0
  20. data/base/strtoint.h +93 -0
  21. data/base/template_util.h +96 -0
  22. data/base/type_traits.h +198 -0
  23. data/base/vlog_is_on.h +143 -0
  24. data/build.sh +48 -0
  25. data/build.win.cmd +28 -0
  26. data/cld.gemspec +30 -0
  27. data/cld_encodings.h +95 -0
  28. data/encodings/compact_lang_det/#cldutil.cc# +905 -0
  29. data/encodings/compact_lang_det/#cldutil.h# +1205 -0
  30. data/encodings/compact_lang_det/#compact_lang_det_impl.h# +171 -0
  31. data/encodings/compact_lang_det/#ext_lang_enc.cc# +545 -0
  32. data/encodings/compact_lang_det/#ext_lang_enc.h# +119 -0
  33. data/encodings/compact_lang_det/#getonescriptspan.cc# +570 -0
  34. data/encodings/compact_lang_det/#getonescriptspan.h# +131 -0
  35. data/encodings/compact_lang_det/#tote.cc# +299 -0
  36. data/encodings/compact_lang_det/#tote.h# +89 -0
  37. data/encodings/compact_lang_det/cldutil.cc +905 -0
  38. data/encodings/compact_lang_det/cldutil.h +1205 -0
  39. data/encodings/compact_lang_det/cldutil_dbg.h +76 -0
  40. data/encodings/compact_lang_det/cldutil_dbg_empty.cc +76 -0
  41. data/encodings/compact_lang_det/compact_lang_det.cc +62 -0
  42. data/encodings/compact_lang_det/compact_lang_det.h +145 -0
  43. data/encodings/compact_lang_det/compact_lang_det_impl.cc +2574 -0
  44. data/encodings/compact_lang_det/compact_lang_det_impl.h +173 -0
  45. data/encodings/compact_lang_det/compact_lang_det_unittest_small.cc +406 -0
  46. data/encodings/compact_lang_det/compile.cmd +1 -0
  47. data/encodings/compact_lang_det/ext_lang_enc.cc +545 -0
  48. data/encodings/compact_lang_det/ext_lang_enc.h +119 -0
  49. data/encodings/compact_lang_det/generated/cld_generated_score_deltaoctachrome_0406.cc +380 -0
  50. data/encodings/compact_lang_det/generated/cld_generated_score_quadchrome_0406.cc +382 -0
  51. data/encodings/compact_lang_det/generated/compact_lang_det_generated_cjkbis_0.cc +49 -0
  52. data/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz.cc +7119 -0
  53. data/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz_0.cc +61 -0
  54. data/encodings/compact_lang_det/generated/compact_lang_det_generated_deltaoctachrome.cc +1263 -0
  55. data/encodings/compact_lang_det/generated/compact_lang_det_generated_longwords8_0.cc +53 -0
  56. data/encodings/compact_lang_det/generated/compact_lang_det_generated_meanscore.h +10 -0
  57. data/encodings/compact_lang_det/generated/compact_lang_det_generated_quads_0.cc +50 -0
  58. data/encodings/compact_lang_det/generated/compact_lang_det_generated_quadschrome.cc +70935 -0
  59. data/encodings/compact_lang_det/getonescriptspan.cc +570 -0
  60. data/encodings/compact_lang_det/getonescriptspan.h +131 -0
  61. data/encodings/compact_lang_det/letterscript_enum.cc +117 -0
  62. data/encodings/compact_lang_det/letterscript_enum.h +99 -0
  63. data/encodings/compact_lang_det/subsetsequence.cc +259 -0
  64. data/encodings/compact_lang_det/subsetsequence.h +44 -0
  65. data/encodings/compact_lang_det/subsetsequence_unittest.cc +99 -0
  66. data/encodings/compact_lang_det/tote.cc +299 -0
  67. data/encodings/compact_lang_det/tote.h +89 -0
  68. data/encodings/compact_lang_det/unittest_data.h +193 -0
  69. data/encodings/compact_lang_det/utf8propjustletter.h +1162 -0
  70. data/encodings/compact_lang_det/utf8propletterscriptnum.h +1222 -0
  71. data/encodings/compact_lang_det/utf8scannotjustletterspecial.h +1185 -0
  72. data/encodings/compact_lang_det/win/#cld_unilib_windows.cc# +29 -0
  73. data/encodings/compact_lang_det/win/cld_basictypes.h +10 -0
  74. data/encodings/compact_lang_det/win/cld_commandlineflags.h +28 -0
  75. data/encodings/compact_lang_det/win/cld_google.h +18 -0
  76. data/encodings/compact_lang_det/win/cld_htmlutils.h +13 -0
  77. data/encodings/compact_lang_det/win/cld_htmlutils_google3.cc +32 -0
  78. data/encodings/compact_lang_det/win/cld_htmlutils_windows.cc +29 -0
  79. data/encodings/compact_lang_det/win/cld_logging.h +21 -0
  80. data/encodings/compact_lang_det/win/cld_macros.h +19 -0
  81. data/encodings/compact_lang_det/win/cld_strtoint.h +26 -0
  82. data/encodings/compact_lang_det/win/cld_unicodetext.cc +84 -0
  83. data/encodings/compact_lang_det/win/cld_unicodetext.h +40 -0
  84. data/encodings/compact_lang_det/win/cld_unilib.h +15 -0
  85. data/encodings/compact_lang_det/win/cld_unilib_google3.cc +18 -0
  86. data/encodings/compact_lang_det/win/cld_unilib_windows.cc +29 -0
  87. data/encodings/compact_lang_det/win/cld_utf.h +24 -0
  88. data/encodings/compact_lang_det/win/cld_utf8statetable.cc +224 -0
  89. data/encodings/compact_lang_det/win/cld_utf8statetable.h +141 -0
  90. data/encodings/compact_lang_det/win/cld_utf8utils.h +22 -0
  91. data/encodings/compact_lang_det/win/cld_utf8utils_google3.cc +18 -0
  92. data/encodings/compact_lang_det/win/cld_utf8utils_windows.cc +17 -0
  93. data/encodings/compact_lang_det/win/normalizedunicodetext.cc +172 -0
  94. data/encodings/compact_lang_det/win/normalizedunicodetext.h +67 -0
  95. data/encodings/internal/encodings.cc +12 -0
  96. data/encodings/lang_enc.h +254 -0
  97. data/encodings/proto/encodings.pb.h +169 -0
  98. data/encodings/public/encodings.h +301 -0
  99. data/ext/cld/extconf.rb +7 -0
  100. data/languages/internal/#languages.cc# +337 -0
  101. data/languages/internal/languages.cc +337 -0
  102. data/languages/proto/languages.pb.h +179 -0
  103. data/languages/public/languages.h +379 -0
  104. data/lib/cld.rb +12 -0
  105. data/test/test.rb +570 -0
  106. data/thunk.cc +131 -0
  107. metadata +168 -0
File without changes
@@ -0,0 +1,107 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // In most .h files, we would rather include a declaration of an stl
6
+ // rather than including the appropriate stl h file (which brings in
7
+ // lots of noise). For many STL classes this is ok (eg pair), but for
8
+ // some it's really annoying. We define those here, so you can
9
+ // just include this file instead of having to deal with the annoyance.
10
+ //
11
+ // Most of the annoyance, btw, has to do with the default allocator.
12
+
13
+ #ifndef _STL_DECL_MSVC_H
14
+ #define _STL_DECL_MSVC_H
15
+
16
+ // VC++ namespace / STL issues; make them explicit
17
+ #include <wchar.h>
18
+ #include <string>
19
+ #include <vector>
20
+ #include <functional>
21
+ #include <utility>
22
+ #include <set>
23
+ #include <list>
24
+ #define slist list
25
+ #include <algorithm>
26
+ #include <deque>
27
+ #include <iostream>
28
+ #include <map>
29
+ #include <queue>
30
+ #include <stack>
31
+
32
+ // copy_n isn't to be found anywhere in MSVC's STL
33
+ template <typename InputIterator, typename Size, typename OutputIterator>
34
+ std::pair<InputIterator, OutputIterator>
35
+ copy_n(InputIterator in, Size count, OutputIterator out) {
36
+ for ( ; count > 0; --count) {
37
+ *out = *in;
38
+ ++out;
39
+ ++in;
40
+ }
41
+ return std::make_pair(in, out);
42
+ }
43
+
44
+ // Nor are the following selectors
45
+ template <typename T>
46
+ struct identity {
47
+ inline const T& operator()(const T& t) const { return t; }
48
+ };
49
+
50
+ // Copied from STLport
51
+ template <class _Pair>
52
+ struct select1st : public std::unary_function<_Pair, typename _Pair::first_type> {
53
+ const typename _Pair::first_type& operator()(const _Pair& __x) const {
54
+ return __x.first;
55
+ }
56
+ };
57
+
58
+ template <class _Pair>
59
+ struct select2nd : public std::unary_function<_Pair, typename _Pair::second_type>
60
+ {
61
+ const typename _Pair::second_type& operator()(const _Pair& __x) const {
62
+ return __x.second;
63
+ }
64
+ };
65
+
66
+
67
+ #if _MSC_VER >= 1300
68
+
69
+ // If you compile on Windows and get a compile-time error because
70
+ // some google3 code specifies a 3rd or 4th parameter to one of
71
+ // these template classes, then you have to put in some #ifdefs
72
+ // and use the NATIVE_HASH_NAMESPACE::hash_(set|map) implementation.
73
+ namespace msvchash {
74
+ template <typename Key>
75
+ struct hash;
76
+
77
+ template <class Key,
78
+ class HashFcn = hash<Key> >
79
+ class hash_set;
80
+
81
+ template <class Key, class Val,
82
+ class HashFcn = hash<Key> >
83
+ class hash_map;
84
+
85
+ template <class Key,
86
+ class HashFcn = hash<Key> >
87
+ class hash_multiset;
88
+
89
+ template <class Key, class Val,
90
+ class HashFcn = hash<Key> >
91
+ class hash_multimap;
92
+ } // end namespace msvchash
93
+
94
+ using msvchash::hash_set;
95
+ using msvchash::hash_map;
96
+ using msvchash::hash;
97
+ using msvchash::hash_multimap;
98
+ using msvchash::hash_multiset;
99
+
100
+ #else
101
+ #define hash_map map
102
+ #define hash_set set
103
+ #endif
104
+
105
+ using namespace std;
106
+
107
+ #endif /* #ifdef _STL_DECL_MSVC_H */
@@ -0,0 +1,29 @@
1
+ // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ //
5
+ // This file defines utility functions for working with strings.
6
+
7
+ #ifndef BASE_STRING_UTIL_H_
8
+ #define BASE_STRING_UTIL_H_
9
+
10
+ #include <string.h>
11
+
12
+ namespace base {
13
+
14
+ #ifdef WIN32
15
+ // Compare the two strings s1 and s2 without regard to case using
16
+ // the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
17
+ // s2 > s1 according to a lexicographic comparison.
18
+ inline int strcasecmp(const char* s1, const char* s2) {
19
+ return _stricmp(s1, s2);
20
+ }
21
+ #else
22
+ inline int strcasecmp(const char* s1, const char* s2) {
23
+ return ::strcasecmp(s1, s2);
24
+ }
25
+ #endif
26
+
27
+ }
28
+
29
+ #endif // BASE_STRING_UTIL_H_
@@ -0,0 +1,93 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Architecture-neutral plug compatible replacements for strtol() friends.
6
+ //
7
+ // Long's have different lengths on ILP-32 and LP-64 platforms, and so overflow
8
+ // behavior across the two varies when strtol() and similar are used to parse
9
+ // 32-bit integers. Similar problems exist with atoi(), because although it
10
+ // has an all-integer interface, it uses strtol() internally, and so suffers
11
+ // from the same narrowing problems on assignments to int.
12
+ //
13
+ // Examples:
14
+ // errno = 0;
15
+ // i = strtol("3147483647", NULL, 10);
16
+ // printf("%d, errno %d\n", i, errno);
17
+ // // 32-bit platform: 2147483647, errno 34
18
+ // // 64-bit platform: -1147483649, errno 0
19
+ //
20
+ // printf("%d\n", atoi("3147483647"));
21
+ // // 32-bit platform: 2147483647
22
+ // // 64-bit platform: -1147483649
23
+ //
24
+ // A way round this is to define local replacements for these, and use them
25
+ // instead of the standard libc functions.
26
+ //
27
+ // In most 32-bit cases the replacements can be inlined away to a call to the
28
+ // libc function. In a couple of 64-bit cases, however, adapters are required,
29
+ // to provide the right overflow and errno behavior.
30
+ //
31
+
32
+ #ifndef BASE_STRTOINT_H_
33
+ #define BASE_STRTOINT_H_
34
+
35
+ #include <stdlib.h> // For strtol* functions.
36
+ #include <string>
37
+ #include "base/port.h"
38
+ #include "base/basictypes.h"
39
+
40
+ // Adapter functions for handling overflow and errno.
41
+ int32 strto32_adapter(const char *nptr, char **endptr, int base);
42
+ uint32 strtou32_adapter(const char *nptr, char **endptr, int base);
43
+
44
+ // Conversions to a 32-bit integer can pass the call to strto[u]l on 32-bit
45
+ // platforms, but need a little extra work on 64-bit platforms.
46
+ inline int32 strto32(const char *nptr, char **endptr, int base) {
47
+ if (sizeof(int32) == sizeof(long))
48
+ return strtol(nptr, endptr, base);
49
+ else
50
+ return strto32_adapter(nptr, endptr, base);
51
+ }
52
+
53
+ inline uint32 strtou32(const char *nptr, char **endptr, int base) {
54
+ if (sizeof(uint32) == sizeof(unsigned long))
55
+ return strtoul(nptr, endptr, base);
56
+ else
57
+ return strtou32_adapter(nptr, endptr, base);
58
+ }
59
+
60
+ // For now, long long is 64-bit on all the platforms we care about, so these
61
+ // functions can simply pass the call to strto[u]ll.
62
+ inline int64 strto64(const char *nptr, char **endptr, int base) {
63
+ COMPILE_ASSERT(sizeof(int64) == sizeof(long long),
64
+ sizeof_int64_is_not_sizeof_long_long);
65
+ return strtoll(nptr, endptr, base);
66
+ }
67
+
68
+ inline uint64 strtou64(const char *nptr, char **endptr, int base) {
69
+ COMPILE_ASSERT(sizeof(uint64) == sizeof(unsigned long long),
70
+ sizeof_uint64_is_not_sizeof_long_long);
71
+ return strtoull(nptr, endptr, base);
72
+ }
73
+
74
+ // Although it returns an int, atoi() is implemented in terms of strtol, and
75
+ // so has differing overflow and underflow behavior. atol is the same.
76
+ inline int32 atoi32(const char *nptr) {
77
+ return strto32(nptr, NULL, 10);
78
+ }
79
+
80
+ inline int64 atoi64(const char *nptr) {
81
+ return strto64(nptr, NULL, 10);
82
+ }
83
+
84
+ // Convenience versions of the above that take a string argument.
85
+ inline int32 atoi32(const string &s) {
86
+ return atoi32(s.c_str());
87
+ }
88
+
89
+ inline int64 atoi64(const string &s) {
90
+ return atoi64(s.c_str());
91
+ }
92
+
93
+ #endif // BASE_STRTOINT_H_
@@ -0,0 +1,96 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Template metaprogramming utility functions.
6
+ //
7
+ // This code is compiled directly on many platforms, including client
8
+ // platforms like Windows, Mac, and embedded systems. Before making
9
+ // any changes here, make sure that you're not breaking any platforms.
10
+ //
11
+ // The names choosen here reflect those used in tr1 and the boost::mpl
12
+ // library, there are similar operations used in the Loki library as
13
+ // well. I prefer the boost names for 2 reasons:
14
+ // 1. I think that portions of the Boost libraries are more likely to
15
+ // be included in the c++ standard.
16
+ // 2. It is not impossible that some of the boost libraries will be
17
+ // included in our own build in the future.
18
+ // Both of these outcomes means that we may be able to directly replace
19
+ // some of these with boost equivalents.
20
+ //
21
+ #ifndef BASE_TEMPLATE_UTIL_H_
22
+ #define BASE_TEMPLATE_UTIL_H_
23
+
24
+ namespace base {
25
+
26
+ // Types small_ and big_ are guaranteed such that sizeof(small_) <
27
+ // sizeof(big_)
28
+ typedef char small_;
29
+
30
+ struct big_ {
31
+ char dummy[2];
32
+ };
33
+
34
+ // integral_constant, defined in tr1, is a wrapper for an integer
35
+ // value. We don't really need this generality; we could get away
36
+ // with hardcoding the integer type to bool. We use the fully
37
+ // general integer_constant for compatibility with tr1.
38
+
39
+ template<class T, T v>
40
+ struct integral_constant {
41
+ static const T value = v;
42
+ typedef T value_type;
43
+ typedef integral_constant<T, v> type;
44
+ };
45
+
46
+ template <class T, T v> const T integral_constant<T, v>::value;
47
+
48
+
49
+ // Abbreviations: true_type and false_type are structs that represent boolean
50
+ // true and false values. Also define the boost::mpl versions of those names,
51
+ // true_ and false_.
52
+ typedef integral_constant<bool, true> true_type;
53
+ typedef integral_constant<bool, false> false_type;
54
+ typedef true_type true_;
55
+ typedef false_type false_;
56
+
57
+ // if_ is a templatized conditional statement.
58
+ // if_<cond, A, B> is a compile time evaluation of cond.
59
+ // if_<>::type contains A if cond is true, B otherwise.
60
+ template<bool cond, typename A, typename B>
61
+ struct if_{
62
+ typedef A type;
63
+ };
64
+
65
+ template<typename A, typename B>
66
+ struct if_<false, A, B> {
67
+ typedef B type;
68
+ };
69
+
70
+
71
+ // type_equals_ is a template type comparator, similar to Loki IsSameType.
72
+ // type_equals_<A, B>::value is true iff "A" is the same type as "B".
73
+ template<typename A, typename B>
74
+ struct type_equals_ : public false_ {
75
+ };
76
+
77
+ template<typename A>
78
+ struct type_equals_<A, A> : public true_ {
79
+ };
80
+
81
+ // and_ is a template && operator.
82
+ // and_<A, B>::value evaluates "A::value && B::value".
83
+ template<typename A, typename B>
84
+ struct and_ : public integral_constant<bool, (A::value && B::value)> {
85
+ };
86
+
87
+ // or_ is a template || operator.
88
+ // or_<A, B>::value evaluates "A::value || B::value".
89
+ template<typename A, typename B>
90
+ struct or_ : public integral_constant<bool, (A::value || B::value)> {
91
+ };
92
+
93
+
94
+ } // Close namespace base
95
+
96
+ #endif // BASE_TEMPLATE_UTIL_H_
@@ -0,0 +1,198 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // This code is compiled directly on many platforms, including client
6
+ // platforms like Windows, Mac, and embedded systems. Before making
7
+ // any changes here, make sure that you're not breaking any platforms.
8
+ //
9
+ //
10
+ // Define a small subset of tr1 type traits. The traits we define are:
11
+ // is_integral
12
+ // is_floating_point
13
+ // is_pointer
14
+ // is_reference
15
+ // is_pod
16
+ // has_trivial_constructor
17
+ // has_trivial_copy
18
+ // has_trivial_assign
19
+ // has_trivial_destructor
20
+ // remove_const
21
+ // remove_volatile
22
+ // remove_cv
23
+ // remove_reference
24
+ // remove_pointer
25
+ // is_convertible
26
+ // We can add more type traits as required.
27
+
28
+ #ifndef BASE_TYPE_TRAITS_H_
29
+ #define BASE_TYPE_TRAITS_H_
30
+
31
+ #include "base/template_util.h" // For true_type and false_type
32
+ #include <utility> // For pair
33
+
34
+ namespace base {
35
+
36
+ // is_integral is false except for the built-in integer types.
37
+ template <class T> struct is_integral : false_type { };
38
+ template<> struct is_integral<bool> : true_type { };
39
+ template<> struct is_integral<char> : true_type { };
40
+ template<> struct is_integral<unsigned char> : true_type { };
41
+ template<> struct is_integral<signed char> : true_type { };
42
+ #if defined(_MSC_VER)
43
+ // wchar_t is not by default a distinct type from unsigned short in
44
+ // Microsoft C.
45
+ // See http://msdn2.microsoft.com/en-us/library/dh8che7s(VS.80).aspx
46
+ template<> struct is_integral<__wchar_t> : true_type { };
47
+ #else
48
+ template<> struct is_integral<wchar_t> : true_type { };
49
+ #endif
50
+ template<> struct is_integral<short> : true_type { };
51
+ template<> struct is_integral<unsigned short> : true_type { };
52
+ template<> struct is_integral<int> : true_type { };
53
+ template<> struct is_integral<unsigned int> : true_type { };
54
+ template<> struct is_integral<long> : true_type { };
55
+ template<> struct is_integral<unsigned long> : true_type { };
56
+ template<> struct is_integral<long long> : true_type { };
57
+ template<> struct is_integral<unsigned long long> : true_type { };
58
+
59
+
60
+ // is_floating_point is false except for the built-in floating-point types.
61
+ template <class T> struct is_floating_point : false_type { };
62
+ template<> struct is_floating_point<float> : true_type { };
63
+ template<> struct is_floating_point<double> : true_type { };
64
+ template<> struct is_floating_point<long double> : true_type { };
65
+
66
+
67
+ // is_pointer is false except for pointer types.
68
+ template <class T> struct is_pointer : false_type { };
69
+ template <class T> struct is_pointer<T*> : true_type { };
70
+
71
+
72
+ // is_reference is false except for reference types.
73
+ template<typename T> struct is_reference : false_type {};
74
+ template<typename T> struct is_reference<T&> : true_type {};
75
+
76
+
77
+ // We can't get is_pod right without compiler help, so fail conservatively.
78
+ // We will assume it's false except for arithmetic types and pointers,
79
+ // and const versions thereof. Note that std::pair is not a POD.
80
+ template <class T> struct is_pod
81
+ : integral_constant<bool, (is_integral<T>::value ||
82
+ is_floating_point<T>::value ||
83
+ is_pointer<T>::value)> { };
84
+ template <class T> struct is_pod<const T> : is_pod<T> { };
85
+
86
+
87
+ // We can't get has_trivial_constructor right without compiler help, so
88
+ // fail conservatively. We will assume it's false except for: (1) types
89
+ // for which is_pod is true. (2) std::pair of types with trivial
90
+ // constructors. (3) array of a type with a trivial constructor.
91
+ // (4) const versions thereof.
92
+ template <class T> struct has_trivial_constructor : is_pod<T> { };
93
+ template <class T, class U> struct has_trivial_constructor<std::pair<T, U> >
94
+ : integral_constant<bool,
95
+ (has_trivial_constructor<T>::value &&
96
+ has_trivial_constructor<U>::value)> { };
97
+ template <class A, int N> struct has_trivial_constructor<A[N]>
98
+ : has_trivial_constructor<A> { };
99
+ template <class T> struct has_trivial_constructor<const T>
100
+ : has_trivial_constructor<T> { };
101
+
102
+ // We can't get has_trivial_copy right without compiler help, so fail
103
+ // conservatively. We will assume it's false except for: (1) types
104
+ // for which is_pod is true. (2) std::pair of types with trivial copy
105
+ // constructors. (3) array of a type with a trivial copy constructor.
106
+ // (4) const versions thereof.
107
+ template <class T> struct has_trivial_copy : is_pod<T> { };
108
+ template <class T, class U> struct has_trivial_copy<std::pair<T, U> >
109
+ : integral_constant<bool,
110
+ (has_trivial_copy<T>::value &&
111
+ has_trivial_copy<U>::value)> { };
112
+ template <class A, int N> struct has_trivial_copy<A[N]>
113
+ : has_trivial_copy<A> { };
114
+ template <class T> struct has_trivial_copy<const T> : has_trivial_copy<T> { };
115
+
116
+ // We can't get has_trivial_assign right without compiler help, so fail
117
+ // conservatively. We will assume it's false except for: (1) types
118
+ // for which is_pod is true. (2) std::pair of types with trivial copy
119
+ // constructors. (3) array of a type with a trivial assign constructor.
120
+ template <class T> struct has_trivial_assign : is_pod<T> { };
121
+ template <class T, class U> struct has_trivial_assign<std::pair<T, U> >
122
+ : integral_constant<bool,
123
+ (has_trivial_assign<T>::value &&
124
+ has_trivial_assign<U>::value)> { };
125
+ template <class A, int N> struct has_trivial_assign<A[N]>
126
+ : has_trivial_assign<A> { };
127
+
128
+ // We can't get has_trivial_destructor right without compiler help, so
129
+ // fail conservatively. We will assume it's false except for: (1) types
130
+ // for which is_pod is true. (2) std::pair of types with trivial
131
+ // destructors. (3) array of a type with a trivial destructor.
132
+ // (4) const versions thereof.
133
+ template <class T> struct has_trivial_destructor : is_pod<T> { };
134
+ template <class T, class U> struct has_trivial_destructor<std::pair<T, U> >
135
+ : integral_constant<bool,
136
+ (has_trivial_destructor<T>::value &&
137
+ has_trivial_destructor<U>::value)> { };
138
+ template <class A, int N> struct has_trivial_destructor<A[N]>
139
+ : has_trivial_destructor<A> { };
140
+ template <class T> struct has_trivial_destructor<const T>
141
+ : has_trivial_destructor<T> { };
142
+
143
+ // Specified by TR1 [4.7.1]
144
+ template<typename T> struct remove_const { typedef T type; };
145
+ template<typename T> struct remove_const<T const> { typedef T type; };
146
+ template<typename T> struct remove_volatile { typedef T type; };
147
+ template<typename T> struct remove_volatile<T volatile> { typedef T type; };
148
+ template<typename T> struct remove_cv {
149
+ typedef typename remove_const<typename remove_volatile<T>::type>::type type;
150
+ };
151
+
152
+
153
+ // Specified by TR1 [4.7.2]
154
+ template<typename T> struct remove_reference { typedef T type; };
155
+ template<typename T> struct remove_reference<T&> { typedef T type; };
156
+
157
+ // Specified by TR1 [4.7.4] Pointer modifications.
158
+ template<typename T> struct remove_pointer { typedef T type; };
159
+ template<typename T> struct remove_pointer<T*> { typedef T type; };
160
+ template<typename T> struct remove_pointer<T* const> { typedef T type; };
161
+ template<typename T> struct remove_pointer<T* volatile> { typedef T type; };
162
+ template<typename T> struct remove_pointer<T* const volatile> {
163
+ typedef T type; };
164
+
165
+ // Specified by TR1 [4.6] Relationships between types
166
+ #ifndef _MSC_VER
167
+ namespace internal {
168
+
169
+ // This class is an implementation detail for is_convertible, and you
170
+ // don't need to know how it works to use is_convertible. For those
171
+ // who care: we declare two different functions, one whose argument is
172
+ // of type To and one with a variadic argument list. We give them
173
+ // return types of different size, so we can use sizeof to trick the
174
+ // compiler into telling us which function it would have chosen if we
175
+ // had called it with an argument of type From. See Alexandrescu's
176
+ // _Modern C++ Design_ for more details on this sort of trick.
177
+
178
+ template <typename From, typename To>
179
+ struct ConvertHelper {
180
+ static small_ Test(To);
181
+ static big_ Test(...);
182
+ static From Create();
183
+ };
184
+ } // namespace internal
185
+
186
+ // Inherits from true_type if From is convertible to To, false_type otherwise.
187
+ template <typename From, typename To>
188
+ struct is_convertible
189
+ : integral_constant<bool,
190
+ sizeof(internal::ConvertHelper<From, To>::Test(
191
+ internal::ConvertHelper<From, To>::Create()))
192
+ == sizeof(small_)> {
193
+ };
194
+ #endif
195
+
196
+ } // Close namespace base
197
+
198
+ #endif // BASE_TYPE_TRAITS_H_