From e133ace8d907bf42754c86106fc3f04a9d9fe70f Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 31 May 2007 23:37:56 +0000 Subject: re PR libstdc++/31426 (TR1 includes do not work with -std=c++0x) 2007-05-31 Paolo Carlini PR libstdc++/31426 * include/bits/c++config: Remove namespace association bits from tr1 to std. * include/ext/type_traits.h (__promote, __promote2, __promote3, __promote4): Add. * include/bits/hashtable.h: New. * include/bits/functional_hash.h: Likewise. * include/tr1/hashtable.h: Likewise. * include/tr1_impl/random: New. * include/tr1_impl/cinttypes: Likewise. * include/tr1_impl/cstdlib: Likewise. * include/tr1_impl/unordered_map: Likewise. * include/tr1_impl/cstdio: Likewise. * include/tr1_impl/boost_shared_ptr.h: Likewise. * include/tr1_impl/cctype: Likewise. * include/tr1_impl/random.tcc: Likewise. * include/tr1_impl/tuple: Likewise. * include/tr1_impl/functional_hash.h: Likewise. * include/tr1_impl/hashtable: Likewise. * include/tr1_impl/cmath: Likewise. * include/tr1_impl/type_traitsfwd.h: Likewise. * include/tr1_impl/hashtable_policy.h: Likewise. * include/tr1_impl/cfenv: Likewise. * include/tr1_impl/unordered_set: Likewise. * include/tr1_impl/functional: Likewise. * include/tr1_impl/utility: Likewise. * include/tr1_impl/complex: Likewise. * include/tr1_impl/type_traits: Likewise. * include/tr1_impl/cwchar: Likewise. * include/tr1_impl/cstdint: Likewise. * include/tr1_impl/regex: Likewise. * include/tr1_impl/array: Likewise. * include/tr1_impl/cwctype: Likewise. * include/tr1/type_traitsfwd.h: Remove. * include/tr1/boost_shared_ptr.h: Likewise. * include/tr1/common.h: Likewise. * include/tr1/hashtable: Likewise. * include/tr1/hashtable_policy.h: Likewise. * include/tr1/random.tcc: Likewise. * include/c_global/cinttypes: Include tr1_impl/cinttypes. * include/c_global/cstdlib: Likewise for cstdlib. * include/c_global/cstdio: Likewise for cstdio. * include/c_global/cctype: Likewise for cctype. * include/c_global/cmath: Likewise for cmath. * include/c_global/cfenv: Likewise for cfenv. * include/c_global/cwchar: Likewise for cwchar. * include/c_global/cstdint: Likewise for cstdint. * include/c_global/cwctype: Likewise for cwctype. * include/tr1/cinttypes: Likewise for cinttypes. * include/tr1/cstdlib: Likewise for cstdlib. * include/tr1/cstdio: Likewise for cstdio. * include/tr1/cctype: Likewise for cctype. * include/tr1/cmath: Likewise for cmath. * include/tr1/cfenv: Likewise for cfenv. * include/tr1/cwchar: Likewise for cwchar. * include/tr1/cstdint: Likewise for cstdint. * include/tr1/cwctype: Likewise for cwctype. * include/tr1/functional_hash.h: Likewise for functional_hash. * include/std/tuple: Include tr1_impl/tuple. * include/std/utility: Likewise for utility. * include/std/type_traits: Likewise for type_traits. (is_pod): Just forward to __is_pod. (has_trivial_default_constructor): Just forward to __has_trivial_constructor. (has_trivial_copy_constructor): Just forward to __has_trivial_copy. (has_trivial_assign): Just forward to __has_trivial_assign. (has_trivial_destructor): Just forward to __has_trivial_destructor. (has_nothrow_default_constructor): Just forward to __has_nothrow_constructor. (has_nothrow_copy_constructor): Just forward to __has_nothrow_copy. (has_nothrow_assign): Just forward to __has_nothrow_assign. (is_base_of): Just forward to __is_base_of. (is_signed, is_unsigned): Implement according to the C++0x specifications. * include/std/memory: Likewise for memory. * include/std/regex: Likewise for regex. * include/std/random: Likewise for random. * include/std/unordered_map: Likewise for unordered_map. * include/std/unordered_set: Likewise for unordered_set. * include/std/functional: Likewise for functional. * include/std/complex: Likewise for complex. * include/std/array: Likewise for array. * include/tr1/tuple: Likewise for tuple. * include/tr1/utility: Likewise for utility. * include/tr1/type_traits: Likewise for type_traits * include/tr1/memory: Likewise for memory. * include/tr1/regex: Likewise for regex. * include/tr1/random: Likewise for random. * include/tr1/unordered_map: Likewise for unordered_map. * include/tr1/unordered_set: Likewise for unordered_set. * include/tr1/functional: Likewise for functional. * include/tr1/complex: Likewise for complex. * include/tr1/array: Likewise for array. * include/c_global/ctgmath: Tweak. * include/c_global/cstdarg: Likewise. * include/c_global/ctime: Likewise. * include/c_global/climits: Likewise. * include/c_global/cfloat: Likewise. * include/c_global/ccomplex: Likewise. * include/c_global/cstdbool: Likewise. * include/tr1/poly_laguerre.tcc: Tweak, don't use _GLIBCXX_TR1. * include/tr1/riemann_zeta.tcc: Likewise. * include/tr1/beta_function.tcc: Likewise. * include/tr1/exp_integral.tcc: Likewise. * include/tr1/hypergeometric.tcc: Likewise. * include/tr1/modified_bessel_func.tcc: Likewise. * include/tr1/legendre_function.tcc: Likewise. * include/tr1/special_function_util.h: Likewise. * include/tr1/bessel_function.tcc: Likewise. * include/tr1/poly_hermite.tcc: Likewise. * include/tr1/ell_integral.tcc: Likewise. * include/tr1/gamma.tcc: Likewise. * include/tr1/stdlib.h: Likewise. * include/tr1/math.h: Likewise. * include/tr1/complex.h: Minor tweaks. * include/tr1/wctype.h: Likewise. * include/tr1/wchar.h: Likewise. * include/tr1/inttypes.h: Likewise. * include/tr1/tgmath.h: Likewise. * include/tr1/cstdbool: Likewise. * include/tr1/cfloat: Likewise. * include/tr1/ccomplex: Likewise. * include/tr1/ctime: Likewise. * include/tr1/climits: Likewise. * include/tr1/ctgmath: Likewise. * include/tr1/cstdarg: Likewise. * testsuite/tr1/headers.cc: Move... * testsuite/tr1/headers/all.cc: ... here. * testsuite/tr1/using_namespace_std_tr1.cc: Move... * testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc: ... here. * testsuite/tr1/headers/using_namespace_std_tr1.cc ... here. * testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc: New. * testsuite/20_util/tuple/requirements/explicit_instantiation.cc: Adjust namespace. * testsuite/20_util/has_nothrow_copy_constructor/value.cc: Adjust to the C++0x requirements. * testsuite/20_util/has_nothrow_default_constructor/value.cc: Likewise. * testsuite/20_util/has_trivial_copy_constructor/value.cc: Likewise. * testsuite/20_util/has_trivial_default_constructor/value.cc: Likewise. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust dg-error lines. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc: Un-xfail. * testsuite/20_util/is_signed/value.cc: New. * testsuite/20_util/is_signed/requirements/typedefs.cc: Likewise. * testsuite/20_util/is_signed/requirements/explicit_instantiation.cc: Likewise. * testsuite/20_util/is_unsigned/value.cc: Likewise.. * testsuite/20_util/is_unsigned/requirements/typedefs.cc: Likewise. * testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc: Likewise. * include/Makefile.am: Adjust. * include/Makefile.in: Regenerate. From-SVN: r125244 --- libstdc++-v3/ChangeLog | 172 ++ libstdc++-v3/include/Makefile.am | 57 +- libstdc++-v3/include/Makefile.in | 56 +- libstdc++-v3/include/bits/c++config | 16 - libstdc++-v3/include/bits/functional_hash.h | 63 + libstdc++-v3/include/bits/hashtable.h | 63 + libstdc++-v3/include/c_global/ccomplex | 11 +- libstdc++-v3/include/c_global/cctype | 20 +- libstdc++-v3/include/c_global/cfenv | 25 +- libstdc++-v3/include/c_global/cfloat | 10 +- libstdc++-v3/include/c_global/cinttypes | 25 +- libstdc++-v3/include/c_global/climits | 15 +- libstdc++-v3/include/c_global/cmath | 68 +- libstdc++-v3/include/c_global/cstdarg | 4 - libstdc++-v3/include/c_global/cstdbool | 9 +- libstdc++-v3/include/c_global/cstdint | 25 +- libstdc++-v3/include/c_global/cstdio | 20 +- libstdc++-v3/include/c_global/cstdlib | 20 +- libstdc++-v3/include/c_global/ctgmath | 6 +- libstdc++-v3/include/c_global/ctime | 7 +- libstdc++-v3/include/c_global/cwchar | 17 +- libstdc++-v3/include/c_global/cwctype | 20 +- libstdc++-v3/include/ext/type_traits.h | 46 + libstdc++-v3/include/std/array | 29 +- libstdc++-v3/include/std/complex | 45 +- libstdc++-v3/include/std/functional | 26 +- libstdc++-v3/include/std/memory | 28 +- libstdc++-v3/include/std/random | 35 +- libstdc++-v3/include/std/regex | 36 +- libstdc++-v3/include/std/tuple | 29 +- libstdc++-v3/include/std/type_traits | 199 +- libstdc++-v3/include/std/unordered_map | 33 +- libstdc++-v3/include/std/unordered_set | 33 +- libstdc++-v3/include/std/utility | 17 +- libstdc++-v3/include/tr1/array | 229 +- libstdc++-v3/include/tr1/bessel_function.tcc | 19 +- libstdc++-v3/include/tr1/beta_function.tcc | 29 +- libstdc++-v3/include/tr1/boost_shared_ptr.h | 1147 ---------- libstdc++-v3/include/tr1/ccomplex | 6 +- libstdc++-v3/include/tr1/cctype | 34 +- libstdc++-v3/include/tr1/cfenv | 65 +- libstdc++-v3/include/tr1/cfloat | 8 +- libstdc++-v3/include/tr1/cinttypes | 58 +- libstdc++-v3/include/tr1/climits | 8 +- libstdc++-v3/include/tr1/cmath | 1031 +-------- libstdc++-v3/include/tr1/common.h | 91 - libstdc++-v3/include/tr1/complex | 385 +--- libstdc++-v3/include/tr1/complex.h | 6 +- libstdc++-v3/include/tr1/cstdarg | 8 +- libstdc++-v3/include/tr1/cstdbool | 6 +- libstdc++-v3/include/tr1/cstdint | 74 +- libstdc++-v3/include/tr1/cstdio | 38 +- libstdc++-v3/include/tr1/cstdlib | 58 +- libstdc++-v3/include/tr1/ctgmath | 8 +- libstdc++-v3/include/tr1/ctime | 8 +- libstdc++-v3/include/tr1/cwchar | 53 +- libstdc++-v3/include/tr1/cwctype | 38 +- libstdc++-v3/include/tr1/ell_integral.tcc | 11 +- libstdc++-v3/include/tr1/exp_integral.tcc | 11 +- libstdc++-v3/include/tr1/functional | 2292 +------------------ libstdc++-v3/include/tr1/functional_hash.h | 213 +- libstdc++-v3/include/tr1/gamma.tcc | 13 +- libstdc++-v3/include/tr1/hashtable | 1203 ---------- libstdc++-v3/include/tr1/hashtable.h | 58 + libstdc++-v3/include/tr1/hashtable_policy.h | 904 -------- libstdc++-v3/include/tr1/hypergeometric.tcc | 19 +- libstdc++-v3/include/tr1/inttypes.h | 8 +- libstdc++-v3/include/tr1/legendre_function.tcc | 17 +- libstdc++-v3/include/tr1/math.h | 254 +- libstdc++-v3/include/tr1/memory | 32 +- libstdc++-v3/include/tr1/modified_bessel_func.tcc | 11 +- libstdc++-v3/include/tr1/poly_hermite.tcc | 11 +- libstdc++-v3/include/tr1/poly_laguerre.tcc | 15 +- libstdc++-v3/include/tr1/random | 2339 +------------------ libstdc++-v3/include/tr1/random.tcc | 1547 ------------- libstdc++-v3/include/tr1/regex | 2405 +------------------ libstdc++-v3/include/tr1/riemann_zeta.tcc | 31 +- libstdc++-v3/include/tr1/special_function_util.h | 11 +- libstdc++-v3/include/tr1/stdlib.h | 17 +- libstdc++-v3/include/tr1/tgmath.h | 8 +- libstdc++-v3/include/tr1/tuple | 416 +--- libstdc++-v3/include/tr1/type_traits | 507 +--- libstdc++-v3/include/tr1/type_traitsfwd.h | 222 -- libstdc++-v3/include/tr1/unordered_map | 235 +- libstdc++-v3/include/tr1/unordered_set | 233 +- libstdc++-v3/include/tr1/utility | 89 +- libstdc++-v3/include/tr1/wchar.h | 8 +- libstdc++-v3/include/tr1/wctype.h | 8 +- libstdc++-v3/include/tr1_impl/array | 239 ++ libstdc++-v3/include/tr1_impl/boost_shared_ptr.h | 1142 +++++++++ libstdc++-v3/include/tr1_impl/cctype | 48 + libstdc++-v3/include/tr1_impl/cfenv | 77 + libstdc++-v3/include/tr1_impl/cinttypes | 73 + libstdc++-v3/include/tr1_impl/cmath | 907 ++++++++ libstdc++-v3/include/tr1_impl/complex | 369 +++ libstdc++-v3/include/tr1_impl/cstdint | 85 + libstdc++-v3/include/tr1_impl/cstdio | 49 + libstdc++-v3/include/tr1_impl/cstdlib | 70 + libstdc++-v3/include/tr1_impl/cwchar | 63 + libstdc++-v3/include/tr1_impl/cwctype | 48 + libstdc++-v3/include/tr1_impl/functional | 2294 +++++++++++++++++++ libstdc++-v3/include/tr1_impl/functional_hash.h | 223 ++ libstdc++-v3/include/tr1_impl/hashtable | 1190 ++++++++++ libstdc++-v3/include/tr1_impl/hashtable_policy.h | 896 ++++++++ libstdc++-v3/include/tr1_impl/random | 2349 +++++++++++++++++++ libstdc++-v3/include/tr1_impl/random.tcc | 1548 +++++++++++++ libstdc++-v3/include/tr1_impl/regex | 2414 ++++++++++++++++++++ libstdc++-v3/include/tr1_impl/tuple | 430 ++++ libstdc++-v3/include/tr1_impl/type_traits | 489 ++++ libstdc++-v3/include/tr1_impl/type_traitsfwd.h | 178 ++ libstdc++-v3/include/tr1_impl/unordered_map | 229 ++ libstdc++-v3/include/tr1_impl/unordered_set | 227 ++ libstdc++-v3/include/tr1_impl/utility | 98 + .../20_util/has_nothrow_copy_constructor/value.cc | 5 +- .../has_nothrow_default_constructor/value.cc | 5 +- .../20_util/has_trivial_copy_constructor/value.cc | 5 +- .../has_trivial_default_constructor/value.cc | 5 +- .../headers/type_traits/types_std_c++0x_neg.cc | 8 +- .../requirements/explicit_instantiation.cc | 40 + .../20_util/is_signed/requirements/typedefs.cc | 37 + libstdc++-v3/testsuite/20_util/is_signed/value.cc | 61 + .../requirements/explicit_instantiation.cc | 40 + .../20_util/is_unsigned/requirements/typedefs.cc | 37 + .../testsuite/20_util/is_unsigned/value.cc | 61 + .../make_signed/requirements/typedefs_neg.cc | 4 +- .../make_unsigned/requirements/typedefs_neg.cc | 4 +- .../tuple/requirements/explicit_instantiation.cc | 2 +- libstdc++-v3/testsuite/tr1/headers.cc | 64 - libstdc++-v3/testsuite/tr1/headers/all.cc | 64 + .../tr1/headers/c++200x/using_namespace_std_tr1.cc | 27 + .../tr1/headers/using_namespace_std_tr1.cc | 26 + .../testsuite/tr1/using_namespace_std_tr1.cc | 26 - 132 files changed, 18151 insertions(+), 15945 deletions(-) create mode 100644 libstdc++-v3/include/bits/functional_hash.h create mode 100644 libstdc++-v3/include/bits/hashtable.h delete mode 100644 libstdc++-v3/include/tr1/boost_shared_ptr.h delete mode 100644 libstdc++-v3/include/tr1/common.h delete mode 100644 libstdc++-v3/include/tr1/hashtable create mode 100644 libstdc++-v3/include/tr1/hashtable.h delete mode 100644 libstdc++-v3/include/tr1/hashtable_policy.h delete mode 100644 libstdc++-v3/include/tr1/random.tcc delete mode 100644 libstdc++-v3/include/tr1/type_traitsfwd.h create mode 100644 libstdc++-v3/include/tr1_impl/array create mode 100644 libstdc++-v3/include/tr1_impl/boost_shared_ptr.h create mode 100644 libstdc++-v3/include/tr1_impl/cctype create mode 100644 libstdc++-v3/include/tr1_impl/cfenv create mode 100644 libstdc++-v3/include/tr1_impl/cinttypes create mode 100644 libstdc++-v3/include/tr1_impl/cmath create mode 100644 libstdc++-v3/include/tr1_impl/complex create mode 100644 libstdc++-v3/include/tr1_impl/cstdint create mode 100644 libstdc++-v3/include/tr1_impl/cstdio create mode 100644 libstdc++-v3/include/tr1_impl/cstdlib create mode 100644 libstdc++-v3/include/tr1_impl/cwchar create mode 100644 libstdc++-v3/include/tr1_impl/cwctype create mode 100644 libstdc++-v3/include/tr1_impl/functional create mode 100644 libstdc++-v3/include/tr1_impl/functional_hash.h create mode 100644 libstdc++-v3/include/tr1_impl/hashtable create mode 100644 libstdc++-v3/include/tr1_impl/hashtable_policy.h create mode 100644 libstdc++-v3/include/tr1_impl/random create mode 100644 libstdc++-v3/include/tr1_impl/random.tcc create mode 100644 libstdc++-v3/include/tr1_impl/regex create mode 100644 libstdc++-v3/include/tr1_impl/tuple create mode 100644 libstdc++-v3/include/tr1_impl/type_traits create mode 100644 libstdc++-v3/include/tr1_impl/type_traitsfwd.h create mode 100644 libstdc++-v3/include/tr1_impl/unordered_map create mode 100644 libstdc++-v3/include/tr1_impl/unordered_set create mode 100644 libstdc++-v3/include/tr1_impl/utility create mode 100644 libstdc++-v3/testsuite/20_util/is_signed/requirements/explicit_instantiation.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_signed/requirements/typedefs.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_signed/value.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_unsigned/requirements/typedefs.cc create mode 100644 libstdc++-v3/testsuite/20_util/is_unsigned/value.cc delete mode 100644 libstdc++-v3/testsuite/tr1/headers.cc create mode 100644 libstdc++-v3/testsuite/tr1/headers/all.cc create mode 100644 libstdc++-v3/testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc create mode 100644 libstdc++-v3/testsuite/tr1/headers/using_namespace_std_tr1.cc delete mode 100644 libstdc++-v3/testsuite/tr1/using_namespace_std_tr1.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4259ef3..48d6f87 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,177 @@ 2007-05-31 Paolo Carlini + PR libstdc++/31426 + * include/bits/c++config: Remove namespace association bits + from tr1 to std. + + * include/ext/type_traits.h (__promote, __promote2, + __promote3, __promote4): Add. + + * include/bits/hashtable.h: New. + * include/bits/functional_hash.h: Likewise. + * include/tr1/hashtable.h: Likewise. + + * include/tr1_impl/random: New. + * include/tr1_impl/cinttypes: Likewise. + * include/tr1_impl/cstdlib: Likewise. + * include/tr1_impl/unordered_map: Likewise. + * include/tr1_impl/cstdio: Likewise. + * include/tr1_impl/boost_shared_ptr.h: Likewise. + * include/tr1_impl/cctype: Likewise. + * include/tr1_impl/random.tcc: Likewise. + * include/tr1_impl/tuple: Likewise. + * include/tr1_impl/functional_hash.h: Likewise. + * include/tr1_impl/hashtable: Likewise. + * include/tr1_impl/cmath: Likewise. + * include/tr1_impl/type_traitsfwd.h: Likewise. + * include/tr1_impl/hashtable_policy.h: Likewise. + * include/tr1_impl/cfenv: Likewise. + * include/tr1_impl/unordered_set: Likewise. + * include/tr1_impl/functional: Likewise. + * include/tr1_impl/utility: Likewise. + * include/tr1_impl/complex: Likewise. + * include/tr1_impl/type_traits: Likewise. + * include/tr1_impl/cwchar: Likewise. + * include/tr1_impl/cstdint: Likewise. + * include/tr1_impl/regex: Likewise. + * include/tr1_impl/array: Likewise. + * include/tr1_impl/cwctype: Likewise. + + * include/tr1/type_traitsfwd.h: Remove. + * include/tr1/boost_shared_ptr.h: Likewise. + * include/tr1/common.h: Likewise. + * include/tr1/hashtable: Likewise. + * include/tr1/hashtable_policy.h: Likewise. + * include/tr1/random.tcc: Likewise. + + * include/c_global/cinttypes: Include tr1_impl/cinttypes. + * include/c_global/cstdlib: Likewise for cstdlib. + * include/c_global/cstdio: Likewise for cstdio. + * include/c_global/cctype: Likewise for cctype. + * include/c_global/cmath: Likewise for cmath. + * include/c_global/cfenv: Likewise for cfenv. + * include/c_global/cwchar: Likewise for cwchar. + * include/c_global/cstdint: Likewise for cstdint. + * include/c_global/cwctype: Likewise for cwctype. + * include/tr1/cinttypes: Likewise for cinttypes. + * include/tr1/cstdlib: Likewise for cstdlib. + * include/tr1/cstdio: Likewise for cstdio. + * include/tr1/cctype: Likewise for cctype. + * include/tr1/cmath: Likewise for cmath. + * include/tr1/cfenv: Likewise for cfenv. + * include/tr1/cwchar: Likewise for cwchar. + * include/tr1/cstdint: Likewise for cstdint. + * include/tr1/cwctype: Likewise for cwctype. + * include/tr1/functional_hash.h: Likewise for functional_hash. + + * include/std/tuple: Include tr1_impl/tuple. + * include/std/utility: Likewise for utility. + * include/std/type_traits: Likewise for type_traits. + (is_pod): Just forward to __is_pod. + (has_trivial_default_constructor): Just forward to + __has_trivial_constructor. + (has_trivial_copy_constructor): Just forward to __has_trivial_copy. + (has_trivial_assign): Just forward to __has_trivial_assign. + (has_trivial_destructor): Just forward to __has_trivial_destructor. + (has_nothrow_default_constructor): Just forward to + __has_nothrow_constructor. + (has_nothrow_copy_constructor): Just forward to __has_nothrow_copy. + (has_nothrow_assign): Just forward to __has_nothrow_assign. + (is_base_of): Just forward to __is_base_of. + (is_signed, is_unsigned): Implement according to the C++0x + specifications. + * include/std/memory: Likewise for memory. + * include/std/regex: Likewise for regex. + * include/std/random: Likewise for random. + * include/std/unordered_map: Likewise for unordered_map. + * include/std/unordered_set: Likewise for unordered_set. + * include/std/functional: Likewise for functional. + * include/std/complex: Likewise for complex. + * include/std/array: Likewise for array. + * include/tr1/tuple: Likewise for tuple. + * include/tr1/utility: Likewise for utility. + * include/tr1/type_traits: Likewise for type_traits + * include/tr1/memory: Likewise for memory. + * include/tr1/regex: Likewise for regex. + * include/tr1/random: Likewise for random. + * include/tr1/unordered_map: Likewise for unordered_map. + * include/tr1/unordered_set: Likewise for unordered_set. + * include/tr1/functional: Likewise for functional. + * include/tr1/complex: Likewise for complex. + * include/tr1/array: Likewise for array. + + * include/c_global/ctgmath: Tweak. + * include/c_global/cstdarg: Likewise. + * include/c_global/ctime: Likewise. + * include/c_global/climits: Likewise. + * include/c_global/cfloat: Likewise. + * include/c_global/ccomplex: Likewise. + * include/c_global/cstdbool: Likewise. + + * include/tr1/poly_laguerre.tcc: Tweak, don't use _GLIBCXX_TR1. + * include/tr1/riemann_zeta.tcc: Likewise. + * include/tr1/beta_function.tcc: Likewise. + * include/tr1/exp_integral.tcc: Likewise. + * include/tr1/hypergeometric.tcc: Likewise. + * include/tr1/modified_bessel_func.tcc: Likewise. + * include/tr1/legendre_function.tcc: Likewise. + * include/tr1/special_function_util.h: Likewise. + * include/tr1/bessel_function.tcc: Likewise. + * include/tr1/poly_hermite.tcc: Likewise. + * include/tr1/ell_integral.tcc: Likewise. + * include/tr1/gamma.tcc: Likewise. + * include/tr1/stdlib.h: Likewise. + * include/tr1/math.h: Likewise. + + * include/tr1/complex.h: Minor tweaks. + * include/tr1/wctype.h: Likewise. + * include/tr1/wchar.h: Likewise. + * include/tr1/inttypes.h: Likewise. + * include/tr1/tgmath.h: Likewise. + * include/tr1/cstdbool: Likewise. + * include/tr1/cfloat: Likewise. + * include/tr1/ccomplex: Likewise. + * include/tr1/ctime: Likewise. + * include/tr1/climits: Likewise. + * include/tr1/ctgmath: Likewise. + * include/tr1/cstdarg: Likewise. + + * testsuite/tr1/headers.cc: Move... + * testsuite/tr1/headers/all.cc: ... here. + * testsuite/tr1/using_namespace_std_tr1.cc: Move... + * testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc: ... here. + * testsuite/tr1/headers/using_namespace_std_tr1.cc ... here. + * testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc: New. + + * testsuite/20_util/tuple/requirements/explicit_instantiation.cc: + Adjust namespace. + * testsuite/20_util/has_nothrow_copy_constructor/value.cc: Adjust to + the C++0x requirements. + * testsuite/20_util/has_nothrow_default_constructor/value.cc: Likewise. + * testsuite/20_util/has_trivial_copy_constructor/value.cc: Likewise. + * testsuite/20_util/has_trivial_default_constructor/value.cc: Likewise. + + * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust + dg-error lines. + * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: + Likewise. + * testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc: + Un-xfail. + + * testsuite/20_util/is_signed/value.cc: New. + * testsuite/20_util/is_signed/requirements/typedefs.cc: Likewise. + * testsuite/20_util/is_signed/requirements/explicit_instantiation.cc: + Likewise. + * testsuite/20_util/is_unsigned/value.cc: Likewise.. + * testsuite/20_util/is_unsigned/requirements/typedefs.cc: Likewise. + * testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc: + Likewise. + + * include/Makefile.am: Adjust. + * include/Makefile.in: Regenerate. + +2007-05-31 Paolo Carlini + PR c++/32158 (libstdc++ bits) * include/bits/stl_uninitialized.h (__uninitialized_copy_aux, __uninitialized_fill_aux, __uninitialized_fill_n_aux): diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index cfa995e..406b313 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -82,8 +82,10 @@ bits_headers = \ ${bits_srcdir}/deque.tcc \ ${bits_srcdir}/fstream.tcc \ ${bits_srcdir}/functexcept.h \ + ${bits_srcdir}/functional_hash.h \ ${bits_srcdir}/gslice.h \ ${bits_srcdir}/gslice_array.h \ + ${bits_srcdir}/hashtable.h \ ${bits_srcdir}/indirect_array.h \ ${bits_srcdir}/ios_base.h \ ${bits_srcdir}/istream.tcc \ @@ -540,7 +542,6 @@ tr1_headers = \ ${tr1_srcdir}/array \ ${tr1_srcdir}/bessel_function.tcc \ ${tr1_srcdir}/beta_function.tcc \ - ${tr1_srcdir}/boost_shared_ptr.h \ ${tr1_srcdir}/ccomplex \ ${tr1_srcdir}/cctype \ ${tr1_srcdir}/cfenv \ @@ -548,7 +549,6 @@ tr1_headers = \ ${tr1_srcdir}/cinttypes \ ${tr1_srcdir}/climits \ ${tr1_srcdir}/cmath \ - ${tr1_srcdir}/common.h \ ${tr1_srcdir}/complex \ ${tr1_srcdir}/complex.h \ ${tr1_srcdir}/cstdarg \ @@ -568,9 +568,8 @@ tr1_headers = \ ${tr1_srcdir}/functional \ ${tr1_srcdir}/functional_hash.h \ ${tr1_srcdir}/gamma.tcc \ - ${tr1_srcdir}/hashtable \ ${tr1_srcdir}/hypergeometric.tcc \ - ${tr1_srcdir}/hashtable_policy.h \ + ${tr1_srcdir}/hashtable.h \ ${tr1_srcdir}/inttypes.h \ ${tr1_srcdir}/limits.h \ ${tr1_srcdir}/math.h \ @@ -580,7 +579,6 @@ tr1_headers = \ ${tr1_srcdir}/poly_laguerre.tcc \ ${tr1_srcdir}/legendre_function.tcc \ ${tr1_srcdir}/random \ - ${tr1_srcdir}/random.tcc \ ${tr1_srcdir}/regex \ ${tr1_srcdir}/riemann_zeta.tcc \ ${tr1_srcdir}/special_function_util.h \ @@ -592,7 +590,6 @@ tr1_headers = \ ${tr1_srcdir}/tgmath.h \ ${tr1_srcdir}/tuple \ ${tr1_srcdir}/type_traits \ - ${tr1_srcdir}/type_traitsfwd.h \ ${tr1_srcdir}/unordered_set \ ${tr1_srcdir}/unordered_map \ ${tr1_srcdir}/utility \ @@ -600,6 +597,36 @@ tr1_headers = \ ${tr1_srcdir}/wctype.h +tr1_impl_srcdir = ${glibcxx_srcdir}/include/tr1_impl +tr1_impl_builddir = ./tr1_impl +tr1_impl_headers = \ + ${tr1_impl_srcdir}/array \ + ${tr1_impl_srcdir}/boost_shared_ptr.h \ + ${tr1_impl_srcdir}/cctype \ + ${tr1_impl_srcdir}/cfenv \ + ${tr1_impl_srcdir}/cinttypes \ + ${tr1_impl_srcdir}/cmath \ + ${tr1_impl_srcdir}/complex \ + ${tr1_impl_srcdir}/cstdint \ + ${tr1_impl_srcdir}/cstdio \ + ${tr1_impl_srcdir}/cstdlib \ + ${tr1_impl_srcdir}/cwchar \ + ${tr1_impl_srcdir}/cwctype \ + ${tr1_impl_srcdir}/functional \ + ${tr1_impl_srcdir}/functional_hash.h \ + ${tr1_impl_srcdir}/hashtable \ + ${tr1_impl_srcdir}/hashtable_policy.h \ + ${tr1_impl_srcdir}/random \ + ${tr1_impl_srcdir}/random.tcc \ + ${tr1_impl_srcdir}/regex \ + ${tr1_impl_srcdir}/tuple \ + ${tr1_impl_srcdir}/type_traits \ + ${tr1_impl_srcdir}/type_traitsfwd.h \ + ${tr1_impl_srcdir}/unordered_map \ + ${tr1_impl_srcdir}/unordered_set \ + ${tr1_impl_srcdir}/utility + + # This is the common subset of C++ files that all three "C" header models use. c_base_srcdir = $(C_INCLUDE_DIR) c_base_builddir = . @@ -793,7 +820,7 @@ endif allstamped = \ stamp-std stamp-bits stamp-c_base stamp-c_base_extra \ stamp-c_compatibility stamp-backward stamp-ext stamp-pb \ - stamp-tr1 stamp-debug stamp-host + stamp-tr1 stamp-tr1-impl stamp-debug stamp-host # List of all files that are created by explicit building, editing, or # catenation. @@ -932,6 +959,15 @@ stamp-tr1: ${tr1_headers} fi ;\ $(STAMP) stamp-tr1 +stamp-tr1-impl: ${tr1_impl_headers} + @if [ ! -d "${tr1_impl_builddir}" ]; then \ + mkdir -p ${tr1_impl_builddir} ;\ + fi ;\ + if [ ! -f stamp-tr1-impl ]; then \ + (cd ${tr1_impl_builddir} && $(LN_S) $? . || true) ;\ + fi ;\ + $(STAMP) stamp-tr1-impl + stamp-debug: ${debug_headers} @if [ ! -d "${debug_builddir}" ]; then \ mkdir -p ${debug_builddir} ;\ @@ -1158,6 +1194,9 @@ install-headers: $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir} for file in ${tr1_headers}; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done + $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_impl_builddir} + for file in ${tr1_impl_headers}; do \ + $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_impl_builddir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir} for file in ${c_base_headers}; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${c_base_builddir}; done @@ -1200,8 +1239,10 @@ clean-local: # developer tries to create them via make in the include build # directory. (This is more of an example of how this kind of rule can # be made.) -.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers) $(ext_headers) +.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers) $(tr1_impl_headers) + $(ext_headers) $(std_headers): ; @: $(c_base_headers): ; @: $(tr1_headers): ; @: +$(tr1_impl_headers): ; @: $(ext_headers): ; @: diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 5a807a0..bffba8d 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -327,8 +327,10 @@ bits_headers = \ ${bits_srcdir}/deque.tcc \ ${bits_srcdir}/fstream.tcc \ ${bits_srcdir}/functexcept.h \ + ${bits_srcdir}/functional_hash.h \ ${bits_srcdir}/gslice.h \ ${bits_srcdir}/gslice_array.h \ + ${bits_srcdir}/hashtable.h \ ${bits_srcdir}/indirect_array.h \ ${bits_srcdir}/ios_base.h \ ${bits_srcdir}/istream.tcc \ @@ -781,7 +783,6 @@ tr1_headers = \ ${tr1_srcdir}/array \ ${tr1_srcdir}/bessel_function.tcc \ ${tr1_srcdir}/beta_function.tcc \ - ${tr1_srcdir}/boost_shared_ptr.h \ ${tr1_srcdir}/ccomplex \ ${tr1_srcdir}/cctype \ ${tr1_srcdir}/cfenv \ @@ -789,7 +790,6 @@ tr1_headers = \ ${tr1_srcdir}/cinttypes \ ${tr1_srcdir}/climits \ ${tr1_srcdir}/cmath \ - ${tr1_srcdir}/common.h \ ${tr1_srcdir}/complex \ ${tr1_srcdir}/complex.h \ ${tr1_srcdir}/cstdarg \ @@ -809,9 +809,8 @@ tr1_headers = \ ${tr1_srcdir}/functional \ ${tr1_srcdir}/functional_hash.h \ ${tr1_srcdir}/gamma.tcc \ - ${tr1_srcdir}/hashtable \ ${tr1_srcdir}/hypergeometric.tcc \ - ${tr1_srcdir}/hashtable_policy.h \ + ${tr1_srcdir}/hashtable.h \ ${tr1_srcdir}/inttypes.h \ ${tr1_srcdir}/limits.h \ ${tr1_srcdir}/math.h \ @@ -821,7 +820,6 @@ tr1_headers = \ ${tr1_srcdir}/poly_laguerre.tcc \ ${tr1_srcdir}/legendre_function.tcc \ ${tr1_srcdir}/random \ - ${tr1_srcdir}/random.tcc \ ${tr1_srcdir}/regex \ ${tr1_srcdir}/riemann_zeta.tcc \ ${tr1_srcdir}/special_function_util.h \ @@ -833,13 +831,41 @@ tr1_headers = \ ${tr1_srcdir}/tgmath.h \ ${tr1_srcdir}/tuple \ ${tr1_srcdir}/type_traits \ - ${tr1_srcdir}/type_traitsfwd.h \ ${tr1_srcdir}/unordered_set \ ${tr1_srcdir}/unordered_map \ ${tr1_srcdir}/utility \ ${tr1_srcdir}/wchar.h \ ${tr1_srcdir}/wctype.h +tr1_impl_srcdir = ${glibcxx_srcdir}/include/tr1_impl +tr1_impl_builddir = ./tr1_impl +tr1_impl_headers = \ + ${tr1_impl_srcdir}/array \ + ${tr1_impl_srcdir}/boost_shared_ptr.h \ + ${tr1_impl_srcdir}/cctype \ + ${tr1_impl_srcdir}/cfenv \ + ${tr1_impl_srcdir}/cinttypes \ + ${tr1_impl_srcdir}/cmath \ + ${tr1_impl_srcdir}/complex \ + ${tr1_impl_srcdir}/cstdint \ + ${tr1_impl_srcdir}/cstdio \ + ${tr1_impl_srcdir}/cstdlib \ + ${tr1_impl_srcdir}/cwchar \ + ${tr1_impl_srcdir}/cwctype \ + ${tr1_impl_srcdir}/functional \ + ${tr1_impl_srcdir}/functional_hash.h \ + ${tr1_impl_srcdir}/hashtable \ + ${tr1_impl_srcdir}/hashtable_policy.h \ + ${tr1_impl_srcdir}/random \ + ${tr1_impl_srcdir}/random.tcc \ + ${tr1_impl_srcdir}/regex \ + ${tr1_impl_srcdir}/tuple \ + ${tr1_impl_srcdir}/type_traits \ + ${tr1_impl_srcdir}/type_traitsfwd.h \ + ${tr1_impl_srcdir}/unordered_map \ + ${tr1_impl_srcdir}/unordered_set \ + ${tr1_impl_srcdir}/utility + # This is the common subset of C++ files that all three "C" header models use. c_base_srcdir = $(C_INCLUDE_DIR) @@ -1017,7 +1043,7 @@ PCHFLAGS = -Winvalid-pch -Wno-deprecated -x c++-header $(CXXFLAGS) allstamped = \ stamp-std stamp-bits stamp-c_base stamp-c_base_extra \ stamp-c_compatibility stamp-backward stamp-ext stamp-pb \ - stamp-tr1 stamp-debug stamp-host + stamp-tr1 stamp-tr1-impl stamp-debug stamp-host # List of all files that are created by explicit building, editing, or @@ -1326,6 +1352,15 @@ stamp-tr1: ${tr1_headers} fi ;\ $(STAMP) stamp-tr1 +stamp-tr1-impl: ${tr1_impl_headers} + @if [ ! -d "${tr1_impl_builddir}" ]; then \ + mkdir -p ${tr1_impl_builddir} ;\ + fi ;\ + if [ ! -f stamp-tr1-impl ]; then \ + (cd ${tr1_impl_builddir} && $(LN_S) $? . || true) ;\ + fi ;\ + $(STAMP) stamp-tr1-impl + stamp-debug: ${debug_headers} @if [ ! -d "${debug_builddir}" ]; then \ mkdir -p ${debug_builddir} ;\ @@ -1540,6 +1575,9 @@ install-headers: $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir} for file in ${tr1_headers}; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done + $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_impl_builddir} + for file in ${tr1_impl_headers}; do \ + $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_impl_builddir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir} for file in ${c_base_headers}; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${c_base_builddir}; done @@ -1579,10 +1617,12 @@ clean-local: # developer tries to create them via make in the include build # directory. (This is more of an example of how this kind of rule can # be made.) -.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers) $(ext_headers) +.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers) $(tr1_impl_headers) + $(ext_headers) $(std_headers): ; @: $(c_base_headers): ; @: $(tr1_headers): ; @: +$(tr1_impl_headers): ; @: $(ext_headers): ; @: # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index f4e951c..a519018 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -71,10 +71,6 @@ # define _GLIBCXX_NAMESPACE_ASSOCIATION_DEBUG 1 #endif -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# define _GLIBCXX_NAMESPACE_ASSOCIATION_CXX0X 1 -#endif - #define _GLIBCXX_NAMESPACE_ASSOCIATION_VERSION // Macros for namespace scope. @@ -155,18 +151,6 @@ namespace __gnu_cxx #endif #endif -// Namespace associations for C++0x, TR1 in std. -#if _GLIBCXX_NAMESPACE_ASSOCIATION_CXX0X -namespace std -{ - namespace __cxx200x { } - using namespace __cxx200x __attribute__ ((strong)); -} -# define _GLIBCXX_TR1 __cxx200x -#else -# define _GLIBCXX_TR1 tr1 -#endif - // Define if compatibility should be provided for -mlong-double-64. #undef _GLIBCXX_LONG_DOUBLE_COMPAT diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h new file mode 100644 index 0000000..022c5ca --- /dev/null +++ b/libstdc++-v3/include/bits/functional_hash.h @@ -0,0 +1,63 @@ +// functional_hash.h header -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file functional_hash.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#ifndef _FUNCTIONAL_HASH_H +#define _FUNCTIONAL_HASH_H 1 + +#pragma GCC system_header + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#endif + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif + +#endif // _FUNCTIONAL_HASH_H + diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h new file mode 100644 index 0000000..d1da5fdd --- /dev/null +++ b/libstdc++-v3/include/bits/hashtable.h @@ -0,0 +1,63 @@ +// hashtable.h header -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file hashtable.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#ifndef _HASHTABLE_H +#define _HASHTABLE_H 1 + +#pragma GCC system_header + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#endif + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif + +#endif // _HASHTABLE_H + diff --git a/libstdc++-v3/include/c_global/ccomplex b/libstdc++-v3/include/c_global/ccomplex index 1d08038..bd37e22 100644 --- a/libstdc++-v3/include/c_global/ccomplex +++ b/libstdc++-v3/include/c_global/ccomplex @@ -36,11 +36,14 @@ #ifndef _GLIBCXX_CCOMPLEX #define _GLIBCXX_CCOMPLEX 1 -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#endif diff --git a/libstdc++-v3/include/c_global/cctype b/libstdc++-v3/include/c_global/cctype index 05436e4..440245e 100644 --- a/libstdc++-v3/include/c_global/cctype +++ b/libstdc++-v3/include/c_global/cctype @@ -1,6 +1,7 @@ // -*- C++ -*- forwarding header. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -84,7 +85,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_END_NAMESPACE #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif diff --git a/libstdc++-v3/include/c_global/cfenv b/libstdc++-v3/include/c_global/cfenv index f11c531..de72ed4 100644 --- a/libstdc++-v3/include/c_global/cfenv +++ b/libstdc++-v3/include/c_global/cfenv @@ -36,11 +36,28 @@ #ifndef _GLIBCXX_CFENV #define _GLIBCXX_CFENV 1 -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif + +#endif diff --git a/libstdc++-v3/include/c_global/cfloat b/libstdc++-v3/include/c_global/cfloat index 9d8c039..a3edc2a 100644 --- a/libstdc++-v3/include/c_global/cfloat +++ b/libstdc++-v3/include/c_global/cfloat @@ -50,7 +50,15 @@ #define _GLIBCXX_CFLOAT 1 #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# ifndef DECIMAL_DIG +# define DECIMAL_DIG __DECIMAL_DIG__ +# endif +# ifndef FLT_EVAL_METHOD +# define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ +# endif #endif #endif diff --git a/libstdc++-v3/include/c_global/cinttypes b/libstdc++-v3/include/c_global/cinttypes index d42c7a3..8caceaf 100644 --- a/libstdc++-v3/include/c_global/cinttypes +++ b/libstdc++-v3/include/c_global/cinttypes @@ -36,11 +36,28 @@ #ifndef _GLIBCXX_CINTTYPES #define _GLIBCXX_CINTTYPES 1 -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif + +#endif diff --git a/libstdc++-v3/include/c_global/climits b/libstdc++-v3/include/c_global/climits index 396bbcb..910c80a 100644 --- a/libstdc++-v3/include/c_global/climits +++ b/libstdc++-v3/include/c_global/climits @@ -1,6 +1,7 @@ // -*- C++ -*- forwarding header. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -49,8 +50,16 @@ #ifndef _GLIBCXX_CLIMITS #define _GLIBCXX_CLIMITS 1 -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +#ifndef LLONG_MIN +#define LLONG_MIN -__LONG_LONG_MAX__ - 1 +#endif + +#ifndef LLONG_MAX +#define LLONG_MAX __LONG_LONG_MAX__ +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX __LONG_LONG_MAX__ * 2ULL + 1 #endif #endif diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index ab21c9a..dde0154 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -1,6 +1,7 @@ // -*- C++ -*- C forwarding header. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -82,7 +83,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Forward declaration of a helper function. This really should be // an `exported' forward declaration. - template _Tp __cmath_power(_Tp, unsigned int); + template + _Tp __cmath_power(_Tp, unsigned int); + + template + inline _Tp + __pow_helper(_Tp __x, int __n) + { + return __n < 0 + ? _Tp(1)/__cmath_power(__x, -__n) + : __cmath_power(__x, __n); + } inline double abs(double __x) @@ -123,8 +134,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __builtin_asinl(__x); } template - inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, - double>::__type + inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, + double>::__type asin(_Tp __x) { return __builtin_asin(__x); } @@ -139,8 +150,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __builtin_atanl(__x); } template - inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, - double>::__type + inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, + double>::__type atan(_Tp __x) { return __builtin_atan(__x); } @@ -155,11 +166,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __builtin_atan2l(__y, __x); } template - inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value - && __is_integer<_Up>::__value, - double>::__type + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type atan2(_Tp __y, _Up __x) - { return __builtin_atan2(__y, __x); } + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return atan2(__type(__y), __type(__x)); + } using ::ceil; @@ -341,15 +353,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) modf(long double __x, long double* __iptr) { return __builtin_modfl(__x, __iptr); } - template - inline _Tp - __pow_helper(_Tp __x, int __n) - { - return __n < 0 - ? _Tp(1)/__cmath_power(__x, -__n) - : __cmath_power(__x, __n); - } - using ::pow; inline float @@ -360,6 +363,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) pow(long double __x, long double __y) { return __builtin_powl(__x, __y); } + // DR 550. inline double pow(double __x, int __i) { return __builtin_powi(__x, __i); } @@ -372,6 +376,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) pow(long double __x, int __n) { return __builtin_powil(__x, __n); } + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + pow(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return pow(__type(__x), __type(__y)); + } + using ::sin; inline float @@ -597,7 +609,23 @@ _GLIBCXX_END_NAMESPACE #endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# include +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif diff --git a/libstdc++-v3/include/c_global/cstdarg b/libstdc++-v3/include/c_global/cstdarg index 9acd24e..21b4f7a 100644 --- a/libstdc++-v3/include/c_global/cstdarg +++ b/libstdc++-v3/include/c_global/cstdarg @@ -61,8 +61,4 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_END_NAMESPACE -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#endif - #endif diff --git a/libstdc++-v3/include/c_global/cstdbool b/libstdc++-v3/include/c_global/cstdbool index ac18c74..28dfa76 100644 --- a/libstdc++-v3/include/c_global/cstdbool +++ b/libstdc++-v3/include/c_global/cstdbool @@ -36,10 +36,13 @@ #ifndef _GLIBCXX_CSTDBOOL #define _GLIBCXX_CSTDBOOL 1 -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include #else -# include +# include +# if _GLIBCXX_HAVE_STDBOOL_H +# include_next +# endif #endif #endif diff --git a/libstdc++-v3/include/c_global/cstdint b/libstdc++-v3/include/c_global/cstdint index ece67a3..6c3f438 100644 --- a/libstdc++-v3/include/c_global/cstdint +++ b/libstdc++-v3/include/c_global/cstdint @@ -36,11 +36,28 @@ #ifndef _GLIBCXX_CSTDINT #define _GLIBCXX_CSTDINT 1 -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif + +#endif diff --git a/libstdc++-v3/include/c_global/cstdio b/libstdc++-v3/include/c_global/cstdio index ec25b99..3cdb5d6 100644 --- a/libstdc++-v3/include/c_global/cstdio +++ b/libstdc++-v3/include/c_global/cstdio @@ -1,6 +1,7 @@ // -*- C++ -*- forwarding header. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -188,7 +189,22 @@ _GLIBCXX_END_NAMESPACE #endif // _GLIBCXX_USE_C99 #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib index e4ab8f9..3386ff0 100644 --- a/libstdc++-v3/include/c_global/cstdlib +++ b/libstdc++-v3/include/c_global/cstdlib @@ -1,6 +1,7 @@ // -*- C++ -*- forwarding header. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -223,7 +224,22 @@ _GLIBCXX_END_NAMESPACE #endif // _GLIBCXX_USE_C99 #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif // !_GLIBCXX_HOSTED diff --git a/libstdc++-v3/include/c_global/ctgmath b/libstdc++-v3/include/c_global/ctgmath index 623ed9b..2f3d7d0 100644 --- a/libstdc++-v3/include/c_global/ctgmath +++ b/libstdc++-v3/include/c_global/ctgmath @@ -36,10 +36,10 @@ #ifndef _GLIBCXX_CTGMATH #define _GLIBCXX_CTGMATH 1 -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include #else -# include +# include #endif #endif diff --git a/libstdc++-v3/include/c_global/ctime b/libstdc++-v3/include/c_global/ctime index 8b563ba..915c2fc 100644 --- a/libstdc++-v3/include/c_global/ctime +++ b/libstdc++-v3/include/c_global/ctime @@ -1,6 +1,7 @@ // -*- C++ -*- forwarding header. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -79,8 +80,4 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_END_NAMESPACE -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#endif - #endif diff --git a/libstdc++-v3/include/c_global/cwchar b/libstdc++-v3/include/c_global/cwchar index c49ebbd..92bca61 100644 --- a/libstdc++-v3/include/c_global/cwchar +++ b/libstdc++-v3/include/c_global/cwchar @@ -278,7 +278,22 @@ _GLIBCXX_END_NAMESPACE #endif //_GLIBCXX_USE_WCHAR_T #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif diff --git a/libstdc++-v3/include/c_global/cwctype b/libstdc++-v3/include/c_global/cwctype index 5c8d598..d2f2d77 100644 --- a/libstdc++-v3/include/c_global/cwctype +++ b/libstdc++-v3/include/c_global/cwctype @@ -1,6 +1,7 @@ // -*- C++ -*- forwarding header. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -109,7 +110,22 @@ _GLIBCXX_END_NAMESPACE #endif //_GLIBCXX_USE_WCHAR_T #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif diff --git a/libstdc++-v3/include/ext/type_traits.h b/libstdc++-v3/include/ext/type_traits.h index 8a896fa..746d866 100644 --- a/libstdc++-v3/include/ext/type_traits.h +++ b/libstdc++-v3/include/ext/type_traits.h @@ -159,6 +159,52 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) __is_null_pointer(_Type) { return false; } + + // For complex and cmath + template::__value> + struct __promote + { typedef double __type; }; + + template + struct __promote<_Tp, false> + { typedef _Tp __type; }; + + template + struct __promote_2 + { + private: + typedef typename __promote<_Tp>::__type __type1; + typedef typename __promote<_Up>::__type __type2; + + public: + typedef __typeof__(__type1() + __type2()) __type; + }; + + template + struct __promote_3 + { + private: + typedef typename __promote<_Tp>::__type __type1; + typedef typename __promote<_Up>::__type __type2; + typedef typename __promote<_Vp>::__type __type3; + + public: + typedef __typeof__(__type1() + __type2() + __type3()) __type; + }; + + template + struct __promote_4 + { + private: + typedef typename __promote<_Tp>::__type __type1; + typedef typename __promote<_Up>::__type __type2; + typedef typename __promote<_Vp>::__type __type3; + typedef typename __promote<_Wp>::__type __type4; + + public: + typedef __typeof__(__type1() + __type2() + __type3() + __type4()) __type; + }; + _GLIBCXX_END_NAMESPACE #endif diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index 5ca26046..691f41c 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -31,16 +31,33 @@ * This is a Standard C++ Library header. */ -#ifndef _GLIBCXX_ARRAY -#define _GLIBCXX_ARRAY 1 +#ifndef _GLIBCXX_CXX0X_ARRAY +#define _GLIBCXX_CXX0X_ARRAY 1 #pragma GCC system_header -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif +#endif // _GLIBCXX_CXX0X_ARRAY diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex index 04a6c69..61d3580 100644 --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -1508,8 +1509,50 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_END_NAMESPACE +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + + // See ext/type_traits.h for the primary template. + template + struct __promote_2, _Up> + { + public: + typedef std::complex::__type> __type; + }; + + template + struct __promote_2<_Tp, std::complex<_Up> > + { + public: + typedef std::complex::__type> __type; + }; + + template + struct __promote_2, std::complex<_Up> > + { + public: + typedef std::complex::__type> __type; + }; + +_GLIBCXX_END_NAMESPACE + #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# include +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif /* _GLIBCXX_COMPLEX */ diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 33bab64..27e8817 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -55,7 +55,29 @@ #include #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# include +# include +# include +# include +# include +# include +# include +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif -#endif /* _GLIBCXX_FUNCTIONAL */ +#endif // _GLIBCXX_FUNCTIONAL diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory index 28b8d85..c48a5c3 100644 --- a/libstdc++-v3/include/std/memory +++ b/libstdc++-v3/include/std/memory @@ -60,7 +60,33 @@ #include #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# include // std::exception +# include // std::bad_alloc +# include // std::type_info in get_deleter +# include // std::swap +# include // std::basic_ostream +# include +# include +# include +# include // std::less +# include +# include +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif /* _GLIBCXX_MEMORY */ diff --git a/libstdc++-v3/include/std/random b/libstdc++-v3/include/std/random index 6faf5f5..2fccb60 100644 --- a/libstdc++-v3/include/std/random +++ b/libstdc++-v3/include/std/random @@ -36,11 +36,38 @@ #pragma GCC system_header -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif +#endif // _GLIBCXX_RANDOM diff --git a/libstdc++-v3/include/std/regex b/libstdc++-v3/include/std/regex index 4b4e482..5c25718 100644 --- a/libstdc++-v3/include/std/regex +++ b/libstdc++-v3/include/std/regex @@ -31,16 +31,40 @@ * This is a Standard C++ Library header. */ -#ifndef _GLIBCXX_REGEX -#define _GLIBCXX_REGEX 1 +#ifndef _GLIBCXX_CXX0X_REGEX +#define _GLIBCXX_CXX0X_REGEX 1 #pragma GCC system_header -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif +#endif // _GLIBCXX_CXX0X_REGEX diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 7ea9aff..94e7ef5 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -31,16 +31,33 @@ * This is a Standard C++ Library header. */ -#ifndef _GLIBCXX_TUPLE -#define _GLIBCXX_TUPLE 1 +#ifndef _GLIBCXX_CXX0X_TUPLE +#define _GLIBCXX_CXX0X_TUPLE 1 #pragma GCC system_header -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif +#endif // _GLIBCXX_CXX0X_TUPLE diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 6806ebc..8dbfb56 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -31,18 +31,159 @@ * This is a Standard C++ Library header. */ -#ifndef _GLIBCXX_TYPE_TRAITS -#define _GLIBCXX_TYPE_TRAITS 1 +#ifndef _GLIBCXX_CXX0X_TYPE_TRAITS +#define _GLIBCXX_CXX0X_TYPE_TRAITS 1 #pragma GCC system_header -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -_GLIBCXX_BEGIN_NAMESPACE(std) +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif + +namespace std +{ + template::value, + bool = is_floating_point<_Tp>::value> + struct __is_signed_helper + : public false_type { }; + + template + struct __is_signed_helper<_Tp, false, true> + : public true_type { }; + + template + struct __is_signed_helper<_Tp, true, false> + : public integral_constant + { }; + + template + struct is_signed + : public integral_constant::value> + { }; + + template + struct is_unsigned + : public integral_constant::value + && !is_signed<_Tp>::value)> + { }; + + template + struct is_pod + : public integral_constant + { }; + + template + struct has_trivial_default_constructor + : public integral_constant + { }; + + template + struct has_trivial_copy_constructor + : public integral_constant + { }; + + template + struct has_trivial_assign + : public integral_constant + { }; + + template + struct has_trivial_destructor + : public integral_constant + { }; + + template + struct has_nothrow_default_constructor + : public integral_constant + { }; + + template + struct has_nothrow_copy_constructor + : public integral_constant + { }; + + template + struct has_nothrow_assign + : public integral_constant + { }; + + template + struct is_base_of + : public integral_constant + { }; + + // XXX FIXME + // The C++0x specifications are different, see N2255. + template + struct __is_convertible_simple + : public __sfinae_types + { + private: + static __one __test(_To); + static __two __test(...); + static _From __makeFrom(); + + public: + static const bool __value = sizeof(__test(__makeFrom())) == 1; + }; + + template + struct __is_int_or_cref + { + typedef typename remove_reference<_Tp>::type __rr_Tp; + static const bool __value = (is_integral<_Tp>::value + || (is_integral<__rr_Tp>::value + && is_const<__rr_Tp>::value + && !is_volatile<__rr_Tp>::value)); + }; + + template::value || is_void<_To>::value + || is_function<_To>::value || is_array<_To>::value + // This special case is here only to avoid warnings. + || (is_floating_point::type>::value + && __is_int_or_cref<_To>::__value))> + struct __is_convertible_helper + { + // "An imaginary lvalue of type From...". + static const bool __value = (__is_convertible_simple::type, _To>::__value); + }; + + template + struct __is_convertible_helper<_From, _To, true> + { static const bool __value = (is_void<_To>::value + || (__is_int_or_cref<_To>::__value + && !is_void<_From>::value)); }; + + template + struct is_convertible + : public integral_constant::__value> + { }; + // Define a nested type if some predicate holds. template @@ -131,7 +272,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Utility for finding the unsigned versions of signed integral types. template - struct __make_unsigned; + struct __make_unsigned + { typedef _Tp __type; }; template<> struct __make_unsigned @@ -165,16 +307,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Select between integral and enum: not possible to be both. template::value, - bool _IsUnsigned = is_unsigned<_Tp>::value, bool _IsEnum = is_enum<_Tp>::value> struct __make_unsigned_selector; template - struct __make_unsigned_selector<_Tp, true, true, false> - { typedef _Tp __type; }; - - template - struct __make_unsigned_selector<_Tp, true, false, false> + struct __make_unsigned_selector<_Tp, true, false> { private: typedef __make_unsigned::type> __unsignedt; @@ -186,7 +323,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) }; template - struct __make_unsigned_selector<_Tp, false, false, true> + struct __make_unsigned_selector<_Tp, false, true> { private: // GNU enums start with sizeof short. @@ -214,7 +351,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Utility for finding the signed versions of unsigned integral types. template - struct __make_signed; + struct __make_signed + { typedef _Tp __type; }; template<> struct __make_signed @@ -248,16 +386,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Select between integral and enum: not possible to be both. template::value, - bool _IsSigned = is_signed<_Tp>::value, bool _IsEnum = is_enum<_Tp>::value> struct __make_signed_selector; template - struct __make_signed_selector<_Tp, true, true, false> - { typedef _Tp __type; }; - - template - struct __make_signed_selector<_Tp, true, false, false> + struct __make_signed_selector<_Tp, true, false> { private: typedef __make_signed::type> __signedt; @@ -269,7 +402,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) }; template - struct __make_signed_selector<_Tp, false, false, true> + struct __make_signed_selector<_Tp, false, true> { private: // GNU enums start with sizeof short. @@ -293,25 +426,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Integral, but don't define. template<> struct make_signed; +} - - template - struct has_nothrow_default_constructor - : public integral_constant::value> { }; - - template - struct has_nothrow_copy_constructor - : public integral_constant::value> { }; - - template - struct has_trivial_default_constructor - : public integral_constant::value> { }; - - template - struct has_trivial_copy_constructor - : public integral_constant::value> { }; - -_GLIBCXX_END_NAMESPACE - -#endif +#endif // _GLIBCXX_CXX0X_TYPE_TRAITS diff --git a/libstdc++-v3/include/std/unordered_map b/libstdc++-v3/include/std/unordered_map index 9eee766..016d3ea 100644 --- a/libstdc++-v3/include/std/unordered_map +++ b/libstdc++-v3/include/std/unordered_map @@ -36,11 +36,36 @@ #pragma GCC system_header -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#include +#include +#include // lower_bound +#include +#include // equal_to, _Identity, _Select1st +#include +#include +#include + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif +#endif // _GLIBCXX_UNORDERED_MAP diff --git a/libstdc++-v3/include/std/unordered_set b/libstdc++-v3/include/std/unordered_set index d83cfa3..dba7816 100644 --- a/libstdc++-v3/include/std/unordered_set +++ b/libstdc++-v3/include/std/unordered_set @@ -36,11 +36,36 @@ #pragma GCC system_header -#ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include -#else +#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif -#endif +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +#endif + +#include +#include +#include +#include // lower_bound +#include +#include // equal_to, _Identity, _Select1st +#include +#include +#include + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +#else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +#endif +#endif // _GLIBCXX_UNORDERED_SET diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index c17b355..21440e5 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -67,7 +67,22 @@ #include #ifdef __GXX_EXPERIMENTAL_CXX0X__ -# include +# if defined(_GLIBCXX_INCLUDE_AS_TR1) +# error C++0x header cannot be included from TR1 header +# endif +# if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# include +# else +# define _GLIBCXX_INCLUDE_AS_CXX0X +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 +# define _GLIBCXX_END_NAMESPACE_TR1 +# define _GLIBCXX_TR1 +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_CXX0X +# endif #endif #endif /* _GLIBCXX_UTILITY */ diff --git a/libstdc++-v3/include/tr1/array b/libstdc++-v3/include/tr1/array index 34508df..cca9520 100644 --- a/libstdc++-v3/include/tr1/array +++ b/libstdc++-v3/include/tr1/array @@ -31,216 +31,29 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_ARRAY -#define _TR1_ARRAY 1 +#ifndef _GLIBCXX_TR1_ARRAY +#define _GLIBCXX_TR1_ARRAY 1 -#include - -//namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - /// @brief struct array [6.2.2]. - /// NB: Requires complete type _Tp. - template - struct array - { - typedef _Tp value_type; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* iterator; - typedef const value_type* const_iterator; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; - - // Support for zero-sized arrays mandatory. - value_type _M_instance[_Nm ? _Nm : 1] __attribute__((__aligned__)); - - // No explicit construct/copy/destroy for aggregate type. - - void - assign(const value_type& __u) - { std::fill_n(begin(), size(), __u); } - - void - swap(array& __other) - { std::swap_ranges(begin(), end(), __other.begin()); } - - // Iterators. - iterator - begin() - { return iterator(&_M_instance[0]); } - - const_iterator - begin() const - { return const_iterator(&_M_instance[0]); } - - iterator - end() - { return iterator(&_M_instance[_Nm]); } - - const_iterator - end() const - { return const_iterator(&_M_instance[_Nm]); } - - reverse_iterator - rbegin() - { return reverse_iterator(end()); } - - const_reverse_iterator - rbegin() const - { return const_reverse_iterator(end()); } - - reverse_iterator - rend() - { return reverse_iterator(begin()); } - - const_reverse_iterator - rend() const - { return const_reverse_iterator(begin()); } - - // Capacity. - size_type - size() const { return _Nm; } - - size_type - max_size() const { return _Nm; } - - bool - empty() const { return size() == 0; } - - // Element access. - reference - operator[](size_type __n) - { return _M_instance[__n]; } - - const_reference - operator[](size_type __n) const - { return _M_instance[__n]; } - - reference - at(size_type __n) - { - _M_check<_Nm>(__n); - return _M_instance[__n]; - } - - const_reference - at(size_type __n) const - { - _M_check<_Nm>(__n); - return _M_instance[__n]; - } - - reference - front() - { return *begin(); } +#pragma GCC system_header - const_reference - front() const - { return *begin(); } - - reference - back() - { return _Nm ? *(end() - 1) : *end(); } - - const_reference - back() const - { return _Nm ? *(end() - 1) : *end(); } - - _Tp* - data() - { return &_M_instance[0]; } - - const _Tp* - data() const - { return &_M_instance[0]; } - - private: - template - typename __gnu_cxx::__enable_if<_Mm, void>::__type - _M_check(size_type __n) const - { - if (__builtin_expect(__n >= _Mm, false)) - std::__throw_out_of_range(__N("array::_M_check")); - } - - // Avoid "unsigned comparison with zero" warnings. - template - typename __gnu_cxx::__enable_if::__type - _M_check(size_type) const - { std::__throw_out_of_range(__N("array::_M_check")); } - }; - - // Array comparisons. - template - inline bool - operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return std::equal(__one.begin(), __one.end(), __two.begin()); } - - template - inline bool - operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return !(__one == __two); } - - template - inline bool - operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) - { - return std::lexicographical_compare(__a.begin(), __a.end(), - __b.begin(), __b.end()); - } - - template - inline bool - operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return __two < __one; } - - template - inline bool - operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return !(__one > __two); } - - template - inline bool - operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) - { return !(__one < __two); } - - // Specialized algorithms [6.2.2.2]. - template - inline void - swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) - { std::swap_ranges(__one.begin(), __one.end(), __two.begin()); } - - // Tuple interface to class template array [6.2.2.5]. - template class tuple_size; - template class tuple_element; - - template - struct tuple_size > - { static const int value = _Nm; }; - - template - const int tuple_size >::value; - - template - struct tuple_element<_Int, array<_Tp, _Nm> > - { typedef _Tp type; }; - - template - inline _Tp& - get(array<_Tp, _Nm>& __arr) - { return __arr[_Int]; } - - template - inline const _Tp& - get(const array<_Tp, _Nm>& __arr) - { return __arr[_Int]; } +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif -_GLIBCXX_END_NAMESPACE -} +#include +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif + +#endif // _GLIBCXX_TR1_ARRAY diff --git a/libstdc++-v3/include/tr1/bessel_function.tcc b/libstdc++-v3/include/tr1/bessel_function.tcc index 68ca9a3..eebafac4 100644 --- a/libstdc++-v3/include/tr1/bessel_function.tcc +++ b/libstdc++-v3/include/tr1/bessel_function.tcc @@ -49,14 +49,15 @@ // W. T. Vetterling, B. P. Flannery, Cambridge University Press (1992), // 2nd ed, pp. 240-245 -#ifndef _TR1_BESSEL_FUNCTION_TCC -#define _TR1_BESSEL_FUNCTION_TCC 1 +#ifndef _GLIBCXX_TR1_BESSEL_FUNCTION_TCC +#define _GLIBCXX_TR1_BESSEL_FUNCTION_TCC 1 #include "special_function_util.h" namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -102,8 +103,8 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) _Tp & __gam1, _Tp & __gam2, _Tp & __gampl, _Tp & __gammi) { #if _GLIBCXX_USE_C99_MATH_TR1 - __gampl = _Tp(1) / std::_GLIBCXX_TR1::tgamma(_Tp(1) + __mu); - __gammi = _Tp(1) / std::_GLIBCXX_TR1::tgamma(_Tp(1) - __mu); + __gampl = _Tp(1) / std::tr1::tgamma(_Tp(1) + __mu); + __gammi = _Tp(1) / std::tr1::tgamma(_Tp(1) - __mu); #else __gampl = _Tp(1) / __gamma(_Tp(1) + __mu); __gammi = _Tp(1) / __gamma(_Tp(1) - __mu); @@ -318,7 +319,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) const _Tp __gam = (__p - __f) / __q; __Jmu = std::sqrt(__w / ((__p - __f) * __gam + __q)); #if _GLIBCXX_USE_C99_MATH_TR1 - __Jmu = std::_GLIBCXX_TR1::copysign(__Jmu, __Jnul); + __Jmu = std::tr1::copysign(__Jmu, __Jnul); #else if (__Jmu * __Jnul < _Tp(0)) __Jmu = -__Jmu; @@ -425,7 +426,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) const _Tp __x2 = __x / _Tp(2); _Tp __fact = __nu * std::log(__x2); #if _GLIBCXX_USE_C99_MATH_TR1 - __fact -= std::_GLIBCXX_TR1::lgamma(__nu + _Tp(1)); + __fact -= std::tr1::lgamma(__nu + _Tp(1)); #else __fact -= __log_gamma(__nu + _Tp(1)); #endif @@ -635,7 +636,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_BESSEL_FUNCTION_TCC +#endif // _GLIBCXX_TR1_BESSEL_FUNCTION_TCC diff --git a/libstdc++-v3/include/tr1/beta_function.tcc b/libstdc++-v3/include/tr1/beta_function.tcc index a460117..537947e 100644 --- a/libstdc++-v3/include/tr1/beta_function.tcc +++ b/libstdc++-v3/include/tr1/beta_function.tcc @@ -49,12 +49,13 @@ // (4) Gamma, Exploring Euler's Constant, Julian Havil, // Princeton, 2003. -#ifndef _TR1_BETA_FUNCTION_TCC -#define _TR1_BETA_FUNCTION_TCC 1 +#ifndef _GLIBCXX_TR1_BETA_FUNCTION_TCC +#define _GLIBCXX_TR1_BETA_FUNCTION_TCC 1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -90,15 +91,15 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) #if _GLIBCXX_USE_C99_MATH_TR1 if (__x > __y) { - __bet = std::_GLIBCXX_TR1::tgamma(__x) - / std::_GLIBCXX_TR1::tgamma(__x + __y); - __bet *= std::_GLIBCXX_TR1::tgamma(__y); + __bet = std::tr1::tgamma(__x) + / std::tr1::tgamma(__x + __y); + __bet *= std::tr1::tgamma(__y); } else { - __bet = std::_GLIBCXX_TR1::tgamma(__y) - / std::_GLIBCXX_TR1::tgamma(__x + __y); - __bet *= std::_GLIBCXX_TR1::tgamma(__x); + __bet = std::tr1::tgamma(__y) + / std::tr1::tgamma(__x + __y); + __bet *= std::tr1::tgamma(__x); } #else if (__x > __y) @@ -134,9 +135,9 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) __beta_lgamma(_Tp __x, _Tp __y) { #if _GLIBCXX_USE_C99_MATH_TR1 - _Tp __bet = std::_GLIBCXX_TR1::lgamma(__x) - + std::_GLIBCXX_TR1::lgamma(__y) - - std::_GLIBCXX_TR1::lgamma(__x + __y); + _Tp __bet = std::tr1::lgamma(__x) + + std::tr1::lgamma(__y) + - std::tr1::lgamma(__x + __y); #else _Tp __bet = __log_gamma(__x) + __log_gamma(__y) @@ -205,7 +206,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_BETA_FUNCTION_TCC +#endif // __GLIBCXX_TR1_BETA_FUNCTION_TCC diff --git a/libstdc++-v3/include/tr1/boost_shared_ptr.h b/libstdc++-v3/include/tr1/boost_shared_ptr.h deleted file mode 100644 index 0e56af5..0000000 --- a/libstdc++-v3/include/tr1/boost_shared_ptr.h +++ /dev/null @@ -1,1147 +0,0 @@ -// -*- C++ -*- - -// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -// shared_count.hpp -// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. - -// shared_ptr.hpp -// Copyright (C) 1998, 1999 Greg Colvin and Beman Dawes. -// Copyright (C) 2001, 2002, 2003 Peter Dimov - -// weak_ptr.hpp -// Copyright (C) 2001, 2002, 2003 Peter Dimov - -// enable_shared_from_this.hpp -// Copyright (C) 2002 Peter Dimov - -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// GCC Note: based on version 1.32.0 of the Boost library. - -/** @file tr1/boost_shared_ptr.h - * This is an internal header file, included by other library headers. - * You should not attempt to use it directly. - */ - -#ifndef _BOOST_SHARED_PTR_H -#define _BOOST_SHARED_PTR_H 1 - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - class bad_weak_ptr : public std::exception - { - public: - virtual char const* - what() const throw() - { return "tr1::bad_weak_ptr"; } - }; - - // Substitute for bad_weak_ptr object in the case of -fno-exceptions. - inline void - __throw_bad_weak_ptr() - { -#if __EXCEPTIONS - throw bad_weak_ptr(); -#else - __builtin_abort(); -#endif - } - - using __gnu_cxx::_Lock_policy; - using __gnu_cxx::__default_lock_policy; - using __gnu_cxx::_S_single; - using __gnu_cxx::_S_mutex; - using __gnu_cxx::_S_atomic; - - template - struct _Sp_deleter - { - typedef void result_type; - typedef _Tp* argument_type; - - void - operator()(_Tp* __p) const - { delete __p; } - }; - - // Empty helper class except when the template argument is _S_mutex. - template<_Lock_policy _Lp> - class _Mutex_base - { }; - - template<> - class _Mutex_base<_S_mutex> - : public __gnu_cxx::__mutex - { }; - - template<_Lock_policy _Lp = __default_lock_policy> - class _Sp_counted_base - : public _Mutex_base<_Lp> - { - public: - _Sp_counted_base() - : _M_use_count(1), _M_weak_count(1) { } - - virtual - ~_Sp_counted_base() // nothrow - { } - - // Called when _M_use_count drops to zero, to release the resources - // managed by *this. - virtual void - _M_dispose() = 0; // nothrow - - // Called when _M_weak_count drops to zero. - virtual void - _M_destroy() // nothrow - { delete this; } - - virtual void* - _M_get_deleter(const std::type_info&) = 0; - - void - _M_add_ref_copy() - { __gnu_cxx::__atomic_add_dispatch(&_M_use_count, 1); } - - void - _M_add_ref_lock(); - - void - _M_release() // nothrow - { - if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, - -1) == 1) - { - _M_dispose(); -#ifdef __GTHREADS - _GLIBCXX_READ_MEM_BARRIER; - _GLIBCXX_WRITE_MEM_BARRIER; -#endif - if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, - -1) == 1) - _M_destroy(); - } - } - - void - _M_weak_add_ref() // nothrow - { __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1); } - - void - _M_weak_release() // nothrow - { - if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1) - { -#ifdef __GTHREADS - _GLIBCXX_READ_MEM_BARRIER; - _GLIBCXX_WRITE_MEM_BARRIER; -#endif - _M_destroy(); - } - } - - long - _M_get_use_count() const // nothrow - { return _M_use_count; } // XXX is this MT safe? - - private: - _Sp_counted_base(_Sp_counted_base const&); - _Sp_counted_base& operator=(_Sp_counted_base const&); - - _Atomic_word _M_use_count; // #shared - _Atomic_word _M_weak_count; // #weak + (#shared != 0) - }; - - template<> - inline void - _Sp_counted_base<_S_single>:: - _M_add_ref_lock() - { - if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0) - { - _M_use_count = 0; - __throw_bad_weak_ptr(); - } - } - - template<> - inline void - _Sp_counted_base<_S_mutex>:: - _M_add_ref_lock() - { - __gnu_cxx::__scoped_lock sentry(*this); - if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0) - { - _M_use_count = 0; - __throw_bad_weak_ptr(); - } - } - - template<> - inline void - _Sp_counted_base<_S_atomic>:: - _M_add_ref_lock() - { - // Perform lock-free add-if-not-zero operation. - _Atomic_word __count; - do - { - __count = _M_use_count; - if (__count == 0) - __throw_bad_weak_ptr(); - - // Replace the current counter value with the old value + 1, as - // long as it's not changed meanwhile. - } - while (!__sync_bool_compare_and_swap(&_M_use_count, __count, - __count + 1)); - } - - template - class _Sp_counted_base_impl - : public _Sp_counted_base<_Lp> - { - public: - /** - * @brief - * @pre __d(__p) must not throw. - */ - _Sp_counted_base_impl(_Ptr __p, _Deleter __d) - : _M_ptr(__p), _M_del(__d) { } - - virtual void - _M_dispose() // nothrow - { _M_del(_M_ptr); } - - virtual void* - _M_get_deleter(const std::type_info& __ti) - { return __ti == typeid(_Deleter) ? &_M_del : 0; } - - private: - _Sp_counted_base_impl(const _Sp_counted_base_impl&); - _Sp_counted_base_impl& operator=(const _Sp_counted_base_impl&); - - _Ptr _M_ptr; // copy constructor must not throw - _Deleter _M_del; // copy constructor must not throw - }; - - template<_Lock_policy _Lp = __default_lock_policy> - class __weak_count; - - template<_Lock_policy _Lp = __default_lock_policy> - class __shared_count - { - public: - __shared_count() - : _M_pi(0) // nothrow - { } - - template - __shared_count(_Ptr __p, _Deleter __d) : _M_pi(0) - { - try - { - _M_pi = new _Sp_counted_base_impl<_Ptr, _Deleter, _Lp>(__p, __d); - } - catch(...) - { - __d(__p); // Call _Deleter on __p. - __throw_exception_again; - } - } - - // Special case for auto_ptr<_Tp> to provide the strong guarantee. - template - explicit - __shared_count(std::auto_ptr<_Tp>& __r) - : _M_pi(new _Sp_counted_base_impl<_Tp*, - _Sp_deleter<_Tp>, _Lp >(__r.get(), _Sp_deleter<_Tp>())) - { __r.release(); } - - // Throw bad_weak_ptr when __r._M_get_use_count() == 0. - explicit - __shared_count(const __weak_count<_Lp>& __r); - - ~__shared_count() // nothrow - { - if (_M_pi != 0) - _M_pi->_M_release(); - } - - __shared_count(const __shared_count& __r) - : _M_pi(__r._M_pi) // nothrow - { - if (_M_pi != 0) - _M_pi->_M_add_ref_copy(); - } - - __shared_count& - operator=(const __shared_count& __r) // nothrow - { - _Sp_counted_base<_Lp>* __tmp = __r._M_pi; - if (__tmp != _M_pi) - { - if (__tmp != 0) - __tmp->_M_add_ref_copy(); - if (_M_pi != 0) - _M_pi->_M_release(); - _M_pi = __tmp; - } - return *this; - } - - void - _M_swap(__shared_count& __r) // nothrow - { - _Sp_counted_base<_Lp>* __tmp = __r._M_pi; - __r._M_pi = _M_pi; - _M_pi = __tmp; - } - - long - _M_get_use_count() const // nothrow - { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; } - - bool - _M_unique() const // nothrow - { return this->_M_get_use_count() == 1; } - - friend inline bool - operator==(const __shared_count& __a, const __shared_count& __b) - { return __a._M_pi == __b._M_pi; } - - friend inline bool - operator<(const __shared_count& __a, const __shared_count& __b) - { return std::less<_Sp_counted_base<_Lp>*>()(__a._M_pi, __b._M_pi); } - - void* - _M_get_deleter(const std::type_info& __ti) const - { return _M_pi ? _M_pi->_M_get_deleter(__ti) : 0; } - - private: - friend class __weak_count<_Lp>; - - _Sp_counted_base<_Lp>* _M_pi; - }; - - template<_Lock_policy _Lp> - class __weak_count - { - public: - __weak_count() - : _M_pi(0) // nothrow - { } - - __weak_count(const __shared_count<_Lp>& __r) - : _M_pi(__r._M_pi) // nothrow - { - if (_M_pi != 0) - _M_pi->_M_weak_add_ref(); - } - - __weak_count(const __weak_count<_Lp>& __r) - : _M_pi(__r._M_pi) // nothrow - { - if (_M_pi != 0) - _M_pi->_M_weak_add_ref(); - } - - ~__weak_count() // nothrow - { - if (_M_pi != 0) - _M_pi->_M_weak_release(); - } - - __weak_count<_Lp>& - operator=(const __shared_count<_Lp>& __r) // nothrow - { - _Sp_counted_base<_Lp>* __tmp = __r._M_pi; - if (__tmp != 0) - __tmp->_M_weak_add_ref(); - if (_M_pi != 0) - _M_pi->_M_weak_release(); - _M_pi = __tmp; - return *this; - } - - __weak_count<_Lp>& - operator=(const __weak_count<_Lp>& __r) // nothrow - { - _Sp_counted_base<_Lp>* __tmp = __r._M_pi; - if (__tmp != 0) - __tmp->_M_weak_add_ref(); - if (_M_pi != 0) - _M_pi->_M_weak_release(); - _M_pi = __tmp; - return *this; - } - - void - _M_swap(__weak_count<_Lp>& __r) // nothrow - { - _Sp_counted_base<_Lp>* __tmp = __r._M_pi; - __r._M_pi = _M_pi; - _M_pi = __tmp; - } - - long - _M_get_use_count() const // nothrow - { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; } - - friend inline bool - operator==(const __weak_count<_Lp>& __a, const __weak_count<_Lp>& __b) - { return __a._M_pi == __b._M_pi; } - - friend inline bool - operator<(const __weak_count<_Lp>& __a, const __weak_count<_Lp>& __b) - { return std::less<_Sp_counted_base<_Lp>*>()(__a._M_pi, __b._M_pi); } - - private: - friend class __shared_count<_Lp>; - - _Sp_counted_base<_Lp>* _M_pi; - }; - - template<_Lock_policy _Lp> - inline - __shared_count<_Lp>:: - __shared_count(const __weak_count<_Lp>& __r) - : _M_pi(__r._M_pi) - { - if (_M_pi != 0) - _M_pi->_M_add_ref_lock(); - else - __throw_bad_weak_ptr(); - } - - - // Forward declarations. - template - class __shared_ptr; - - template - class __weak_ptr; - - template - class __enable_shared_from_this; - - template - class shared_ptr; - - template - class weak_ptr; - - template - class enable_shared_from_this; - - // Support for enable_shared_from_this. - - // Friend of __enable_shared_from_this. - template<_Lock_policy _Lp, typename _Tp1, typename _Tp2> - void - __enable_shared_from_this_helper(const __shared_count<_Lp>&, - const __enable_shared_from_this<_Tp1, - _Lp>*, const _Tp2*); - - // Friend of enable_shared_from_this. - template - void - __enable_shared_from_this_helper(const __shared_count<>&, - const enable_shared_from_this<_Tp1>*, - const _Tp2*); - - template<_Lock_policy _Lp> - inline void - __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...) - { } - - - struct __static_cast_tag { }; - struct __const_cast_tag { }; - struct __dynamic_cast_tag { }; - - /** - * @class shared_ptr - * - * A smart pointer with reference-counted copy semantics. - * The object pointed to is deleted when the last shared_ptr pointing to - * it is destroyed or reset. - */ - template - class __shared_ptr - { - public: - typedef _Tp element_type; - - /** @brief Construct an empty %__shared_ptr. - * @post use_count()==0 && get()==0 - */ - __shared_ptr() - : _M_ptr(0), _M_refcount() // never throws - { } - - /** @brief Construct a %__shared_ptr that owns the pointer @a __p. - * @param __p A pointer that is convertible to element_type*. - * @post use_count() == 1 && get() == __p - * @throw std::bad_alloc, in which case @c delete @a __p is called. - */ - template - explicit - __shared_ptr(_Tp1* __p) - : _M_ptr(__p), _M_refcount(__p, _Sp_deleter<_Tp1>()) - { - __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) - // __glibcxx_function_requires(_CompleteConcept<_Tp1*>) - __enable_shared_from_this_helper(_M_refcount, __p, __p); - } - - // - // Requirements: _Deleter' copy constructor and destructor must not throw - // - // __shared_ptr will release __p by calling __d(__p) - // - /** @brief Construct a %__shared_ptr that owns the pointer @a __p - * and the deleter @a __d. - * @param __p A pointer. - * @param __d A deleter. - * @post use_count() == 1 && get() == __p - * @throw std::bad_alloc, in which case @a __d(__p) is called. - */ - template - __shared_ptr(_Tp1* __p, _Deleter __d) - : _M_ptr(__p), _M_refcount(__p, __d) - { - __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) - // TODO requires _Deleter CopyConstructible and __d(__p) well-formed - __enable_shared_from_this_helper(_M_refcount, __p, __p); - } - - // generated copy constructor, assignment, destructor are fine. - - /** @brief If @a __r is empty, constructs an empty %__shared_ptr; - * otherwise construct a %__shared_ptr that shares ownership - * with @a __r. - * @param __r A %__shared_ptr. - * @post get() == __r.get() && use_count() == __r.use_count() - * @throw std::bad_alloc, in which case - */ - template - __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) - : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws - { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } - - /** @brief Constructs a %__shared_ptr that shares ownership with @a __r - * and stores a copy of the pointer stored in @a __r. - * @param __r A weak_ptr. - * @post use_count() == __r.use_count() - * @throw bad_weak_ptr when __r.expired(), - * in which case the constructor has no effect. - */ - template - explicit - __shared_ptr(const __weak_ptr<_Tp1, _Lp>& __r) - : _M_refcount(__r._M_refcount) // may throw - { - __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) - // It is now safe to copy __r._M_ptr, as _M_refcount(__r._M_refcount) - // did not throw. - _M_ptr = __r._M_ptr; - } - - /** - * @post use_count() == 1 and __r.get() == 0 - */ - template - explicit - __shared_ptr(std::auto_ptr<_Tp1>& __r) - : _M_ptr(__r.get()), _M_refcount() - { - // TODO requires __r.release() convertible to _Tp*, _Tp1 is complete, - // delete __r.release() well-formed - _Tp1* __tmp = __r.get(); - _M_refcount = __shared_count<_Lp>(__r); - __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp); - } - - template - __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, __static_cast_tag) - : _M_ptr(static_cast(__r._M_ptr)), - _M_refcount(__r._M_refcount) - { } - - template - __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, __const_cast_tag) - : _M_ptr(const_cast(__r._M_ptr)), - _M_refcount(__r._M_refcount) - { } - - template - __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, __dynamic_cast_tag) - : _M_ptr(dynamic_cast(__r._M_ptr)), - _M_refcount(__r._M_refcount) - { - if (_M_ptr == 0) // need to allocate new counter -- the cast failed - _M_refcount = __shared_count<_Lp>(); - } - - template - __shared_ptr& - operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws - { - _M_ptr = __r._M_ptr; - _M_refcount = __r._M_refcount; // __shared_count::op= doesn't throw - return *this; - } - - template - __shared_ptr& - operator=(std::auto_ptr<_Tp1>& __r) - { - __shared_ptr(__r).swap(*this); - return *this; - } - - void - reset() // never throws - { __shared_ptr().swap(*this); } - - template - void - reset(_Tp1* __p) // _Tp1 must be complete. - { - // Catch self-reset errors. - _GLIBCXX_DEBUG_ASSERT(__p == 0 || __p != _M_ptr); - __shared_ptr(__p).swap(*this); - } - - template - void - reset(_Tp1* __p, _Deleter __d) - { __shared_ptr(__p, __d).swap(*this); } - - // Allow class instantiation when _Tp is [cv-qual] void. - typename add_reference<_Tp>::type - operator*() const // never throws - { - _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); - return *_M_ptr; - } - - _Tp* - operator->() const // never throws - { - _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); - return _M_ptr; - } - - _Tp* - get() const // never throws - { return _M_ptr; } - - // Implicit conversion to "bool" - private: - typedef _Tp* __shared_ptr::*__unspecified_bool_type; - - public: - operator __unspecified_bool_type() const // never throws - { return _M_ptr == 0 ? 0 : &__shared_ptr::_M_ptr; } - - bool - unique() const // never throws - { return _M_refcount._M_unique(); } - - long - use_count() const // never throws - { return _M_refcount._M_get_use_count(); } - - void - swap(__shared_ptr<_Tp, _Lp>& __other) // never throws - { - std::swap(_M_ptr, __other._M_ptr); - _M_refcount._M_swap(__other._M_refcount); - } - - private: - void* - _M_get_deleter(const std::type_info& __ti) const - { return _M_refcount._M_get_deleter(__ti); } - - template - bool - _M_less(const __shared_ptr<_Tp1, _Lp1>& __rhs) const - { return _M_refcount < __rhs._M_refcount; } - - template friend class __shared_ptr; - template friend class __weak_ptr; - - template - friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&); - - // Friends injected into enclosing namespace and found by ADL: - template - friend inline bool - operator==(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b) - { return __a.get() == __b.get(); } - - template - friend inline bool - operator!=(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b) - { return __a.get() != __b.get(); } - - template - friend inline bool - operator<(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b) - { return __a._M_less(__b); } - - _Tp* _M_ptr; // Contained pointer. - __shared_count<_Lp> _M_refcount; // Reference counter. - }; - - // 2.2.3.8 shared_ptr specialized algorithms. - template - inline void - swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b) - { __a.swap(__b); } - - // 2.2.3.9 shared_ptr casts - /** @warning The seemingly equivalent - * shared_ptr<_Tp, _Lp>(static_cast<_Tp*>(__r.get())) - * will eventually result in undefined behaviour, - * attempting to delete the same object twice. - */ - template - __shared_ptr<_Tp, _Lp> - static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) - { return __shared_ptr<_Tp, _Lp>(__r, __static_cast_tag()); } - - /** @warning The seemingly equivalent - * shared_ptr<_Tp, _Lp>(const_cast<_Tp*>(__r.get())) - * will eventually result in undefined behaviour, - * attempting to delete the same object twice. - */ - template - __shared_ptr<_Tp, _Lp> - const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) - { return __shared_ptr<_Tp, _Lp>(__r, __const_cast_tag()); } - - /** @warning The seemingly equivalent - * shared_ptr<_Tp, _Lp>(dynamic_cast<_Tp*>(__r.get())) - * will eventually result in undefined behaviour, - * attempting to delete the same object twice. - */ - template - __shared_ptr<_Tp, _Lp> - dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) - { return __shared_ptr<_Tp, _Lp>(__r, __dynamic_cast_tag()); } - - // 2.2.3.7 shared_ptr I/O - template - std::basic_ostream<_Ch, _Tr>& - operator<<(std::basic_ostream<_Ch, _Tr>& __os, - const __shared_ptr<_Tp, _Lp>& __p) - { - __os << __p.get(); - return __os; - } - - // 2.2.3.10 shared_ptr get_deleter (experimental) - template - inline _Del* - get_deleter(const __shared_ptr<_Tp, _Lp>& __p) - { return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); } - - - template - class __weak_ptr - { - public: - typedef _Tp element_type; - - __weak_ptr() - : _M_ptr(0), _M_refcount() // never throws - { } - - // Generated copy constructor, assignment, destructor are fine. - - // The "obvious" converting constructor implementation: - // - // template - // __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) - // : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws - // { } - // - // has a serious problem. - // - // __r._M_ptr may already have been invalidated. The _M_ptr(__r._M_ptr) - // conversion may require access to *__r._M_ptr (virtual inheritance). - // - // It is not possible to avoid spurious access violations since - // in multithreaded programs __r._M_ptr may be invalidated at any point. - template - __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) - : _M_refcount(__r._M_refcount) // never throws - { - __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) - _M_ptr = __r.lock().get(); - } - - template - __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r) - : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws - { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } - - template - __weak_ptr& - operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws - { - _M_ptr = __r.lock().get(); - _M_refcount = __r._M_refcount; - return *this; - } - - template - __weak_ptr& - operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws - { - _M_ptr = __r._M_ptr; - _M_refcount = __r._M_refcount; - return *this; - } - - __shared_ptr<_Tp, _Lp> - lock() const // never throws - { -#ifdef __GTHREADS - // Optimization: avoid throw overhead. - if (expired()) - return __shared_ptr(); - - try - { - return __shared_ptr(*this); - } - catch(const bad_weak_ptr&) - { - // Q: How can we get here? - // A: Another thread may have invalidated r after the - // use_count test above. - return __shared_ptr(); - } - -#else - // Optimization: avoid try/catch overhead when single threaded. - return expired() ? __shared_ptr() - : __shared_ptr(*this); - -#endif - } // XXX MT - - long - use_count() const // never throws - { return _M_refcount._M_get_use_count(); } - - bool - expired() const // never throws - { return _M_refcount._M_get_use_count() == 0; } - - void - reset() // never throws - { __weak_ptr().swap(*this); } - - void - swap(__weak_ptr& __s) // never throws - { - std::swap(_M_ptr, __s._M_ptr); - _M_refcount._M_swap(__s._M_refcount); - } - - private: - // Used by __enable_shared_from_this. - void - _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) - { - _M_ptr = __ptr; - _M_refcount = __refcount; - } - - template - bool - _M_less(const __weak_ptr<_Tp1, _Lp>& __rhs) const - { return _M_refcount < __rhs._M_refcount; } - - template friend class __shared_ptr; - template friend class __weak_ptr; - friend class __enable_shared_from_this<_Tp, _Lp>; - friend class enable_shared_from_this<_Tp>; - - // Friend injected into namespace and found by ADL. - template - friend inline bool - operator<(const __weak_ptr& __lhs, const __weak_ptr<_Tp1, _Lp>& __rhs) - { return __lhs._M_less(__rhs); } - - _Tp* _M_ptr; // Contained pointer. - __weak_count<_Lp> _M_refcount; // Reference counter. - }; - - // 2.2.4.7 weak_ptr specialized algorithms. - template - inline void - swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) - { __a.swap(__b); } - - - template - class __enable_shared_from_this - { - protected: - __enable_shared_from_this() { } - - __enable_shared_from_this(const __enable_shared_from_this&) { } - - __enable_shared_from_this& - operator=(const __enable_shared_from_this&) - { return *this; } - - ~__enable_shared_from_this() { } - - public: - __shared_ptr<_Tp, _Lp> - shared_from_this() - { return __shared_ptr<_Tp, _Lp>(this->_M_weak_this); } - - __shared_ptr - shared_from_this() const - { return __shared_ptr(this->_M_weak_this); } - - private: - template - void - _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const - { _M_weak_this._M_assign(__p, __n); } - - template - friend void - __enable_shared_from_this_helper(const __shared_count<_Lp>& __pn, - const __enable_shared_from_this* __pe, - const _Tp1* __px) - { - if (__pe != 0) - __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn); - } - - mutable __weak_ptr<_Tp, _Lp> _M_weak_this; - }; - - - // The actual TR1 shared_ptr, with forwarding constructors and - // assignment operators. - template - class shared_ptr - : public __shared_ptr<_Tp> - { - public: - shared_ptr() - : __shared_ptr<_Tp>() { } - - template - explicit - shared_ptr(_Tp1* __p) - : __shared_ptr<_Tp>(__p) { } - - template - shared_ptr(_Tp1* __p, _Deleter __d) - : __shared_ptr<_Tp>(__p, __d) { } - - template - shared_ptr(const shared_ptr<_Tp1>& __r) - : __shared_ptr<_Tp>(__r) { } - - template - explicit - shared_ptr(const weak_ptr<_Tp1>& __r) - : __shared_ptr<_Tp>(__r) { } - - template - explicit - shared_ptr(std::auto_ptr<_Tp1>& __r) - : __shared_ptr<_Tp>(__r) { } - - template - shared_ptr(const shared_ptr<_Tp1>& __r, __static_cast_tag) - : __shared_ptr<_Tp>(__r, __static_cast_tag()) { } - - template - shared_ptr(const shared_ptr<_Tp1>& __r, __const_cast_tag) - : __shared_ptr<_Tp>(__r, __const_cast_tag()) { } - - template - shared_ptr(const shared_ptr<_Tp1>& __r, __dynamic_cast_tag) - : __shared_ptr<_Tp>(__r, __dynamic_cast_tag()) { } - - template - shared_ptr& - operator=(const shared_ptr<_Tp1>& __r) // never throws - { - this->__shared_ptr<_Tp>::operator=(__r); - return *this; - } - - template - shared_ptr& - operator=(std::auto_ptr<_Tp1>& __r) - { - this->__shared_ptr<_Tp>::operator=(__r); - return *this; - } - }; - - template - shared_ptr<_Tp> - static_pointer_cast(const shared_ptr<_Tp1>& __r) - { return shared_ptr<_Tp>(__r, __static_cast_tag()); } - - template - shared_ptr<_Tp> - const_pointer_cast(const shared_ptr<_Tp1>& __r) - { return shared_ptr<_Tp>(__r, __const_cast_tag()); } - - template - shared_ptr<_Tp> - dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) - { return shared_ptr<_Tp>(__r, __dynamic_cast_tag()); } - - - // The actual TR1 weak_ptr, with forwarding constructors and - // assignment operators. - template - class weak_ptr - : public __weak_ptr<_Tp> - { - public: - weak_ptr() - : __weak_ptr<_Tp>() { } - - template - weak_ptr(const weak_ptr<_Tp1>& __r) - : __weak_ptr<_Tp>(__r) { } - - template - weak_ptr(const shared_ptr<_Tp1>& __r) - : __weak_ptr<_Tp>(__r) { } - - template - weak_ptr& - operator=(const weak_ptr<_Tp1>& __r) // never throws - { - this->__weak_ptr<_Tp>::operator=(__r); - return *this; - } - - template - weak_ptr& - operator=(const shared_ptr<_Tp1>& __r) // never throws - { - this->__weak_ptr<_Tp>::operator=(__r); - return *this; - } - - shared_ptr<_Tp> - lock() const // never throws - { -#ifdef __GTHREADS - if (this->expired()) - return shared_ptr<_Tp>(); - - try - { - return shared_ptr<_Tp>(*this); - } - catch(const bad_weak_ptr&) - { - return shared_ptr<_Tp>(); - } -#else - return this->expired() ? shared_ptr<_Tp>() - : shared_ptr<_Tp>(*this); -#endif - } - }; - - - template - class enable_shared_from_this - { - protected: - enable_shared_from_this() { } - - enable_shared_from_this(const enable_shared_from_this&) { } - - enable_shared_from_this& - operator=(const enable_shared_from_this&) - { return *this; } - - ~enable_shared_from_this() { } - - public: - shared_ptr<_Tp> - shared_from_this() - { return shared_ptr<_Tp>(this->_M_weak_this); } - - shared_ptr - shared_from_this() const - { return shared_ptr(this->_M_weak_this); } - - private: - template - void - _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const - { _M_weak_this._M_assign(__p, __n); } - - template - friend void - __enable_shared_from_this_helper(const __shared_count<>& __pn, - const enable_shared_from_this* __pe, - const _Tp1* __px) - { - if (__pe != 0) - __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn); - } - - mutable weak_ptr<_Tp> _M_weak_this; - }; - -_GLIBCXX_END_NAMESPACE -} // namespace std - -#endif diff --git a/libstdc++-v3/include/tr1/ccomplex b/libstdc++-v3/include/tr1/ccomplex index a919645..98f2cdc 100644 --- a/libstdc++-v3/include/tr1/ccomplex +++ b/libstdc++-v3/include/tr1/ccomplex @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CCOMPLEX -#define _TR1_CCOMPLEX 1 +#ifndef _GLIBCXX_TR1_CCOMPLEX +#define _GLIBCXX_TR1_CCOMPLEX 1 #include -#endif +#endif // _GLIBCXX_TR1_CCOMPLEX diff --git a/libstdc++-v3/include/tr1/cctype b/libstdc++-v3/include/tr1/cctype index 7d428f9..72607d7 100644 --- a/libstdc++-v3/include/tr1/cctype +++ b/libstdc++-v3/include/tr1/cctype @@ -1,6 +1,6 @@ // TR1 cctype -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,26 +31,24 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CCTYPE -#define _TR1_CCTYPE 1 +#ifndef _GLIBCXX_TR1_CCTYPE +#define _GLIBCXX_TR1_CCTYPE 1 #include #include -#if _GLIBCXX_USE_C99_CTYPE_TR1 - -#undef isblank - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - using ::isblank; - -_GLIBCXX_END_NAMESPACE -} - +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -#endif +#endif // _GLIBCXX_TR1_CCTYPE diff --git a/libstdc++-v3/include/tr1/cfenv b/libstdc++-v3/include/tr1/cfenv index dc9fff8..8544712 100644 --- a/libstdc++-v3/include/tr1/cfenv +++ b/libstdc++-v3/include/tr1/cfenv @@ -1,6 +1,6 @@ -// TR1 cctype -*- C++ -*- +// TR1 cfenv -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,54 +31,23 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CFENV -#define _TR1_CFENV 1 +#ifndef _GLIBCXX_TR1_CFENV +#define _GLIBCXX_TR1_CFENV 1 #include -#if _GLIBCXX_USE_C99_FENV_TR1 - -#include_next - -#undef feclearexcept -#undef fegetexceptflag -#undef feraiseexcept -#undef fesetexceptflag -#undef fetestexcept -#undef fegetround -#undef fesetround -#undef fegetenv -#undef feholdexcept -#undef fesetenv -#undef feupdateenv - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // types - using ::fenv_t; - using ::fexcept_t; - - // functions - using ::feclearexcept; - using ::fegetexceptflag; - using ::feraiseexcept; - using ::fesetexceptflag; - using ::fetestexcept; - - using ::fegetround; - using ::fesetround; - - using ::fegetenv; - using ::feholdexcept; - using ::fesetenv; - using ::feupdateenv; - -_GLIBCXX_END_NAMESPACE -} - +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -#endif +#endif // _GLIBCXX_TR1_CFENV diff --git a/libstdc++-v3/include/tr1/cfloat b/libstdc++-v3/include/tr1/cfloat index 1514ff7..86f3af8 100644 --- a/libstdc++-v3/include/tr1/cfloat +++ b/libstdc++-v3/include/tr1/cfloat @@ -1,6 +1,6 @@ // TR1 cfloat -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,8 +31,8 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CFLOAT -#define _TR1_CFLOAT 1 +#ifndef _GLIBCXX_TR1_CFLOAT +#define _GLIBCXX_TR1_CFLOAT 1 #include @@ -44,4 +44,4 @@ #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ #endif -#endif +#endif //_GLIBCXX_TR1_CFLOAT diff --git a/libstdc++-v3/include/tr1/cinttypes b/libstdc++-v3/include/tr1/cinttypes index e2d2fcd..19e2df3 100644 --- a/libstdc++-v3/include/tr1/cinttypes +++ b/libstdc++-v3/include/tr1/cinttypes @@ -31,51 +31,23 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CINTTYPES -#define _TR1_CINTTYPES 1 +#ifndef _GLIBCXX_TR1_CINTTYPES +#define _GLIBCXX_TR1_CINTTYPES 1 -#include #include -#if _GLIBCXX_USE_C99_INTTYPES_TR1 - -// For 8.11.1/1 (see C99, Note 184) -#define __STDC_FORMAT_MACROS -#include_next - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // types - using ::imaxdiv_t; - - // functions - using ::imaxabs; - - // May collide with _Longlong abs(_Longlong), and is not described - // anywhere outside the synopsis. Likely, a defect. - // - // intmax_t abs(intmax_t) - - using ::imaxdiv; - - // Likewise, with lldiv_t div(_Longlong, _Longlong). - // - // imaxdiv_t div(intmax_t, intmax_t) - - using ::strtoimax; - using ::strtoumax; - -#ifdef _GLIBCXX_USE_WCHAR_T - using ::wcstoimax; - using ::wcstoumax; -#endif - -_GLIBCXX_END_NAMESPACE -} - +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -#endif +#endif // _GLIBCXX_TR1_CINTTYPES diff --git a/libstdc++-v3/include/tr1/climits b/libstdc++-v3/include/tr1/climits index dc04729..9c7b0c5 100644 --- a/libstdc++-v3/include/tr1/climits +++ b/libstdc++-v3/include/tr1/climits @@ -1,6 +1,6 @@ // TR1 climits -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,8 +31,8 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CLIMITS -#define _TR1_CLIMITS 1 +#ifndef _GLIBCXX_TR1_CLIMITS +#define _GLIBCXX_TR1_CLIMITS 1 #include @@ -48,4 +48,4 @@ #define ULLONG_MAX __LONG_LONG_MAX__ * 2ULL + 1 #endif -#endif +#endif // _GLIBCXX_TR1_CLIMITS diff --git a/libstdc++-v3/include/tr1/cmath b/libstdc++-v3/include/tr1/cmath index f1cb1e6..70d65f5 100644 --- a/libstdc++-v3/include/tr1/cmath +++ b/libstdc++-v3/include/tr1/cmath @@ -31,925 +31,42 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CMATH -#define _TR1_CMATH 1 +#ifndef _GLIBCXX_TR1_CMATH +#define _GLIBCXX_TR1_CMATH 1 -#include -#include -#include -#include -#include - -#if _GLIBCXX_USE_C99_MATH_TR1 - -#undef acosh -#undef acoshf -#undef acoshl -#undef asinh -#undef asinhf -#undef asinhl -#undef atanh -#undef atanhf -#undef atanhl -#undef cbrt -#undef cbrtf -#undef cbrtl -#undef copysign -#undef copysignf -#undef copysignl -#undef erf -#undef erff -#undef erfl -#undef erfc -#undef erfcf -#undef erfcl -#undef exp2 -#undef exp2f -#undef exp2l -#undef expm1 -#undef expm1f -#undef expm1l -#undef fdim -#undef fdimf -#undef fdiml -#undef fma -#undef fmaf -#undef fmal -#undef fmax -#undef fmaxf -#undef fmaxl -#undef fmin -#undef fminf -#undef fminl -#undef hypot -#undef hypotf -#undef hypotl -#undef ilogb -#undef ilogbf -#undef ilogbl -#undef lgamma -#undef lgammaf -#undef lgammal -#undef llrint -#undef llrintf -#undef llrintl -#undef llround -#undef llroundf -#undef llroundl -#undef log1p -#undef log1pf -#undef log1pl -#undef log2 -#undef log2f -#undef log2l -#undef logb -#undef logbf -#undef logbl -#undef lrint -#undef lrintf -#undef lrintl -#undef lround -#undef lroundf -#undef lroundl -#undef nan -#undef nanf -#undef nanl -#undef nearbyint -#undef nearbyintf -#undef nearbyintl -#undef nextafter -#undef nextafterf -#undef nextafterl -#undef nexttoward -#undef nexttowardf -#undef nexttowardl -#undef remainder -#undef remainderf -#undef remainderl -#undef remquo -#undef remquo -#undef remquo -#undef rint -#undef rintf -#undef rintl -#undef round -#undef roundf -#undef roundl -#undef scalbln -#undef scalblnf -#undef scalblnl -#undef scalbn -#undef scalbnf -#undef scalbnl -#undef tgamma -#undef tgammaf -#undef tgammal -#undef trunc -#undef truncf -#undef truncl +#pragma GCC system_header +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header #endif -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - -#if _GLIBCXX_USE_C99_MATH_TR1 - - // types - using ::double_t; - using ::float_t; - - // functions - using ::acosh; - using ::acoshf; - using ::acoshl; - - using ::asinh; - using ::asinhf; - using ::asinhl; - - using ::atanh; - using ::atanhf; - using ::atanhl; - - using ::cbrt; - using ::cbrtf; - using ::cbrtl; - - using ::copysign; - using ::copysignf; - using ::copysignl; - - using ::erf; - using ::erff; - using ::erfl; - - using ::erfc; - using ::erfcf; - using ::erfcl; - - using ::exp2; - using ::exp2f; - using ::exp2l; - - using ::expm1; - using ::expm1f; - using ::expm1l; - - using ::fdim; - using ::fdimf; - using ::fdiml; - - using ::fma; - using ::fmaf; - using ::fmal; - - using ::fmax; - using ::fmaxf; - using ::fmaxl; - - using ::fmin; - using ::fminf; - using ::fminl; - - using ::hypot; - using ::hypotf; - using ::hypotl; - - using ::ilogb; - using ::ilogbf; - using ::ilogbl; - - using ::lgamma; - using ::lgammaf; - using ::lgammal; - - using ::llrint; - using ::llrintf; - using ::llrintl; - - using ::llround; - using ::llroundf; - using ::llroundl; - - using ::log1p; - using ::log1pf; - using ::log1pl; - - using ::log2; - using ::log2f; - using ::log2l; - - using ::logb; - using ::logbf; - using ::logbl; - - using ::lrint; - using ::lrintf; - using ::lrintl; - - using ::lround; - using ::lroundf; - using ::lroundl; - - using ::nan; - using ::nanf; - using ::nanl; - - using ::nearbyint; - using ::nearbyintf; - using ::nearbyintl; - - using ::nextafter; - using ::nextafterf; - using ::nextafterl; - - using ::nexttoward; - using ::nexttowardf; - using ::nexttowardl; - - using ::remainder; - using ::remainderf; - using ::remainderl; - - using ::remquo; - using ::remquo; - using ::remquo; - - using ::rint; - using ::rintf; - using ::rintl; - - using ::round; - using ::roundf; - using ::roundl; - - using ::scalbln; - using ::scalblnf; - using ::scalblnl; - - using ::scalbn; - using ::scalbnf; - using ::scalbnl; - - using ::tgamma; - using ::tgammaf; - using ::tgammal; - - using ::trunc; - using ::truncf; - using ::truncl; - -#endif - -#if _GLIBCXX_USE_C99_MATH -#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC - - /// @brief Function template definitions [8.16.3]. - // - using std::signbit; - - using std::fpclassify; - - using std::isfinite; - using std::isinf; - using std::isnan; - using std::isnormal; - - using std::isgreater; - using std::isgreaterequal; - using std::isless; - using std::islessequal; - using std::islessgreater; - using std::isunordered; -#endif -#endif - -#if _GLIBCXX_USE_C99_MATH_TR1 - - /// @brief Additional overloads [8.16.4]. - // - using std::acos; - - inline float - acosh(float __x) - { return __builtin_acoshf(__x); } - - inline long double - acosh(long double __x) - { return __builtin_acoshl(__x); } - - template - inline typename __promote<_Tp>::__type - acosh(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return acosh(__type(__x)); - } - - using std::asin; - - inline float - asinh(float __x) - { return __builtin_asinhf(__x); } - - inline long double - asinh(long double __x) - { return __builtin_asinhl(__x); } - - template - inline typename __promote<_Tp>::__type - asinh(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return asinh(__type(__x)); - } - - using std::atan; - - // Workaround for c++/21682. - namespace __detail - { - template - inline typename - __gnu_cxx::__enable_if::__value - || std::__is_floating<_Up>::__value, - typename std::_GLIBCXX_TR1:: - __promote_2<_Tp, _Up>::__type>::__type - atan2(_Tp __y, _Up __x) - { - typedef typename std::_GLIBCXX_TR1::__promote_2<_Tp, _Up>::__type - __type; - return std::atan2(__type(__y), __type(__x)); - } - } // namespace __detail - - using std::atan2; - using __detail::atan2; - - inline float - atanh(float __x) - { return __builtin_atanhf(__x); } - - inline long double - atanh(long double __x) - { return __builtin_atanhl(__x); } - - template - inline typename __promote<_Tp>::__type - atanh(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return atanh(__type(__x)); - } - - inline float - cbrt(float __x) - { return __builtin_cbrtf(__x); } - - inline long double - cbrt(long double __x) - { return __builtin_cbrtl(__x); } - - template - inline typename __promote<_Tp>::__type - cbrt(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return cbrt(__type(__x)); - } - - using std::ceil; - - inline float - copysign(float __x, float __y) - { return __builtin_copysignf(__x, __y); } - - inline long double - copysign(long double __x, long double __y) - { return __builtin_copysignl(__x, __y); } - - template - inline typename __promote_2<_Tp, _Up>::__type - copysign(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return copysign(__type(__x), __type(__y)); - } - - using std::cos; - using std::cosh; - - inline float - erf(float __x) - { return __builtin_erff(__x); } - - inline long double - erf(long double __x) - { return __builtin_erfl(__x); } - - template - inline typename __promote<_Tp>::__type - erf(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return erf(__type(__x)); - } - - inline float - erfc(float __x) - { return __builtin_erfcf(__x); } - - inline long double - erfc(long double __x) - { return __builtin_erfcl(__x); } - - template - inline typename __promote<_Tp>::__type - erfc(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return erfc(__type(__x)); - } - - using std::exp; - - inline float - exp2(float __x) - { return __builtin_exp2f(__x); } - - inline long double - exp2(long double __x) - { return __builtin_exp2l(__x); } - - template - inline typename __promote<_Tp>::__type - exp2(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return exp2(__type(__x)); - } - - inline float - expm1(float __x) - { return __builtin_expm1f(__x); } - - inline long double - expm1(long double __x) - { return __builtin_expm1l(__x); } - - template - inline typename __promote<_Tp>::__type - expm1(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return expm1(__type(__x)); - } - - using std::fabs; - - inline float - fdim(float __x, float __y) - { return __builtin_fdimf(__x, __y); } - - inline long double - fdim(long double __x, long double __y) - { return __builtin_fdiml(__x, __y); } - - template - inline typename __promote_2<_Tp, _Up>::__type - fdim(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return fdim(__type(__x), __type(__y)); - } - - using std::floor; - - inline float - fma(float __x, float __y, float __z) - { return __builtin_fmaf(__x, __y, __z); } - - inline long double - fma(long double __x, long double __y, long double __z) - { return __builtin_fmal(__x, __y, __z); } - - template - inline typename __promote_3<_Tp, _Up, _Vp>::__type - fma(_Tp __x, _Up __y, _Vp __z) - { - typedef typename __promote_3<_Tp, _Up, _Vp>::__type __type; - return fma(__type(__x), __type(__y), __type(__z)); - } - - inline float - fmax(float __x, float __y) - { return __builtin_fmaxf(__x, __y); } - - inline long double - fmax(long double __x, long double __y) - { return __builtin_fmaxl(__x, __y); } - - template - inline typename __promote_2<_Tp, _Up>::__type - fmax(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return fmax(__type(__x), __type(__y)); - } - - inline float - fmin(float __x, float __y) - { return __builtin_fminf(__x, __y); } - - inline long double - fmin(long double __x, long double __y) - { return __builtin_fminl(__x, __y); } - - template - inline typename __promote_2<_Tp, _Up>::__type - fmin(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return fmin(__type(__x), __type(__y)); - } - - using std::fmod; - using std::frexp; - - inline float - hypot(float __x, float __y) - { return __builtin_hypotf(__x, __y); } - - inline long double - hypot(long double __x, long double __y) - { return __builtin_hypotl(__x, __y); } - - template - inline typename __promote_2<_Tp, _Up>::__type - hypot(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return hypot(__type(__x), __type(__y)); - } - - inline int - ilogb(float __x) - { return __builtin_ilogbf(__x); } - - inline int - ilogb(long double __x) - { return __builtin_ilogbl(__x); } - - template - inline int - ilogb(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return ilogb(__type(__x)); - } - - using std::ldexp; - - inline float - lgamma(float __x) - { return __builtin_lgammaf(__x); } - - inline long double - lgamma(long double __x) - { return __builtin_lgammal(__x); } - - template - inline typename __promote<_Tp>::__type - lgamma(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return lgamma(__type(__x)); - } - - inline long long - llrint(float __x) - { return __builtin_llrintf(__x); } - - inline long long - llrint(long double __x) - { return __builtin_llrintl(__x); } - - template - inline long long - llrint(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return llrint(__type(__x)); - } - - inline long long - llround(float __x) - { return __builtin_llroundf(__x); } - - inline long long - llround(long double __x) - { return __builtin_llroundl(__x); } - - template - inline long long - llround(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return llround(__type(__x)); - } - - using std::log; - using std::log10; - - inline float - log1p(float __x) - { return __builtin_log1pf(__x); } - - inline long double - log1p(long double __x) - { return __builtin_log1pl(__x); } - - template - inline typename __promote<_Tp>::__type - log1p(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return log1p(__type(__x)); - } - - // DR 568. - inline float - log2(float __x) - { return __builtin_log2f(__x); } - - inline long double - log2(long double __x) - { return __builtin_log2l(__x); } - - template - inline typename __promote<_Tp>::__type - log2(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return log2(__type(__x)); - } - - inline float - logb(float __x) - { return __builtin_logbf(__x); } - - inline long double - logb(long double __x) - { return __builtin_logbl(__x); } - - template - inline typename __promote<_Tp>::__type - logb(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return logb(__type(__x)); - } - - inline long - lrint(float __x) - { return __builtin_lrintf(__x); } - - inline long - lrint(long double __x) - { return __builtin_lrintl(__x); } - - template - inline long - lrint(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return lrint(__type(__x)); - } - - inline long - lround(float __x) - { return __builtin_lroundf(__x); } - - inline long - lround(long double __x) - { return __builtin_lroundl(__x); } - - template - inline long - lround(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return lround(__type(__x)); - } - - inline float - nearbyint(float __x) - { return __builtin_nearbyintf(__x); } - - inline long double - nearbyint(long double __x) - { return __builtin_nearbyintl(__x); } - - template - inline typename __promote<_Tp>::__type - nearbyint(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return nearbyint(__type(__x)); - } - - inline float - nextafter(float __x, float __y) - { return __builtin_nextafterf(__x, __y); } - - inline long double - nextafter(long double __x, long double __y) - { return __builtin_nextafterl(__x, __y); } - - template - inline typename __promote_2<_Tp, _Up>::__type - nextafter(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return nextafter(__type(__x), __type(__y)); - } - - inline float - nexttoward(float __x, long double __y) - { return __builtin_nexttowardf(__x, __y); } - - inline long double - nexttoward(long double __x, long double __y) - { return __builtin_nexttowardl(__x, __y); } - - template - inline typename __promote<_Tp>::__type - nexttoward(_Tp __x, long double __y) - { - typedef typename __promote<_Tp>::__type __type; - return nexttoward(__type(__x), __y); - } - - using std::pow; - - // DR 550. - template - inline typename __promote_2<_Tp, _Up>::__type - pow(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return pow(__type(__x), __type(__y)); - } - - inline float - remainder(float __x, float __y) - { return __builtin_remainderf(__x, __y); } - - inline long double - remainder(long double __x, long double __y) - { return __builtin_remainderl(__x, __y); } - - template - inline typename __promote_2<_Tp, _Up>::__type - remainder(_Tp __x, _Up __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return remainder(__type(__x), __type(__y)); - } - - inline float - remquo(float __x, float __y, int* __pquo) - { return __builtin_remquof(__x, __y, __pquo); } - - inline long double - remquo(long double __x, long double __y, int* __pquo) - { return __builtin_remquol(__x, __y, __pquo); } - - template - inline typename __promote_2<_Tp, _Up>::__type - remquo(_Tp __x, _Up __y, int* __pquo) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return remquo(__type(__x), __type(__y), __pquo); - } - - inline float - rint(float __x) - { return __builtin_rintf(__x); } - - inline long double - rint(long double __x) - { return __builtin_rintl(__x); } - - template - inline typename __promote<_Tp>::__type - rint(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return rint(__type(__x)); - } - - inline float - round(float __x) - { return __builtin_roundf(__x); } - - inline long double - round(long double __x) - { return __builtin_roundl(__x); } - - template - inline typename __promote<_Tp>::__type - round(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return round(__type(__x)); - } - - inline float - scalbln(float __x, long __ex) - { return __builtin_scalblnf(__x, __ex); } - - inline long double - scalbln(long double __x, long __ex) - { return __builtin_scalblnl(__x, __ex); } - - template - inline typename __promote<_Tp>::__type - scalbln(_Tp __x, long __ex) - { - typedef typename __promote<_Tp>::__type __type; - return scalbln(__type(__x), __ex); - } - - inline float - scalbn(float __x, int __ex) - { return __builtin_scalbnf(__x, __ex); } - - inline long double - scalbn(long double __x, int __ex) - { return __builtin_scalbnl(__x, __ex); } - - template - inline typename __promote<_Tp>::__type - scalbn(_Tp __x, int __ex) - { - typedef typename __promote<_Tp>::__type __type; - return scalbn(__type(__x), __ex); - } - - using std::sin; - using std::sinh; - using std::sqrt; - using std::tan; - using std::tanh; - - inline float - tgamma(float __x) - { return __builtin_tgammaf(__x); } - - inline long double - tgamma(long double __x) - { return __builtin_tgammal(__x); } - - template - inline typename __promote<_Tp>::__type - tgamma(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return tgamma(__type(__x)); - } - - inline float - trunc(float __x) - { return __builtin_truncf(__x); } - - inline long double - trunc(long double __x) - { return __builtin_truncl(__x); } - - template - inline typename __promote<_Tp>::__type - trunc(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return trunc(__type(__x)); - } - +#include +#include +#include + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -_GLIBCXX_END_NAMESPACE -} - - /** * @defgroup tr1_math_spec_func Mathematical Special Functions * A collection of advanced mathematical special functions. * @{ */ #ifndef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include + #include #include #include @@ -965,8 +82,8 @@ _GLIBCXX_END_NAMESPACE // namespace std::tr1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - +namespace tr1 +{ // 5.2.1.1 Associated Laguerre polynomials. inline float @@ -980,10 +97,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__assoc_laguerre<__type>(__n, __m, __x); } @@ -999,10 +116,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__assoc_legendre_p(__l, __m, __x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type assoc_legendre(unsigned int __l, unsigned int __m, _Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__assoc_legendre_p<__type>(__l, __m, __x); } @@ -1018,10 +135,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__beta(__x, __y); } template - inline typename __promote_2<_Tpx, _Tpy>::__type + inline typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type beta(_Tpx __x, _Tpy __y) { - typedef typename __promote_2<_Tpx, _Tpy>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tpx, _Tpy>::__type __type; return __detail::__beta<__type>(__x, __y); } @@ -1037,10 +154,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__comp_ellint_1(__k); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type comp_ellint_1(_Tp __k) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__comp_ellint_1<__type>(__k); } @@ -1056,10 +173,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__comp_ellint_2(__k); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type comp_ellint_2(_Tp __k) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__comp_ellint_2<__type>(__k); } @@ -1075,10 +192,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__comp_ellint_3(__k, __nu); } template - inline typename __promote_2<_Tp, _Tpn>::__type + inline typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type comp_ellint_3(_Tp __k, _Tpn __nu) { - typedef typename __promote_2<_Tp, _Tpn>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tp, _Tpn>::__type __type; return __detail::__comp_ellint_3<__type>(__k, __nu); } @@ -1094,10 +211,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__conf_hyperg(__a, __c, __x); } template - inline typename __promote_3<_Tpa, _Tpc, _Tp>::__type + inline typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type conf_hyperg(_Tpa __a, _Tpc __c, _Tp __x) { - typedef typename __promote_3<_Tpa, _Tpc, _Tp>::__type __type; + typedef typename __gnu_cxx::__promote_3<_Tpa, _Tpc, _Tp>::__type __type; return __detail::__conf_hyperg<__type>(__a, __c, __x); } @@ -1113,10 +230,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__cyl_bessel_i(__nu, __x); } template - inline typename __promote_2<_Tpnu, _Tp>::__type + inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type cyl_bessel_i(_Tpnu __nu, _Tp __x) { - typedef typename __promote_2<_Tpnu, _Tp>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; return __detail::__cyl_bessel_i<__type>(__nu, __x); } @@ -1132,10 +249,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__cyl_bessel_j(__nu, __x); } template - inline typename __promote_2<_Tpnu, _Tp>::__type + inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type cyl_bessel_j(_Tpnu __nu, _Tp __x) { - typedef typename __promote_2<_Tpnu, _Tp>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; return __detail::__cyl_bessel_j<__type>(__nu, __x); } @@ -1151,10 +268,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__cyl_bessel_k(__nu, __x); } template - inline typename __promote_2<_Tpnu, _Tp>::__type + inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type cyl_bessel_k(_Tpnu __nu, _Tp __x) { - typedef typename __promote_2<_Tpnu, _Tp>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; return __detail::__cyl_bessel_k<__type>(__nu, __x); } @@ -1170,10 +287,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__cyl_neumann_n(__nu, __x); } template - inline typename __promote_2<_Tpnu, _Tp>::__type + inline typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type cyl_neumann(_Tpnu __nu, _Tp __x) { - typedef typename __promote_2<_Tpnu, _Tp>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tpnu, _Tp>::__type __type; return __detail::__cyl_neumann_n<__type>(__nu, __x); } @@ -1189,10 +306,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__ellint_1(__k, __phi); } template - inline typename __promote_2<_Tp, _Tpp>::__type + inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type ellint_1(_Tp __k, _Tpp __phi) { - typedef typename __promote_2<_Tp, _Tpp>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type; return __detail::__ellint_1<__type>(__k, __phi); } @@ -1208,10 +325,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__ellint_2(__k, __phi); } template - inline typename __promote_2<_Tp, _Tpp>::__type + inline typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type ellint_2(_Tp __k, _Tpp __phi) { - typedef typename __promote_2<_Tp, _Tpp>::__type __type; + typedef typename __gnu_cxx::__promote_2<_Tp, _Tpp>::__type __type; return __detail::__ellint_2<__type>(__k, __phi); } @@ -1227,10 +344,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__ellint_3(__k, __nu, __phi); } template - inline typename __promote_3<_Tp, _Tpn, _Tpp>::__type + inline typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type ellint_3(_Tp __k, _Tpn __nu, _Tpp __phi) { - typedef typename __promote_3<_Tp, _Tpn, _Tpp>::__type __type; + typedef typename __gnu_cxx::__promote_3<_Tp, _Tpn, _Tpp>::__type __type; return __detail::__ellint_3<__type>(__k, __nu, __phi); } @@ -1246,10 +363,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__expint(__x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type expint(_Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__expint<__type>(__x); } @@ -1265,10 +382,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__poly_hermite(__n, __x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type hermite(unsigned int __n, _Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__poly_hermite<__type>(__n, __x); } @@ -1284,10 +401,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__hyperg(__a, __b, __c, __x); } template - inline typename __promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type + inline typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type hyperg(_Tpa __a, _Tpb __b, _Tpc __c, _Tp __x) { - typedef typename __promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type __type; + typedef typename __gnu_cxx::__promote_4<_Tpa, _Tpb, _Tpc, _Tp>::__type __type; return __detail::__hyperg<__type>(__a, __b, __c, __x); } @@ -1303,10 +420,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__laguerre(__n, __x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type laguerre(unsigned int __n, _Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__laguerre<__type>(__n, __x); } @@ -1322,10 +439,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__poly_legendre_p(__n, __x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type legendre(unsigned int __n, _Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__poly_legendre_p<__type>(__n, __x); } @@ -1341,10 +458,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__riemann_zeta(__x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type riemann_zeta(_Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__riemann_zeta<__type>(__x); } @@ -1360,10 +477,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__sph_bessel(__n, __x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type sph_bessel(unsigned int __n, _Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__sph_bessel<__type>(__n, __x); } @@ -1379,10 +496,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__sph_legendre(__l, __m, __theta); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type sph_legendre(unsigned int __l, unsigned int __m, _Tp __theta) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__sph_legendre<__type>(__l, __m, __theta); } @@ -1398,18 +515,18 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { return __detail::__sph_neumann(__n, __x); } template - inline typename __promote<_Tp>::__type + inline typename __gnu_cxx::__promote<_Tp>::__type sph_neumann(unsigned int __n, _Tp __x) { - typedef typename __promote<_Tp>::__type __type; + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return __detail::__sph_neumann<__type>(__n, __x); } /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } #endif // __GXX_EXPERIMENTAL_CXX0X__ -#endif +#endif // _GLIBCXX_TR1_CMATH diff --git a/libstdc++-v3/include/tr1/common.h b/libstdc++-v3/include/tr1/common.h deleted file mode 100644 index d26fdd6..0000000 --- a/libstdc++-v3/include/tr1/common.h +++ /dev/null @@ -1,91 +0,0 @@ -// Internal header for TR1 complex -*- C++ -*- - -// Copyright (C) 2006 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/** @file tr1/common.h - * This is a TR1 C++ Library header. - */ - -#ifndef _TR1_COMMON_H -#define _TR1_COMMON_H 1 - -#include - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - template::value> - struct __promote - { typedef double __type; }; - - template - struct __promote<_Tp, false> - { typedef _Tp __type; }; - - template - struct __promote_2 - { - private: - typedef typename __promote<_Tp>::__type __type1; - typedef typename __promote<_Up>::__type __type2; - - public: - typedef __typeof__(__type1() + __type2()) __type; - }; - - template - struct __promote_3 - { - private: - typedef typename __promote<_Tp>::__type __type1; - typedef typename __promote<_Up>::__type __type2; - typedef typename __promote<_Vp>::__type __type3; - - public: - typedef __typeof__(__type1() + __type2() + __type3()) __type; - }; - - template - struct __promote_4 - { - private: - typedef typename __promote<_Tp>::__type __type1; - typedef typename __promote<_Up>::__type __type2; - typedef typename __promote<_Vp>::__type __type3; - typedef typename __promote<_Wp>::__type __type4; - - public: - typedef __typeof__(__type1() + __type2() + __type3() + __type4()) __type; - }; - -_GLIBCXX_END_NAMESPACE -} // namespace std - -#endif diff --git a/libstdc++-v3/include/tr1/complex b/libstdc++-v3/include/tr1/complex index 666cae9..ef21129 100644 --- a/libstdc++-v3/include/tr1/complex +++ b/libstdc++-v3/include/tr1/complex @@ -31,379 +31,46 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_COMPLEX -#define _TR1_COMPLEX 1 +#ifndef _GLIBCXX_TR1_COMPLEX +#define _GLIBCXX_TR1_COMPLEX 1 -#include -#include - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // Forward declarations. - template std::complex<_Tp> acos(const std::complex<_Tp>&); - template std::complex<_Tp> asin(const std::complex<_Tp>&); - template std::complex<_Tp> atan(const std::complex<_Tp>&); - - template std::complex<_Tp> acosh(const std::complex<_Tp>&); - template std::complex<_Tp> asinh(const std::complex<_Tp>&); - template std::complex<_Tp> atanh(const std::complex<_Tp>&); - template std::complex<_Tp> fabs(const std::complex<_Tp>&); - - /// @brief acos(__z) [8.1.2]. - // Effects: Behaves the same as C99 function cacos, defined - // in subclause 7.3.5.1. - template - inline std::complex<_Tp> - __complex_acos(const std::complex<_Tp>& __z) - { - const std::complex<_Tp> __t = std::_GLIBCXX_TR1::asin(__z); - const _Tp __pi_2 = 1.5707963267948966192313216916397514L; - return std::complex<_Tp>(__pi_2 - __t.real(), -__t.imag()); - } - -#if _GLIBCXX_USE_C99_COMPLEX_TR1 - inline __complex__ float - __complex_acos(__complex__ float __z) - { return __builtin_cacosf(__z); } - - inline __complex__ double - __complex_acos(__complex__ double __z) - { return __builtin_cacos(__z); } - - inline __complex__ long double - __complex_acos(const __complex__ long double& __z) - { return __builtin_cacosl(__z); } - - template - inline std::complex<_Tp> - acos(const std::complex<_Tp>& __z) - { return __complex_acos(__z.__rep()); } -#else - template - inline std::complex<_Tp> - acos(const std::complex<_Tp>& __z) - { return __complex_acos(__z); } -#endif - - /// @brief asin(__z) [8.1.3]. - // Effects: Behaves the same as C99 function casin, defined - // in subclause 7.3.5.2. - template - inline std::complex<_Tp> - __complex_asin(const std::complex<_Tp>& __z) - { - std::complex<_Tp> __t(-__z.imag(), __z.real()); - __t = std::_GLIBCXX_TR1::asinh(__t); - return std::complex<_Tp>(__t.imag(), -__t.real()); - } - -#if _GLIBCXX_USE_C99_COMPLEX_TR1 - inline __complex__ float - __complex_asin(__complex__ float __z) - { return __builtin_casinf(__z); } - - inline __complex__ double - __complex_asin(__complex__ double __z) - { return __builtin_casin(__z); } - - inline __complex__ long double - __complex_asin(const __complex__ long double& __z) - { return __builtin_casinl(__z); } - - template - inline std::complex<_Tp> - asin(const std::complex<_Tp>& __z) - { return __complex_asin(__z.__rep()); } -#else - template - inline std::complex<_Tp> - asin(const std::complex<_Tp>& __z) - { return __complex_asin(__z); } -#endif - - /// @brief atan(__z) [8.1.4]. - // Effects: Behaves the same as C99 function catan, defined - // in subclause 7.3.5.3. - template - std::complex<_Tp> - __complex_atan(const std::complex<_Tp>& __z) - { - const _Tp __r2 = __z.real() * __z.real(); - const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag(); - - _Tp __num = __z.imag() + _Tp(1.0); - _Tp __den = __z.imag() - _Tp(1.0); - - __num = __r2 + __num * __num; - __den = __r2 + __den * __den; - - return std::complex<_Tp>(_Tp(0.5) * atan2(_Tp(2.0) * __z.real(), __x), - _Tp(0.25) * log(__num / __den)); - } - -#if _GLIBCXX_USE_C99_COMPLEX_TR1 - inline __complex__ float - __complex_atan(__complex__ float __z) - { return __builtin_catanf(__z); } - - inline __complex__ double - __complex_atan(__complex__ double __z) - { return __builtin_catan(__z); } - - inline __complex__ long double - __complex_atan(const __complex__ long double& __z) - { return __builtin_catanl(__z); } - - template - inline std::complex<_Tp> - atan(const std::complex<_Tp>& __z) - { return __complex_atan(__z.__rep()); } -#else - template - inline std::complex<_Tp> - atan(const std::complex<_Tp>& __z) - { return __complex_atan(__z); } -#endif - - /// @brief acosh(__z) [8.1.5]. - // Effects: Behaves the same as C99 function cacosh, defined - // in subclause 7.3.6.1. - template - std::complex<_Tp> - __complex_acosh(const std::complex<_Tp>& __z) - { - std::complex<_Tp> __t((__z.real() - __z.imag()) - * (__z.real() + __z.imag()) - _Tp(1.0), - _Tp(2.0) * __z.real() * __z.imag()); - __t = std::sqrt(__t); - - return std::log(__t + __z); - } - -#if _GLIBCXX_USE_C99_COMPLEX_TR1 - inline __complex__ float - __complex_acosh(__complex__ float __z) - { return __builtin_cacoshf(__z); } - - inline __complex__ double - __complex_acosh(__complex__ double __z) - { return __builtin_cacosh(__z); } - - inline __complex__ long double - __complex_acosh(const __complex__ long double& __z) - { return __builtin_cacoshl(__z); } - - template - inline std::complex<_Tp> - acosh(const std::complex<_Tp>& __z) - { return __complex_acosh(__z.__rep()); } -#else - template - inline std::complex<_Tp> - acosh(const std::complex<_Tp>& __z) - { return __complex_acosh(__z); } -#endif - - /// @brief asinh(__z) [8.1.6]. - // Effects: Behaves the same as C99 function casin, defined - // in subclause 7.3.6.2. - template - std::complex<_Tp> - __complex_asinh(const std::complex<_Tp>& __z) - { - std::complex<_Tp> __t((__z.real() - __z.imag()) - * (__z.real() + __z.imag()) + _Tp(1.0), - _Tp(2.0) * __z.real() * __z.imag()); - __t = std::sqrt(__t); +#pragma GCC system_header - return std::log(__t + __z); - } - -#if _GLIBCXX_USE_C99_COMPLEX_TR1 - inline __complex__ float - __complex_asinh(__complex__ float __z) - { return __builtin_casinhf(__z); } - - inline __complex__ double - __complex_asinh(__complex__ double __z) - { return __builtin_casinh(__z); } - - inline __complex__ long double - __complex_asinh(const __complex__ long double& __z) - { return __builtin_casinhl(__z); } - - template - inline std::complex<_Tp> - asinh(const std::complex<_Tp>& __z) - { return __complex_asinh(__z.__rep()); } -#else - template - inline std::complex<_Tp> - asinh(const std::complex<_Tp>& __z) - { return __complex_asinh(__z); } +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header #endif - /// @brief atanh(__z) [8.1.7]. - // Effects: Behaves the same as C99 function catanh, defined - // in subclause 7.3.6.3. - template - std::complex<_Tp> - __complex_atanh(const std::complex<_Tp>& __z) - { - const _Tp __i2 = __z.imag() * __z.imag(); - const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real(); - - _Tp __num = _Tp(1.0) + __z.real(); - _Tp __den = _Tp(1.0) - __z.real(); - - __num = __i2 + __num * __num; - __den = __i2 + __den * __den; - - return std::complex<_Tp>(_Tp(0.25) * (log(__num) - log(__den)), - _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x)); - } - -#if _GLIBCXX_USE_C99_COMPLEX_TR1 - inline __complex__ float - __complex_atanh(__complex__ float __z) - { return __builtin_catanhf(__z); } - - inline __complex__ double - __complex_atanh(__complex__ double __z) - { return __builtin_catanh(__z); } - - inline __complex__ long double - __complex_atanh(const __complex__ long double& __z) - { return __builtin_catanhl(__z); } +#include +#include +#include - template - inline std::complex<_Tp> - atanh(const std::complex<_Tp>& __z) - { return __complex_atanh(__z.__rep()); } +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include #else - template - inline std::complex<_Tp> - atanh(const std::complex<_Tp>& __z) - { return __complex_atanh(__z); } +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif - /// @brief fabs(__z) [8.1.8]. - // Effects: Behaves the same as C99 function cabs, defined - // in subclause 7.3.8.1. - template - inline std::complex<_Tp> - fabs(const std::complex<_Tp>& __z) - { return std::abs(__z); } - - - /// @brief Additional overloads [8.1.9]. - // - - // See common.h for the primary template. - template - struct __promote_2, _Up> - { - public: - typedef std::complex::__type> __type; - }; - - template - struct __promote_2<_Tp, std::complex<_Up> > - { - public: - typedef std::complex::__type> __type; - }; - - template - struct __promote_2, std::complex<_Up> > - { - public: - typedef std::complex::__type> __type; - }; - - +namespace std +{ +namespace tr1 +{ using std::arg; - - template - inline typename __promote<_Tp>::__type - arg(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return std::arg(std::complex<__type>(__x)); - } - using std::conj; - - template - inline std::complex::__type> - conj(_Tp __x) - { return __x; } - using std::imag; - - template - inline typename __promote<_Tp>::__type - imag(_Tp) - { return _Tp(); } - using std::norm; - - template - inline typename __promote<_Tp>::__type - norm(_Tp __x) - { - typedef typename __promote<_Tp>::__type __type; - return __type(__x) * __type(__x); - } - using std::polar; - - template - inline std::complex::__type> - polar(const _Tp& __rho, const _Up& __theta) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return std::polar(__type(__rho), __type(__theta)); - } - using std::pow; - - template - inline std::complex::__type> - pow(const std::complex<_Tp>& __x, const _Up& __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return std::pow(std::complex<__type>(__x), __type(__y)); - } - - template - inline std::complex::__type> - pow(const _Tp& __x, const std::complex<_Up>& __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return std::pow(__type(__x), std::complex<__type>(__y)); - } - - template - inline std::complex::__type> - pow(const std::complex<_Tp>& __x, const std::complex<_Up>& __y) - { - typedef typename __promote_2<_Tp, _Up>::__type __type; - return std::pow(std::complex<__type>(__x), - std::complex<__type>(__y)); - } - using std::real; - - template - inline typename __promote<_Tp>::__type - real(_Tp __x) - { return __x; } - -_GLIBCXX_END_NAMESPACE +} } -#endif +#endif // _GLIBCXX_TR1_COMPLEX + diff --git a/libstdc++-v3/include/tr1/complex.h b/libstdc++-v3/include/tr1/complex.h index 12fadec..ad0c77d 100644 --- a/libstdc++-v3/include/tr1/complex.h +++ b/libstdc++-v3/include/tr1/complex.h @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_COMPLEX_H -#define _TR1_COMPLEX_H 1 +#ifndef _GLIBCXX_TR1_COMPLEX_H +#define _GLIBCXX_TR1_COMPLEX_H 1 #include -#endif +#endif // _GLIBCXX_TR1_COMPLEX_H diff --git a/libstdc++-v3/include/tr1/cstdarg b/libstdc++-v3/include/tr1/cstdarg index e70130e..20629e7 100644 --- a/libstdc++-v3/include/tr1/cstdarg +++ b/libstdc++-v3/include/tr1/cstdarg @@ -1,6 +1,6 @@ // TR1 cstdarg -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CSTDARG -#define _TR1_CSTDARG 1 +#ifndef _GLIBCXX_TR1_CSTDARG +#define _GLIBCXX_TR1_CSTDARG 1 #include -#endif +#endif // _GLIBCXX_TR1_CSTDARG diff --git a/libstdc++-v3/include/tr1/cstdbool b/libstdc++-v3/include/tr1/cstdbool index 939f2c7..4e43db3 100644 --- a/libstdc++-v3/include/tr1/cstdbool +++ b/libstdc++-v3/include/tr1/cstdbool @@ -31,8 +31,8 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CSTDBOOL -#define _TR1_CSTDBOOL 1 +#ifndef _GLIBCXX_TR1_CSTDBOOL +#define _GLIBCXX_TR1_CSTDBOOL 1 #include @@ -40,4 +40,4 @@ #include_next #endif -#endif +#endif // _GLIBCXX_TR1_CSTDBOOL diff --git a/libstdc++-v3/include/tr1/cstdint b/libstdc++-v3/include/tr1/cstdint index 56fa308..6f7ac76 100644 --- a/libstdc++-v3/include/tr1/cstdint +++ b/libstdc++-v3/include/tr1/cstdint @@ -31,62 +31,30 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CSTDINT -#define _TR1_CSTDINT 1 +#ifndef _GLIBCXX_TR1_CSTDINT +#define _GLIBCXX_TR1_CSTDINT 1 -#include - -#if _GLIBCXX_USE_C99_STDINT_TR1 - -// For 8.22.1/1 (see C99, Notes 219, 220, 222) -#define __STDC_LIMIT_MACROS -#define __STDC_CONSTANT_MACROS -#include_next - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - using ::int8_t; - using ::int16_t; - using ::int32_t; - using ::int64_t; - - using ::int_fast8_t; - using ::int_fast16_t; - using ::int_fast32_t; - using ::int_fast64_t; - - using ::int_least8_t; - using ::int_least16_t; - using ::int_least32_t; - using ::int_least64_t; +#pragma GCC system_header - using ::intmax_t; - using ::intptr_t; - - using ::uint8_t; - using ::uint16_t; - using ::uint32_t; - using ::uint64_t; - - using ::uint_fast8_t; - using ::uint_fast16_t; - using ::uint_fast32_t; - using ::uint_fast64_t; - - using ::uint_least8_t; - using ::uint_least16_t; - using ::uint_least32_t; - using ::uint_least64_t; - - using ::uintmax_t; - using ::uintptr_t; +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif -_GLIBCXX_END_NAMESPACE -} +#include +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -#endif +#endif // _GLIBCXX_TR1_CSTDINT + diff --git a/libstdc++-v3/include/tr1/cstdio b/libstdc++-v3/include/tr1/cstdio index b016a15..ddb1867 100644 --- a/libstdc++-v3/include/tr1/cstdio +++ b/libstdc++-v3/include/tr1/cstdio @@ -31,27 +31,29 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CSTDIO -#define _TR1_CSTDIO 1 +#ifndef _GLIBCXX_TR1_CSTDIO +#define _GLIBCXX_TR1_CSTDIO 1 -#include -#include - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - -#if _GLIBCXX_USE_C99 - using std::snprintf; - using std::vsnprintf; +#pragma GCC system_header - using std::vfscanf; - using std::vscanf; - using std::vsscanf; +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header #endif -_GLIBCXX_END_NAMESPACE -} +#include +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif + +#endif // _GLIBCXX_TR1_CSTDIO diff --git a/libstdc++-v3/include/tr1/cstdlib b/libstdc++-v3/include/tr1/cstdlib index 5096fa8..acacbcd 100644 --- a/libstdc++-v3/include/tr1/cstdlib +++ b/libstdc++-v3/include/tr1/cstdlib @@ -31,49 +31,29 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CSTDLIB -#define _TR1_CSTDLIB 1 +#ifndef _GLIBCXX_TR1_CSTDLIB +#define _GLIBCXX_TR1_CSTDLIB 1 -#include +#pragma GCC system_header -#if _GLIBCXX_HOSTED - -#include - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - -#if _GLIBCXX_USE_C99 - -#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC - // types - using std::lldiv_t; - - // functions - using std::llabs; - using std::lldiv; -#endif - - using std::atoll; - using std::strtoll; - using std::strtoull; - - using std::strtof; - using std::strtold; - - // overloads - using std::abs; -#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC - using std::div; +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header #endif -#endif - -_GLIBCXX_END_NAMESPACE -} +#include +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -#endif +#endif // _GLIBCXX_TR1_CSTDLIB diff --git a/libstdc++-v3/include/tr1/ctgmath b/libstdc++-v3/include/tr1/ctgmath index eb91185..2f6af68 100644 --- a/libstdc++-v3/include/tr1/ctgmath +++ b/libstdc++-v3/include/tr1/ctgmath @@ -1,6 +1,6 @@ // TR1 ctgmath -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CTGMATH -#define _TR1_CTGMATH 1 +#ifndef _GLIBCXX_TR1_CTGMATH +#define _GLIBCXX_TR1_CTGMATH 1 #include -#endif +#endif // _GLIBCXX_TR1_CTGMATH diff --git a/libstdc++-v3/include/tr1/ctime b/libstdc++-v3/include/tr1/ctime index 45e0839..4c14cca 100644 --- a/libstdc++-v3/include/tr1/ctime +++ b/libstdc++-v3/include/tr1/ctime @@ -1,6 +1,6 @@ // TR1 ctime -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CTIME -#define _TR1_CTIME 1 +#ifndef _GLIBCXX_TR1_CTIME +#define _GLIBCXX_TR1_CTIME 1 #include -#endif +#endif // _GLIBCXX_TR1_CTIME diff --git a/libstdc++-v3/include/tr1/cwchar b/libstdc++-v3/include/tr1/cwchar index abc88bb..c6fb88e 100644 --- a/libstdc++-v3/include/tr1/cwchar +++ b/libstdc++-v3/include/tr1/cwchar @@ -1,6 +1,6 @@ // TR1 cwchar -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,42 +31,29 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CWCHAR -#define _TR1_CWCHAR 1 +#ifndef _GLIBCXX_TR1_CWCHAR +#define _GLIBCXX_TR1_CWCHAR 1 -#include +#pragma GCC system_header -#if _GLIBCXX_USE_WCHAR_T - -#include - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - -#if _GLIBCXX_HAVE_WCSTOF - using std::wcstof; -#endif -#if _GLIBCXX_HAVE_VFWSCANF - using std::vfwscanf; -#endif -#if _GLIBCXX_HAVE_VSWSCANF - using std::vswscanf; -#endif -#if _GLIBCXX_HAVE_VWSCANF - using std::vwscanf; -#endif - -#if _GLIBCXX_USE_C99 - using std::wcstold; - using std::wcstoll; - using std::wcstoull; +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header #endif -_GLIBCXX_END_NAMESPACE -} +#include +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -#endif +#endif // _GLIBCXX_TR1_CWCHAR diff --git a/libstdc++-v3/include/tr1/cwctype b/libstdc++-v3/include/tr1/cwctype index f6e99be..2b2b367 100644 --- a/libstdc++-v3/include/tr1/cwctype +++ b/libstdc++-v3/include/tr1/cwctype @@ -1,6 +1,6 @@ // TR1 cwctype -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,27 +31,29 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_CWCTYPE -#define _TR1_CWCTYPE 1 +#ifndef _GLIBCXX_TR1_CWCTYPE +#define _GLIBCXX_TR1_CWCTYPE 1 -#include +#pragma GCC system_header -#if _GLIBCXX_USE_WCHAR_T +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif #include -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - -#if _GLIBCXX_HAVE_ISWBLANK - using std::iswblank; -#endif - -_GLIBCXX_END_NAMESPACE -} - +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif -#endif +#endif // _GLIBCXX_TR1_CWCTYPE diff --git a/libstdc++-v3/include/tr1/ell_integral.tcc b/libstdc++-v3/include/tr1/ell_integral.tcc index 03cfefa..745b379 100644 --- a/libstdc++-v3/include/tr1/ell_integral.tcc +++ b/libstdc++-v3/include/tr1/ell_integral.tcc @@ -45,12 +45,13 @@ // W. T. Vetterling, B. P. Flannery, Cambridge University Press // (1992), pp. 261-269 -#ifndef _TR1_ELL_INTEGRAL_TCC -#define _TR1_ELL_INTEGRAL_TCC 1 +#ifndef _GLIBCXX_TR1_ELL_INTEGRAL_TCC +#define _GLIBCXX_TR1_ELL_INTEGRAL_TCC 1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -755,8 +756,8 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_ELL_INTEGRAL_TCC +#endif // _GLIBCXX_TR1_ELL_INTEGRAL_TCC diff --git a/libstdc++-v3/include/tr1/exp_integral.tcc b/libstdc++-v3/include/tr1/exp_integral.tcc index d6acc72..fa016fc 100644 --- a/libstdc++-v3/include/tr1/exp_integral.tcc +++ b/libstdc++-v3/include/tr1/exp_integral.tcc @@ -48,14 +48,15 @@ // 2nd ed, pp. 222-225. // -#ifndef _TR1_EXP_INTEGRAL_TCC -#define _TR1_EXP_INTEGRAL_TCC 1 +#ifndef _GLIBCXX_TR1_EXP_INTEGRAL_TCC +#define _GLIBCXX_TR1_EXP_INTEGRAL_TCC 1 #include "special_function_util.h" namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -532,7 +533,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_EXP_INTEGRAL_TCC +#endif // _GLIBCXX_TR1_EXP_INTEGRAL_TCC diff --git a/libstdc++-v3/include/tr1/functional b/libstdc++-v3/include/tr1/functional index 1fcc0dc..d3afe76 100644 --- a/libstdc++-v3/include/tr1/functional +++ b/libstdc++-v3/include/tr1/functional @@ -31,2280 +31,38 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_FUNCTIONAL -#define _TR1_FUNCTIONAL 1 +#ifndef _GLIBCXX_TR1_FUNCTIONAL +#define _GLIBCXX_TR1_FUNCTIONAL 1 #pragma GCC system_header -#include // for std::frexp -#include // for std::tr1::hash -#include +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif + +#include +#include + +#include +#include #include +#include #include #include -#include - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - template - class _Mem_fn; - - /** - * @if maint - * Actual implementation of _Has_result_type, which uses SFINAE to - * determine if the type _Tp has a publicly-accessible member type - * result_type. - * @endif - */ - template - class _Has_result_type_helper : __sfinae_types - { - template - struct _Wrap_type - { }; - - template - static __one __test(_Wrap_type*); - - template - static __two __test(...); - - public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; - }; - - template - struct _Has_result_type - : integral_constant::type>::value> - { }; - - /** - * @if maint - * If we have found a result_type, extract it. - * @endif - */ - template - struct _Maybe_get_result_type - { }; - - template - struct _Maybe_get_result_type - { - typedef typename _Functor::result_type result_type; - }; - - /** - * @if maint - * Base class for any function object that has a weak result type, as - * defined in 3.3/3 of TR1. - * @endif - */ - template - struct _Weak_result_type_impl - : _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor> - { - }; - - /** - * @if maint - * Retrieve the result type for a function type. - * @endif - */ - template - struct _Weak_result_type_impl<_Res(_ArgTypes...)> - { - typedef _Res result_type; - }; - - /** - * @if maint - * Retrieve the result type for a function reference. - * @endif - */ - template - struct _Weak_result_type_impl<_Res(&)(_ArgTypes...)> - { - typedef _Res result_type; - }; - - /** - * @if maint - * Retrieve the result type for a function pointer. - * @endif - */ - template - struct _Weak_result_type_impl<_Res(*)(_ArgTypes...)> - { - typedef _Res result_type; - }; - - /** - * @if maint - * Retrieve result type for a member function pointer. - * @endif maint - */ - template - struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)> - { - typedef _Res result_type; - }; - - /** - * @if maint - * Retrieve result type for a const member function pointer. - * @endif maint - */ - template - struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) const> - { - typedef _Res result_type; - }; - - /** - * @if maint - * Retrieve result type for a volatile member function pointer. - * @endif maint - */ - template - struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) volatile> - { - typedef _Res result_type; - }; - - /** - * @if maint - * Retrieve result type for a const volatile member function pointer. - * @endif maint - */ - template - struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)const volatile> - { - typedef _Res result_type; - }; - - /** - * @if maint - * Strip top-level cv-qualifiers from the function object and let - * _Weak_result_type_impl perform the real work. - * @endif - */ - template - struct _Weak_result_type - : _Weak_result_type_impl::type> - { - }; - - template - class result_of; - - /** - * @if maint - * Actual implementation of result_of. When _Has_result_type is - * true, gets its result from _Weak_result_type. Otherwise, uses - * the function object's member template result to extract the - * result type. - * @endif - */ - template - struct _Result_of_impl; - - // Handle member data pointers using _Mem_fn's logic - template - struct _Result_of_impl - { - typedef typename _Mem_fn<_Res _Class::*> - ::template _Result_type<_T1>::type type; - }; - - /** - * @if maint - * Determine whether we can determine a result type from @c Functor - * alone. - * @endif - */ - template - class result_of<_Functor(_ArgTypes...)> - : public _Result_of_impl< - _Has_result_type<_Weak_result_type<_Functor> >::value, - _Functor(_ArgTypes...)> - { - }; - - /** - * @if maint - * We already know the result type for @c Functor; use it. - * @endif - */ - template - struct _Result_of_impl - { - typedef typename _Weak_result_type<_Functor>::result_type type; - }; - - /** - * @if maint - * We need to compute the result type for this invocation the hard - * way. - * @endif - */ - template - struct _Result_of_impl - { - typedef typename _Functor - ::template result<_Functor(_ArgTypes...)>::type type; - }; - - /** - * @if maint - * It is unsafe to access ::result when there are zero arguments, so we - * return @c void instead. - * @endif - */ - template - struct _Result_of_impl - { - typedef void type; - }; - - /** - * @if maint - * Determines if the type _Tp derives from unary_function. - * @endif - */ - template - struct _Derives_from_unary_function : __sfinae_types - { - private: - template - static __one __test(const volatile unary_function<_T1, _Res>*); - - // It's tempting to change "..." to const volatile void*, but - // that fails when _Tp is a function type. - static __two __test(...); - - public: - static const bool value = sizeof(__test((_Tp*)0)) == 1; - }; - - /** - * @if maint - * Determines if the type _Tp derives from binary_function. - * @endif - */ - template - struct _Derives_from_binary_function : __sfinae_types - { - private: - template - static __one __test(const volatile binary_function<_T1, _T2, _Res>*); - - // It's tempting to change "..." to const volatile void*, but - // that fails when _Tp is a function type. - static __two __test(...); - - public: - static const bool value = sizeof(__test((_Tp*)0)) == 1; - }; - - /** - * @if maint - * Turns a function type into a function pointer type - * @endif - */ - template::value> - struct _Function_to_function_pointer - { - typedef _Tp type; - }; - - template - struct _Function_to_function_pointer<_Tp, true> - { - typedef _Tp* type; - }; - - /** - * @if maint - * Invoke a function object, which may be either a member pointer or a - * function object. The first parameter will tell which. - * @endif - */ - template - inline - typename __gnu_cxx::__enable_if< - (!is_member_pointer<_Functor>::value - && !is_function<_Functor>::value - && !is_function::type>::value), - typename result_of<_Functor(_Args...)>::type - >::__type - __invoke(_Functor& __f, _Args&... __args) - { - return __f(__args...); - } - - template - inline - typename __gnu_cxx::__enable_if< - (is_member_pointer<_Functor>::value - && !is_function<_Functor>::value - && !is_function::type>::value), - typename result_of<_Functor(_Args...)>::type - >::__type - __invoke(_Functor& __f, _Args&... __args) - { - return mem_fn(__f)(__args...); - } - - // To pick up function references (that will become function pointers) - template - inline - typename __gnu_cxx::__enable_if< - (is_pointer<_Functor>::value - && is_function::type>::value), - typename result_of<_Functor(_Args...)>::type - >::__type - __invoke(_Functor __f, _Args&... __args) - { - return __f(__args...); - } - - /** - * @if maint - * Knowing which of unary_function and binary_function _Tp derives - * from, derives from the same and ensures that reference_wrapper - * will have a weak result type. See cases below. - * @endif - */ - template - struct _Reference_wrapper_base_impl; - - // Not a unary_function or binary_function, so try a weak result type - template - struct _Reference_wrapper_base_impl - : _Weak_result_type<_Tp> - { }; - - // unary_function but not binary_function - template - struct _Reference_wrapper_base_impl - : unary_function - { }; - - // binary_function but not unary_function - template - struct _Reference_wrapper_base_impl - : binary_function - { }; - - // both unary_function and binary_function. import result_type to - // avoid conflicts. - template - struct _Reference_wrapper_base_impl - : unary_function, - binary_function - { - typedef typename _Tp::result_type result_type; - }; - - /** - * @if maint - * Derives from unary_function or binary_function when it - * can. Specializations handle all of the easy cases. The primary - * template determines what to do with a class type, which may - * derive from both unary_function and binary_function. - * @endif - */ - template - struct _Reference_wrapper_base - : _Reference_wrapper_base_impl< - _Derives_from_unary_function<_Tp>::value, - _Derives_from_binary_function<_Tp>::value, - _Tp> - { }; - - // - a function type (unary) - template - struct _Reference_wrapper_base<_Res(_T1)> - : unary_function<_T1, _Res> - { }; - - // - a function type (binary) - template - struct _Reference_wrapper_base<_Res(_T1, _T2)> - : binary_function<_T1, _T2, _Res> - { }; - - // - a function pointer type (unary) - template - struct _Reference_wrapper_base<_Res(*)(_T1)> - : unary_function<_T1, _Res> - { }; - - // - a function pointer type (binary) - template - struct _Reference_wrapper_base<_Res(*)(_T1, _T2)> - : binary_function<_T1, _T2, _Res> - { }; - - // - a pointer to member function type (unary, no qualifiers) - template - struct _Reference_wrapper_base<_Res (_T1::*)()> - : unary_function<_T1*, _Res> - { }; - - // - a pointer to member function type (binary, no qualifiers) - template - struct _Reference_wrapper_base<_Res (_T1::*)(_T2)> - : binary_function<_T1*, _T2, _Res> - { }; - - // - a pointer to member function type (unary, const) - template - struct _Reference_wrapper_base<_Res (_T1::*)() const> - : unary_function - { }; - - // - a pointer to member function type (binary, const) - template - struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const> - : binary_function - { }; - - // - a pointer to member function type (unary, volatile) - template - struct _Reference_wrapper_base<_Res (_T1::*)() volatile> - : unary_function - { }; - - // - a pointer to member function type (binary, volatile) - template - struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile> - : binary_function - { }; - - // - a pointer to member function type (unary, const volatile) - template - struct _Reference_wrapper_base<_Res (_T1::*)() const volatile> - : unary_function - { }; - - // - a pointer to member function type (binary, const volatile) - template - struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile> - : binary_function - { }; - - template - class reference_wrapper - : public _Reference_wrapper_base::type> - { - // If _Tp is a function type, we can't form result_of<_Tp(...)>, - // so turn it into a function pointer type. - typedef typename _Function_to_function_pointer<_Tp>::type - _M_func_type; - - _Tp* _M_data; - public: - typedef _Tp type; - - explicit - reference_wrapper(_Tp& __indata): _M_data(&__indata) - { } - - reference_wrapper(const reference_wrapper<_Tp>& __inref): - _M_data(__inref._M_data) - { } - - reference_wrapper& - operator=(const reference_wrapper<_Tp>& __inref) - { - _M_data = __inref._M_data; - return *this; - } - - operator _Tp&() const - { return this->get(); } - - _Tp& - get() const - { return *_M_data; } - - template - typename result_of<_M_func_type(_Args...)>::type - operator()(_Args&... __args) const - { - return __invoke(get(), __args...); - } - }; - - - // Denotes a reference should be taken to a variable. - template - inline reference_wrapper<_Tp> - ref(_Tp& __t) - { return reference_wrapper<_Tp>(__t); } - - // Denotes a const reference should be taken to a variable. - template - inline reference_wrapper - cref(const _Tp& __t) - { return reference_wrapper(__t); } - - template - inline reference_wrapper<_Tp> - ref(reference_wrapper<_Tp> __t) - { return ref(__t.get()); } - - template - inline reference_wrapper - cref(reference_wrapper<_Tp> __t) - { return cref(__t.get()); } - - template - struct _Mem_fn_const_or_non - { - typedef const _Tp& type; - }; - - template - struct _Mem_fn_const_or_non<_Tp, false> - { - typedef _Tp& type; - }; - - /** - * @if maint - * Derives from @c unary_function or @c binary_function, or perhaps - * nothing, depending on the number of arguments provided. The - * primary template is the basis case, which derives nothing. - * @endif maint - */ - template - struct _Maybe_unary_or_binary_function { }; - - /** - * @if maint - * Derives from @c unary_function, as appropriate. - * @endif - */ - template - struct _Maybe_unary_or_binary_function<_Res, _T1> - : std::unary_function<_T1, _Res> { }; - - /** - * @if maint - * Derives from @c binary_function, as appropriate. - * @endif - */ - template - struct _Maybe_unary_or_binary_function<_Res, _T1, _T2> - : std::binary_function<_T1, _T2, _Res> { }; - - /** - * @if maint - * Implementation of @c mem_fn for member function pointers. - * @endif - */ - template - class _Mem_fn<_Res (_Class::*)(_ArgTypes...)> - : public _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...> - { - typedef _Res (_Class::*_Functor)(_ArgTypes...); - - template - _Res - _M_call(_Tp& __object, const volatile _Class *, - _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - template - _Res - _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const - { return ((*__ptr).*__pmf)(__args...); } - - public: - typedef _Res result_type; - - explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } - - // Handle objects - _Res - operator()(_Class& __object, _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - // Handle pointers - _Res - operator()(_Class* __object, _ArgTypes... __args) const - { return (__object->*__pmf)(__args...); } - - // Handle smart pointers, references and pointers to derived - template - _Res - operator()(_Tp& __object, _ArgTypes... __args) const - { return _M_call(__object, &__object, __args...); } - - private: - _Functor __pmf; - }; - - /** - * @if maint - * Implementation of @c mem_fn for const member function pointers. - * @endif - */ - template - class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const> - : public _Maybe_unary_or_binary_function<_Res, const _Class*, - _ArgTypes...> - { - typedef _Res (_Class::*_Functor)(_ArgTypes...) const; - - template - _Res - _M_call(_Tp& __object, const volatile _Class *, - _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - template - _Res - _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const - { return ((*__ptr).*__pmf)(__args...); } - - public: - typedef _Res result_type; - - explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } - - // Handle objects - _Res - operator()(const _Class& __object, _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - // Handle pointers - _Res - operator()(const _Class* __object, _ArgTypes... __args) const - { return (__object->*__pmf)(__args...); } - - // Handle smart pointers, references and pointers to derived - template - _Res operator()(_Tp& __object, _ArgTypes... __args) const - { return _M_call(__object, &__object, __args...); } - - private: - _Functor __pmf; - }; - - /** - * @if maint - * Implementation of @c mem_fn for volatile member function pointers. - * @endif - */ - template - class _Mem_fn<_Res (_Class::*)(_ArgTypes...) volatile> - : public _Maybe_unary_or_binary_function<_Res, volatile _Class*, - _ArgTypes...> - { - typedef _Res (_Class::*_Functor)(_ArgTypes...) volatile; - - template - _Res - _M_call(_Tp& __object, const volatile _Class *, - _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - template - _Res - _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const - { return ((*__ptr).*__pmf)(__args...); } - - public: - typedef _Res result_type; - - explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } - - // Handle objects - _Res - operator()(volatile _Class& __object, _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - // Handle pointers - _Res - operator()(volatile _Class* __object, _ArgTypes... __args) const - { return (__object->*__pmf)(__args...); } - - // Handle smart pointers, references and pointers to derived - template - _Res - operator()(_Tp& __object, _ArgTypes... __args) const - { return _M_call(__object, &__object, __args...); } - - private: - _Functor __pmf; - }; - - /** - * @if maint - * Implementation of @c mem_fn for const volatile member function pointers. - * @endif - */ - template - class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const volatile> - : public _Maybe_unary_or_binary_function<_Res, const volatile _Class*, - _ArgTypes...> - { - typedef _Res (_Class::*_Functor)(_ArgTypes...) const volatile; - - template - _Res - _M_call(_Tp& __object, const volatile _Class *, - _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - template - _Res - _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const - { return ((*__ptr).*__pmf)(__args...); } - - public: - typedef _Res result_type; - - explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } - - // Handle objects - _Res - operator()(const volatile _Class& __object, _ArgTypes... __args) const - { return (__object.*__pmf)(__args...); } - - // Handle pointers - _Res - operator()(const volatile _Class* __object, _ArgTypes... __args) const - { return (__object->*__pmf)(__args...); } - - // Handle smart pointers, references and pointers to derived - template - _Res operator()(_Tp& __object, _ArgTypes... __args) const - { return _M_call(__object, &__object, __args...); } - - private: - _Functor __pmf; - }; - - - template - class _Mem_fn<_Res _Class::*> - { - // This bit of genius is due to Peter Dimov, improved slightly by - // Douglas Gregor. - template - _Res& - _M_call(_Tp& __object, _Class *) const - { return __object.*__pm; } - - template - _Res& - _M_call(_Tp& __object, _Up * const *) const - { return (*__object).*__pm; } - - template - const _Res& - _M_call(_Tp& __object, const _Up * const *) const - { return (*__object).*__pm; } - - template - const _Res& - _M_call(_Tp& __object, const _Class *) const - { return __object.*__pm; } - - template - const _Res& - _M_call(_Tp& __ptr, const volatile void*) const - { return (*__ptr).*__pm; } - - template static _Tp& __get_ref(); - - template - static __sfinae_types::__one __check_const(_Tp&, _Class*); - template - static __sfinae_types::__one __check_const(_Tp&, _Up * const *); - template - static __sfinae_types::__two __check_const(_Tp&, const _Up * const *); - template - static __sfinae_types::__two __check_const(_Tp&, const _Class*); - template - static __sfinae_types::__two __check_const(_Tp&, const volatile void*); - - public: - template - struct _Result_type - : _Mem_fn_const_or_non<_Res, - (sizeof(__sfinae_types::__two) - == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))> - { }; - - template - struct result; - - template - struct result<_CVMem(_Tp)> - : public _Result_type<_Tp> { }; - - template - struct result<_CVMem(_Tp&)> - : public _Result_type<_Tp> { }; - - explicit - _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { } - - // Handle objects - _Res& - operator()(_Class& __object) const - { return __object.*__pm; } - - const _Res& - operator()(const _Class& __object) const - { return __object.*__pm; } - - // Handle pointers - _Res& - operator()(_Class* __object) const - { return __object->*__pm; } - - const _Res& - operator()(const _Class* __object) const - { return __object->*__pm; } - - // Handle smart pointers and derived - template - typename _Result_type<_Tp>::type - operator()(_Tp& __unknown) const - { return _M_call(__unknown, &__unknown); } - - private: - _Res _Class::*__pm; - }; - - /** - * @brief Returns a function object that forwards to the member - * pointer @a pm. - */ - template - inline _Mem_fn<_Tp _Class::*> - mem_fn(_Tp _Class::* __pm) - { - return _Mem_fn<_Tp _Class::*>(__pm); - } - - /** - * @brief Determines if the given type _Tp is a function object - * should be treated as a subexpression when evaluating calls to - * function objects returned by bind(). [TR1 3.6.1] - */ - template - struct is_bind_expression - { static const bool value = false; }; - - template - const bool is_bind_expression<_Tp>::value; - - /** - * @brief Determines if the given type _Tp is a placeholder in a - * bind() expression and, if so, which placeholder it is. [TR1 3.6.2] - */ - template - struct is_placeholder - { static const int value = 0; }; - - template - const int is_placeholder<_Tp>::value; - - /** - * @if maint - * The type of placeholder objects defined by libstdc++. - * @endif - */ - template struct _Placeholder { }; - - // Define a large number of placeholders. There is no way to - // simplify this with variadic templates, because we're introducing - // unique names for each. - namespace placeholders { namespace { - _Placeholder<1> _1; - _Placeholder<2> _2; - _Placeholder<3> _3; - _Placeholder<4> _4; - _Placeholder<5> _5; - _Placeholder<6> _6; - _Placeholder<7> _7; - _Placeholder<8> _8; - _Placeholder<9> _9; - _Placeholder<10> _10; - _Placeholder<11> _11; - _Placeholder<12> _12; - _Placeholder<13> _13; - _Placeholder<14> _14; - _Placeholder<15> _15; - _Placeholder<16> _16; - _Placeholder<17> _17; - _Placeholder<18> _18; - _Placeholder<19> _19; - _Placeholder<20> _20; - _Placeholder<21> _21; - _Placeholder<22> _22; - _Placeholder<23> _23; - _Placeholder<24> _24; - _Placeholder<25> _25; - _Placeholder<26> _26; - _Placeholder<27> _27; - _Placeholder<28> _28; - _Placeholder<29> _29; - } } - - /** - * @if maint - * Partial specialization of is_placeholder that provides the placeholder - * number for the placeholder objects defined by libstdc++. - * @endif - */ - template - struct is_placeholder<_Placeholder<_Num> > - { static const int value = _Num; }; - - template - const int is_placeholder<_Placeholder<_Num> >::value; - - /** - * @if maint - * Stores a tuple of indices. Used by bind() to extract the elements - * in a tuple. - * @endif - */ - template - struct _Index_tuple { }; - - /** - * @if maint - * Builds an _Index_tuple<0, 1, 2, ..., _Num-1>. - * @endif - */ - template > - struct _Build_index_tuple; - - template - struct _Build_index_tuple<_Num, _Index_tuple<_Indexes...> > - : _Build_index_tuple<_Num - 1, - _Index_tuple<_Indexes..., sizeof...(_Indexes)> > - { - }; - - template - struct _Build_index_tuple<0, _Index_tuple<_Indexes...> > - { - typedef _Index_tuple<_Indexes...> __type; - }; - - /** - * @if maint - * Used by _Safe_tuple_element to indicate that there is no tuple - * element at this position. - * @endif - */ - struct _No_tuple_element; - - /** - * @if maint - * Implementation helper for _Safe_tuple_element. This primary - * template handles the case where it is safe to use @c - * tuple_element. - * @endif - */ - template - struct _Safe_tuple_element_impl - : tuple_element<__i, _Tuple> { }; - - /** - * @if maint - * Implementation helper for _Safe_tuple_element. This partial - * specialization handles the case where it is not safe to use @c - * tuple_element. We just return @c _No_tuple_element. - * @endif - */ - template - struct _Safe_tuple_element_impl<__i, _Tuple, false> - { - typedef _No_tuple_element type; - }; - - /** - * Like tuple_element, but returns @c _No_tuple_element when - * tuple_element would return an error. - */ - template - struct _Safe_tuple_element - : _Safe_tuple_element_impl<__i, _Tuple, - (__i >= 0 && __i < tuple_size<_Tuple>::value)> - { - }; - - /** - * @if maint - * Maps an argument to bind() into an actual argument to the bound - * function object [TR1 3.6.3/5]. Only the first parameter should - * be specified: the rest are used to determine among the various - * implementations. Note that, although this class is a function - * object, isn't not entirely normal because it takes only two - * parameters regardless of the number of parameters passed to the - * bind expression. The first parameter is the bound argument and - * the second parameter is a tuple containing references to the - * rest of the arguments. - * @endif - */ - template::value, - bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)> - class _Mu; - - /** - * @if maint - * If the argument is reference_wrapper<_Tp>, returns the - * underlying reference. [TR1 3.6.3/5 bullet 1] - * @endif - */ - template - class _Mu, false, false> - { - public: - typedef _Tp& result_type; - - /* Note: This won't actually work for const volatile - * reference_wrappers, because reference_wrapper::get() is const - * but not volatile-qualified. This might be a defect in the TR. - */ - template - result_type - operator()(_CVRef& __arg, const _Tuple&) const volatile - { return __arg.get(); } - }; - - /** - * @if maint - * If the argument is a bind expression, we invoke the underlying - * function object with the same cv-qualifiers as we are given and - * pass along all of our arguments (unwrapped). [TR1 3.6.3/5 bullet 2] - * @endif - */ - template - class _Mu<_Arg, true, false> - { - public: - template class result; - - // Determine the result type when we pass the arguments along. This - // involves passing along the cv-qualifiers placed on _Mu and - // unwrapping the argument bundle. - template - class result<_CVMu(_CVArg, tuple<_Args...>)> - : public result_of<_CVArg(_Args...)> { }; - - template - typename result_of<_CVArg(_Args...)>::type - operator()(_CVArg& __arg, - const tuple<_Args...>& __tuple) const volatile - { - // Construct an index tuple and forward to __call - typedef typename _Build_index_tuple::__type - _Indexes; - return this->__call(__arg, __tuple, _Indexes()); - } - - private: - // Invokes the underlying function object __arg by unpacking all - // of the arguments in the tuple. - template - typename result_of<_CVArg(_Args...)>::type - __call(_CVArg& __arg, const tuple<_Args...>& __tuple, - const _Index_tuple<_Indexes...>&) const volatile - { - return __arg(_GLIBCXX_TR1::get<_Indexes>(__tuple)...); - } - }; - - /** - * @if maint - * If the argument is a placeholder for the Nth argument, returns - * a reference to the Nth argument to the bind function object. - * [TR1 3.6.3/5 bullet 3] - * @endif - */ - template - class _Mu<_Arg, false, true> - { - public: - template class result; - - template - class result<_CVMu(_CVArg, _Tuple)> - { - // Add a reference, if it hasn't already been done for us. - // This allows us to be a little bit sloppy in constructing - // the tuple that we pass to result_of<...>. - typedef typename _Safe_tuple_element<(is_placeholder<_Arg>::value - - 1), _Tuple>::type - __base_type; - - public: - typedef typename add_reference<__base_type>::type type; - }; - - template - typename result<_Mu(_Arg, _Tuple)>::type - operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile - { - return ::std::_GLIBCXX_TR1::get<(is_placeholder<_Arg>::value - - 1)>(__tuple); - } - }; - - /** - * @if maint - * If the argument is just a value, returns a reference to that - * value. The cv-qualifiers on the reference are the same as the - * cv-qualifiers on the _Mu object. [TR1 3.6.3/5 bullet 4] - * @endif - */ - template - class _Mu<_Arg, false, false> - { - public: - template struct result; - - template - struct result<_CVMu(_CVArg, _Tuple)> - { - typedef typename add_reference<_CVArg>::type type; - }; - - // Pick up the cv-qualifiers of the argument - template - _CVArg& - operator()(_CVArg& __arg, const _Tuple&) const volatile - { return __arg; } - }; - - /** - * @if maint - * Maps member pointers into instances of _Mem_fn but leaves all - * other function objects untouched. Used by tr1::bind(). The - * primary template handles the non--member-pointer case. - * @endif - */ - template - struct _Maybe_wrap_member_pointer - { - typedef _Tp type; - - static const _Tp& - __do_wrap(const _Tp& __x) - { return __x; } - }; - - /** - * @if maint - * Maps member pointers into instances of _Mem_fn but leaves all - * other function objects untouched. Used by tr1::bind(). This - * partial specialization handles the member pointer case. - * @endif - */ - template - struct _Maybe_wrap_member_pointer<_Tp _Class::*> - { - typedef _Mem_fn<_Tp _Class::*> type; - - static type - __do_wrap(_Tp _Class::* __pm) - { return type(__pm); } - }; - - /** - * @if maint - * Type of the function object returned from bind(). - * @endif - */ - template - struct _Bind; - - template - class _Bind<_Functor(_Bound_args...)> - : public _Weak_result_type<_Functor> - { - typedef _Bind __self_type; - typedef typename _Build_index_tuple::__type - _Bound_indexes; - - _Functor _M_f; - tuple<_Bound_args...> _M_bound_args; - - // Call unqualified - template - typename result_of< - _Functor(typename result_of<_Mu<_Bound_args> - (_Bound_args, tuple<_Args...>)>::type...) - >::type - __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - // Call as const - template - typename result_of< - const _Functor(typename result_of<_Mu<_Bound_args> - (const _Bound_args, tuple<_Args...>) - >::type...)>::type - __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - // Call as volatile - template - typename result_of< - volatile _Functor(typename result_of<_Mu<_Bound_args> - (volatile _Bound_args, tuple<_Args...>) - >::type...)>::type - __call(const tuple<_Args...>& __args, - _Index_tuple<_Indexes...>) volatile - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - // Call as const volatile - template - typename result_of< - const volatile _Functor(typename result_of<_Mu<_Bound_args> - (const volatile _Bound_args, - tuple<_Args...>) - >::type...)>::type - __call(const tuple<_Args...>& __args, - _Index_tuple<_Indexes...>) const volatile - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - public: - explicit _Bind(_Functor __f, _Bound_args... __bound_args) - : _M_f(__f), _M_bound_args(__bound_args...) { } - - // Call unqualified - template - typename result_of< - _Functor(typename result_of<_Mu<_Bound_args> - (_Bound_args, tuple<_Args...>)>::type...) - >::type - operator()(_Args&... __args) - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - - // Call as const - template - typename result_of< - const _Functor(typename result_of<_Mu<_Bound_args> - (const _Bound_args, tuple<_Args...>)>::type...) - >::type - operator()(_Args&... __args) const - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - - - // Call as volatile - template - typename result_of< - volatile _Functor(typename result_of<_Mu<_Bound_args> - (volatile _Bound_args, tuple<_Args...>)>::type...) - >::type - operator()(_Args&... __args) volatile - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - - - // Call as const volatile - template - typename result_of< - const volatile _Functor(typename result_of<_Mu<_Bound_args> - (const volatile _Bound_args, - tuple<_Args...>)>::type...) - >::type - operator()(_Args&... __args) const volatile - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - }; - - /** - * @if maint - * Type of the function object returned from bind(). - * @endif - */ - template - struct _Bind_result; - - template - class _Bind_result<_Result, _Functor(_Bound_args...)> - { - typedef _Bind_result __self_type; - typedef typename _Build_index_tuple::__type - _Bound_indexes; - - _Functor _M_f; - tuple<_Bound_args...> _M_bound_args; - - // Call unqualified - template - _Result - __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - // Call as const - template - _Result - __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - // Call as volatile - template - _Result - __call(const tuple<_Args...>& __args, - _Index_tuple<_Indexes...>) volatile - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - // Call as const volatile - template - _Result - __call(const tuple<_Args...>& __args, - _Index_tuple<_Indexes...>) const volatile - { - return _M_f(_Mu<_Bound_args>() - (_GLIBCXX_TR1::get<_Indexes>(_M_bound_args), __args)...); - } - - public: - typedef _Result result_type; - - explicit - _Bind_result(_Functor __f, _Bound_args... __bound_args) - : _M_f(__f), _M_bound_args(__bound_args...) { } - - // Call unqualified - template - result_type - operator()(_Args&... __args) - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - - // Call as const - template - result_type - operator()(_Args&... __args) const - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - - // Call as volatile - template - result_type - operator()(_Args&... __args) volatile - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - - // Call as const volatile - template - result_type - operator()(_Args&... __args) const volatile - { - return this->__call(_GLIBCXX_TR1::tie(__args...), _Bound_indexes()); - } - }; - - /** - * @if maint - * Class template _Bind is always a bind expression. - * @endif - */ - template - struct is_bind_expression<_Bind<_Signature> > - { static const bool value = true; }; - - template - const bool is_bind_expression<_Bind<_Signature> >::value; - - /** - * @if maint - * Class template _Bind_result is always a bind expression. - * @endif - */ - template - struct is_bind_expression<_Bind_result<_Result, _Signature> > - { static const bool value = true; }; - - template - const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value; - - template - inline - _Bind::type(_ArgTypes...)> - bind(_Functor __f, _ArgTypes... __args) - { - typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type; - typedef typename __maybe_type::type __functor_type; - typedef _Bind<__functor_type(_ArgTypes...)> __result_type; - return __result_type(__maybe_type::__do_wrap(__f), __args...); - } - - template - inline - _Bind_result<_Result, - typename _Maybe_wrap_member_pointer<_Functor>::type - (_ArgTypes...)> - bind(_Functor __f, _ArgTypes... __args) - { - typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type; - typedef typename __maybe_type::type __functor_type; - typedef _Bind_result<_Result, __functor_type(_ArgTypes...)> - __result_type; - return __result_type(__maybe_type::__do_wrap(__f), __args...); - } - - /** - * @brief Exception class thrown when class template function's - * operator() is called with an empty target. - * - */ - class bad_function_call : public std::exception { }; - - /** - * @if maint - * The integral constant expression 0 can be converted into a - * pointer to this type. It is used by the function template to - * accept NULL pointers. - * @endif - */ - struct _M_clear_type; - - /** - * @if maint - * Trait identifying "location-invariant" types, meaning that the - * address of the object (or any of its members) will not escape. - * Also implies a trivial copy constructor and assignment operator. - * @endif - */ - template - struct __is_location_invariant - : integral_constant::value - || is_member_pointer<_Tp>::value)> - { - }; - - class _Undefined_class; - - union _Nocopy_types - { - void* _M_object; - const void* _M_const_object; - void (*_M_function_pointer)(); - void (_Undefined_class::*_M_member_pointer)(); - }; - - union _Any_data - { - void* _M_access() { return &_M_pod_data[0]; } - const void* _M_access() const { return &_M_pod_data[0]; } - - template - _Tp& - _M_access() - { return *static_cast<_Tp*>(_M_access()); } - - template - const _Tp& - _M_access() const - { return *static_cast(_M_access()); } - - _Nocopy_types _M_unused; - char _M_pod_data[sizeof(_Nocopy_types)]; - }; - - enum _Manager_operation - { - __get_type_info, - __get_functor_ptr, - __clone_functor, - __destroy_functor - }; - - /* Simple type wrapper that helps avoid annoying const problems - when casting between void pointers and pointers-to-pointers. */ - template - struct _Simple_type_wrapper - { - _Simple_type_wrapper(_Tp __value) : __value(__value) { } - - _Tp __value; - }; - - template - struct __is_location_invariant<_Simple_type_wrapper<_Tp> > - : __is_location_invariant<_Tp> - { - }; - - // Converts a reference to a function object into a callable - // function object. - template - inline _Functor& - __callable_functor(_Functor& __f) - { return __f; } - - template - inline _Mem_fn<_Member _Class::*> - __callable_functor(_Member _Class::* &__p) - { return mem_fn(__p); } - - template - inline _Mem_fn<_Member _Class::*> - __callable_functor(_Member _Class::* const &__p) - { return mem_fn(__p); } - - template - class function; - - /** - * @if maint - * Base class of all polymorphic function object wrappers. - * @endif - */ - class _Function_base - { - public: - static const std::size_t _M_max_size = sizeof(_Nocopy_types); - static const std::size_t _M_max_align = __alignof__(_Nocopy_types); - - template - class _Base_manager - { - protected: - static const bool __stored_locally = - (__is_location_invariant<_Functor>::value - && sizeof(_Functor) <= _M_max_size - && __alignof__(_Functor) <= _M_max_align - && (_M_max_align % __alignof__(_Functor) == 0)); - - typedef integral_constant _Local_storage; - - // Retrieve a pointer to the function object - static _Functor* - _M_get_pointer(const _Any_data& __source) - { - const _Functor* __ptr = - __stored_locally? &__source._M_access<_Functor>() - /* have stored a pointer */ : __source._M_access<_Functor*>(); - return const_cast<_Functor*>(__ptr); - } - - // Clone a location-invariant function object that fits within - // an _Any_data structure. - static void - _M_clone(_Any_data& __dest, const _Any_data& __source, true_type) - { - new (__dest._M_access()) _Functor(__source._M_access<_Functor>()); - } - - // Clone a function object that is not location-invariant or - // that cannot fit into an _Any_data structure. - static void - _M_clone(_Any_data& __dest, const _Any_data& __source, false_type) - { - __dest._M_access<_Functor*>() = - new _Functor(*__source._M_access<_Functor*>()); - } - - // Destroying a location-invariant object may still require - // destruction. - static void - _M_destroy(_Any_data& __victim, true_type) - { - __victim._M_access<_Functor>().~_Functor(); - } - - // Destroying an object located on the heap. - static void - _M_destroy(_Any_data& __victim, false_type) - { - delete __victim._M_access<_Functor*>(); - } - - public: - static bool - _M_manager(_Any_data& __dest, const _Any_data& __source, - _Manager_operation __op) - { - switch (__op) - { - case __get_type_info: - __dest._M_access() = &typeid(_Functor); - break; - - case __get_functor_ptr: - __dest._M_access<_Functor*>() = _M_get_pointer(__source); - break; - - case __clone_functor: - _M_clone(__dest, __source, _Local_storage()); - break; - - case __destroy_functor: - _M_destroy(__dest, _Local_storage()); - break; - } - return false; - } - - static void - _M_init_functor(_Any_data& __functor, const _Functor& __f) - { - _M_init_functor(__functor, __f, _Local_storage()); - } - - template - static bool - _M_not_empty_function(const function<_Signature>& __f) - { - return __f; - } - - template - static bool - _M_not_empty_function(const _Tp*& __fp) - { - return __fp; - } - - template - static bool - _M_not_empty_function(_Tp _Class::* const& __mp) - { - return __mp; - } - - template - static bool - _M_not_empty_function(const _Tp&) - { - return true; - } - - private: - static void - _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type) - { - new (__functor._M_access()) _Functor(__f); - } - - static void - _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type) - { - __functor._M_access<_Functor*>() = new _Functor(__f); - } - }; - - template - class _Ref_manager : public _Base_manager<_Functor*> - { - typedef _Function_base::_Base_manager<_Functor*> _Base; - - public: - static bool - _M_manager(_Any_data& __dest, const _Any_data& __source, - _Manager_operation __op) - { - switch (__op) - { - case __get_type_info: - __dest._M_access() = &typeid(_Functor); - break; - - case __get_functor_ptr: - __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source); - return is_const<_Functor>::value; - break; - - default: - _Base::_M_manager(__dest, __source, __op); - } - return false; - } - - static void - _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f) - { - // TBD: Use address_of function instead - _Base::_M_init_functor(__functor, &__f.get()); - } - }; - - _Function_base() : _M_manager(0) { } - - ~_Function_base() - { - if (_M_manager) - _M_manager(_M_functor, _M_functor, __destroy_functor); - } - - - bool _M_empty() const { return !_M_manager; } - - typedef bool (*_Manager_type)(_Any_data&, const _Any_data&, - _Manager_operation); - - _Any_data _M_functor; - _Manager_type _M_manager; - }; - - template - class _Function_handler; - - template - class _Function_handler<_Res(_ArgTypes...), _Functor> - : public _Function_base::_Base_manager<_Functor> - { - typedef _Function_base::_Base_manager<_Functor> _Base; - - public: - static _Res - _M_invoke(const _Any_data& __functor, _ArgTypes... __args) - { - return (*_Base::_M_get_pointer(__functor))(__args...); - } - }; - - template - class _Function_handler - : public _Function_base::_Base_manager<_Functor> - { - typedef _Function_base::_Base_manager<_Functor> _Base; - - public: - static void - _M_invoke(const _Any_data& __functor, _ArgTypes... __args) - { - (*_Base::_M_get_pointer(__functor))(__args...); - } - }; - - template - class _Function_handler<_Res(_ArgTypes...), reference_wrapper<_Functor> > - : public _Function_base::_Ref_manager<_Functor> - { - typedef _Function_base::_Ref_manager<_Functor> _Base; - - public: - static _Res - _M_invoke(const _Any_data& __functor, _ArgTypes... __args) - { - return - __callable_functor(**_Base::_M_get_pointer(__functor))(__args...); - } - }; - - template - class _Function_handler > - : public _Function_base::_Ref_manager<_Functor> - { - typedef _Function_base::_Ref_manager<_Functor> _Base; - - public: - static void - _M_invoke(const _Any_data& __functor, _ArgTypes... __args) - { - __callable_functor(**_Base::_M_get_pointer(__functor))(__args...); - } - }; - - template - class _Function_handler<_Res(_ArgTypes...), _Member _Class::*> - : public _Function_handler - { - typedef _Function_handler - _Base; - - public: - static _Res - _M_invoke(const _Any_data& __functor, _ArgTypes... __args) - { - return _GLIBCXX_TR1:: - mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...); - } - }; - - template - class _Function_handler - : public _Function_base::_Base_manager< - _Simple_type_wrapper< _Member _Class::* > > - { - typedef _Member _Class::* _Functor; - typedef _Simple_type_wrapper<_Functor> _Wrapper; - typedef _Function_base::_Base_manager<_Wrapper> _Base; - - public: - static bool - _M_manager(_Any_data& __dest, const _Any_data& __source, - _Manager_operation __op) - { - switch (__op) - { - case __get_type_info: - __dest._M_access() = &typeid(_Functor); - break; - - case __get_functor_ptr: - __dest._M_access<_Functor*>() = - &_Base::_M_get_pointer(__source)->__value; - break; - - default: - _Base::_M_manager(__dest, __source, __op); - } - return false; - } - - static void - _M_invoke(const _Any_data& __functor, _ArgTypes... __args) - { - _GLIBCXX_TR1:: - mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...); - } - }; - - template - class function<_Res(_ArgTypes...)> - : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>, - private _Function_base - { - /** - * @if maint - * This class is used to implement the safe_bool idiom. - * @endif - */ - struct _Hidden_type - { - _Hidden_type* _M_bool; - }; - - /** - * @if maint - * This typedef is used to implement the safe_bool idiom. - * @endif - */ - typedef _Hidden_type* _Hidden_type::* _Safe_bool; - - typedef _Res _Signature_type(_ArgTypes...); - - struct _Useless {}; - - public: - typedef _Res result_type; - - // [3.7.2.1] construct/copy/destroy - - /** - * @brief Default construct creates an empty function call wrapper. - * @post @c !(bool)*this - */ - function() : _Function_base() { } - - /** - * @brief Default construct creates an empty function call wrapper. - * @post @c !(bool)*this - */ - function(_M_clear_type*) : _Function_base() { } - - /** - * @brief %Function copy constructor. - * @param x A %function object with identical call signature. - * @pre @c (bool)*this == (bool)x - * - * The newly-created %function contains a copy of the target of @a - * x (if it has one). - */ - function(const function& __x); - - /** - * @brief Builds a %function that targets a copy of the incoming - * function object. - * @param f A %function object that is callable with parameters of - * type @c T1, @c T2, ..., @c TN and returns a value convertible - * to @c Res. - * - * The newly-created %function object will target a copy of @a - * f. If @a f is @c reference_wrapper, then this function - * object will contain a reference to the function object @c - * f.get(). If @a f is a NULL function pointer or NULL - * pointer-to-member, the newly-created object will be empty. - * - * If @a f is a non-NULL function pointer or an object of type @c - * reference_wrapper, this function will not throw. - */ - template - function(_Functor __f, - typename __gnu_cxx::__enable_if< - !is_integral<_Functor>::value, _Useless>::__type - = _Useless()); - - /** - * @brief %Function assignment operator. - * @param x A %function with identical call signature. - * @post @c (bool)*this == (bool)x - * @returns @c *this - * - * The target of @a x is copied to @c *this. If @a x has no - * target, then @c *this will be empty. - * - * If @a x targets a function pointer or a reference to a function - * object, then this operation will not throw an exception. - */ - function& - operator=(const function& __x) - { - function(__x).swap(*this); - return *this; - } - - /** - * @brief %Function assignment to zero. - * @post @c !(bool)*this - * @returns @c *this - * - * The target of @a *this is deallocated, leaving it empty. - */ - function& - operator=(_M_clear_type*) - { - if (_M_manager) - { - _M_manager(_M_functor, _M_functor, __destroy_functor); - _M_manager = 0; - _M_invoker = 0; - } - return *this; - } - - /** - * @brief %Function assignment to a new target. - * @param f A %function object that is callable with parameters of - * type @c T1, @c T2, ..., @c TN and returns a value convertible - * to @c Res. - * @return @c *this - * - * This %function object wrapper will target a copy of @a - * f. If @a f is @c reference_wrapper, then this function - * object will contain a reference to the function object @c - * f.get(). If @a f is a NULL function pointer or NULL - * pointer-to-member, @c this object will be empty. - * - * If @a f is a non-NULL function pointer or an object of type @c - * reference_wrapper, this function will not throw. - */ - template - typename __gnu_cxx::__enable_if::value, - function&>::__type - operator=(_Functor __f) - { - function(__f).swap(*this); - return *this; - } - - // [3.7.2.2] function modifiers - - /** - * @brief Swap the targets of two %function objects. - * @param f A %function with identical call signature. - * - * Swap the targets of @c this function object and @a f. This - * function will not throw an exception. - */ - void swap(function& __x) - { - _Any_data __old_functor = _M_functor; - _M_functor = __x._M_functor; - __x._M_functor = __old_functor; - _Manager_type __old_manager = _M_manager; - _M_manager = __x._M_manager; - __x._M_manager = __old_manager; - _Invoker_type __old_invoker = _M_invoker; - _M_invoker = __x._M_invoker; - __x._M_invoker = __old_invoker; - } - - // [3.7.2.3] function capacity - - /** - * @brief Determine if the %function wrapper has a target. - * - * @return @c true when this %function object contains a target, - * or @c false when it is empty. - * - * This function will not throw an exception. - */ - operator _Safe_bool() const - { - if (_M_empty()) - return 0; - else - return &_Hidden_type::_M_bool; - } - - // [3.7.2.4] function invocation - - /** - * @brief Invokes the function targeted by @c *this. - * @returns the result of the target. - * @throws bad_function_call when @c !(bool)*this - * - * The function call operator invokes the target function object - * stored by @c this. - */ - _Res operator()(_ArgTypes... __args) const; - - // [3.7.2.5] function target access - /** - * @brief Determine the type of the target of this function object - * wrapper. - * - * @returns the type identifier of the target function object, or - * @c typeid(void) if @c !(bool)*this. - * - * This function will not throw an exception. - */ - const type_info& target_type() const; - - /** - * @brief Access the stored target function object. - * - * @return Returns a pointer to the stored target function object, - * if @c typeid(Functor).equals(target_type()); otherwise, a NULL - * pointer. - * - * This function will not throw an exception. - */ - template _Functor* target(); - - /** - * @overload - */ - template const _Functor* target() const; - - private: - // [3.7.2.6] undefined operators - template - void operator==(const function<_Function>&) const; - template - void operator!=(const function<_Function>&) const; - - typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...); - _Invoker_type _M_invoker; - }; - - template - function<_Res(_ArgTypes...)>:: - function(const function& __x) - : _Function_base() - { - if (__x) - { - _M_invoker = __x._M_invoker; - _M_manager = __x._M_manager; - __x._M_manager(_M_functor, __x._M_functor, __clone_functor); - } - } - - template - template - function<_Res(_ArgTypes...)>:: - function(_Functor __f, - typename __gnu_cxx::__enable_if< - !is_integral<_Functor>::value, _Useless>::__type) - : _Function_base() - { - typedef _Function_handler<_Signature_type, _Functor> _My_handler; - - if (_My_handler::_M_not_empty_function(__f)) - { - _M_invoker = &_My_handler::_M_invoke; - _M_manager = &_My_handler::_M_manager; - _My_handler::_M_init_functor(_M_functor, __f); - } - } +#include - template - _Res - function<_Res(_ArgTypes...)>:: - operator()(_ArgTypes... __args) const - { - if (_M_empty()) - { -#if __EXCEPTIONS - throw bad_function_call(); +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include #else - __builtin_abort(); +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif - } - return _M_invoker(_M_functor, __args...); - } - - template - const type_info& - function<_Res(_ArgTypes...)>:: - target_type() const - { - if (_M_manager) - { - _Any_data __typeinfo_result; - _M_manager(__typeinfo_result, _M_functor, __get_type_info); - return *__typeinfo_result._M_access(); - } - else - return typeid(void); - } - - template - template - _Functor* - function<_Res(_ArgTypes...)>:: - target() - { - if (typeid(_Functor) == target_type() && _M_manager) - { - _Any_data __ptr; - if (_M_manager(__ptr, _M_functor, __get_functor_ptr) - && !is_const<_Functor>::value) - return 0; - else - return __ptr._M_access<_Functor*>(); - } - else - return 0; - } - - template - template - const _Functor* - function<_Res(_ArgTypes...)>:: - target() const - { - if (typeid(_Functor) == target_type() && _M_manager) - { - _Any_data __ptr; - _M_manager(__ptr, _M_functor, __get_functor_ptr); - return __ptr._M_access(); - } - else - return 0; - } - - // [3.7.2.7] null pointer comparisons - - /** - * @brief Compares a polymorphic function object wrapper against 0 - * (the NULL pointer). - * @returns @c true if the wrapper has no target, @c false otherwise - * - * This function will not throw an exception. - */ - template - inline bool - operator==(const function<_Signature>& __f, _M_clear_type*) - { - return !__f; - } - - /** - * @overload - */ - template - inline bool - operator==(_M_clear_type*, const function<_Signature>& __f) - { - return !__f; - } - /** - * @brief Compares a polymorphic function object wrapper against 0 - * (the NULL pointer). - * @returns @c false if the wrapper has no target, @c true otherwise - * - * This function will not throw an exception. - */ - template - inline bool - operator!=(const function<_Signature>& __f, _M_clear_type*) - { - return __f; - } - - /** - * @overload - */ - template - inline bool - operator!=(_M_clear_type*, const function<_Signature>& __f) - { - return __f; - } - - // [3.7.2.8] specialized algorithms - - /** - * @brief Swap the targets of two polymorphic function object wrappers. - * - * This function will not throw an exception. - */ - template - inline void - swap(function<_Signature>& __x, function<_Signature>& __y) - { - __x.swap(__y); - } - -_GLIBCXX_END_NAMESPACE -} - -#include - -#endif +#endif // _GLIBCXX_TR1_FUNCTIONAL diff --git a/libstdc++-v3/include/tr1/functional_hash.h b/libstdc++-v3/include/tr1/functional_hash.h index f692308..a41b232 100644 --- a/libstdc++-v3/include/tr1/functional_hash.h +++ b/libstdc++-v3/include/tr1/functional_hash.h @@ -1,4 +1,4 @@ -// TR1 functional -*- C++ -*- +// TR1 functional_hash.h header -*- C++ -*- // Copyright (C) 2007 Free Software Foundation, Inc. // @@ -32,200 +32,27 @@ * You should not attempt to use it directly. */ -#ifndef _TR1_FUNCTIONAL_HASH_H -#define _TR1_FUNCTIONAL_HASH_H 1 +#ifndef _GLIBCXX_TR1_FUNCTIONAL_HASH_H +#define _GLIBCXX_TR1_FUNCTIONAL_HASH_H 1 -#include -#include // for std::frexp +#pragma GCC system_header -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // Definition of default hash function std::tr1::hash<>. The types for - // which std::tr1::hash is defined is in clause 6.3.3. of the PDTR. - template - struct hash; - -#define _TR1_hashtable_define_trivial_hash(_Tp) \ - template<> \ - struct hash<_Tp> \ - : public std::unary_function<_Tp, std::size_t> \ - { \ - std::size_t \ - operator()(_Tp __val) const \ - { return static_cast(__val); } \ - } - - _TR1_hashtable_define_trivial_hash(bool); - _TR1_hashtable_define_trivial_hash(char); - _TR1_hashtable_define_trivial_hash(signed char); - _TR1_hashtable_define_trivial_hash(unsigned char); - _TR1_hashtable_define_trivial_hash(wchar_t); - _TR1_hashtable_define_trivial_hash(short); - _TR1_hashtable_define_trivial_hash(int); - _TR1_hashtable_define_trivial_hash(long); - _TR1_hashtable_define_trivial_hash(long long); - _TR1_hashtable_define_trivial_hash(unsigned short); - _TR1_hashtable_define_trivial_hash(unsigned int); - _TR1_hashtable_define_trivial_hash(unsigned long); - _TR1_hashtable_define_trivial_hash(unsigned long long); - -#undef _TR1_hashtable_define_trivial_hash - - template - struct hash<_Tp*> - : public std::unary_function<_Tp*, std::size_t> - { - std::size_t - operator()(_Tp* __p) const - { return reinterpret_cast(__p); } - }; - - // Fowler / Noll / Vo (FNV) Hash (type FNV-1a) - // (used by the next specializations of std::tr1::hash<>) - - // Dummy generic implementation (for sizeof(size_t) != 4, 8). - template - struct _Fnv_hash - { - static std::size_t - hash(const char* __first, std::size_t __length) - { - std::size_t __result = 0; - for (; __length > 0; --__length) - __result = (__result * 131) + *__first++; - return __result; - } - }; - - template<> - struct _Fnv_hash<4> - { - static std::size_t - hash(const char* __first, std::size_t __length) - { - std::size_t __result = static_cast(2166136261UL); - for (; __length > 0; --__length) - { - __result ^= static_cast(*__first++); - __result *= static_cast(16777619UL); - } - return __result; - } - }; - - template<> - struct _Fnv_hash<8> - { - static std::size_t - hash(const char* __first, std::size_t __length) - { - std::size_t __result = - static_cast(14695981039346656037ULL); - for (; __length > 0; --__length) - { - __result ^= static_cast(*__first++); - __result *= static_cast(1099511628211ULL); - } - return __result; - } - }; - - // XXX String and floating point hashes probably shouldn't be inline - // member functions, since are nontrivial. Once we have the framework - // for TR1 .cc files, these should go in one. - template<> - struct hash - : public std::unary_function - { - std::size_t - operator()(const std::string& __s) const - { return _Fnv_hash<>::hash(__s.data(), __s.length()); } - }; - -#ifdef _GLIBCXX_USE_WCHAR_T - template<> - struct hash - : public std::unary_function - { - std::size_t - operator()(const std::wstring& __s) const - { - return _Fnv_hash<>::hash(reinterpret_cast(__s.data()), - __s.length() * sizeof(wchar_t)); - } - }; +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header #endif - template<> - struct hash - : public std::unary_function - { - std::size_t - operator()(float __fval) const - { - std::size_t __result = 0; - - // 0 and -0 both hash to zero. - if (__fval != 0.0f) - __result = _Fnv_hash<>::hash(reinterpret_cast(&__fval), - sizeof(__fval)); - return __result; - } - }; - - template<> - struct hash - : public std::unary_function - { - std::size_t - operator()(double __dval) const - { - std::size_t __result = 0; - - // 0 and -0 both hash to zero. - if (__dval != 0.0) - __result = _Fnv_hash<>::hash(reinterpret_cast(&__dval), - sizeof(__dval)); - return __result; - } - }; - - // For long double, careful with random padding bits (e.g., on x86, - // 10 bytes -> 12 bytes) and resort to frexp. - template<> - struct hash - : public std::unary_function - { - std::size_t - operator()(long double __ldval) const - { - std::size_t __result = 0; - - int __exponent; - __ldval = std::frexp(__ldval, &__exponent); - __ldval = __ldval < 0.0l ? -(__ldval + 0.5l) : __ldval; - - const long double __mult = - __gnu_cxx::__numeric_traits::__max + 1.0l; - __ldval *= __mult; - - // Try to use all the bits of the mantissa (really necessary only - // on 32-bit targets, at least for 80-bit floating point formats). - const std::size_t __hibits = (std::size_t)__ldval; - __ldval = (__ldval - (long double)__hibits) * __mult; - - const std::size_t __coeff = - __gnu_cxx::__numeric_traits::__max / __LDBL_MAX_EXP__; - - __result = __hibits + (std::size_t)__ldval + __coeff * __exponent; - - return __result; - } - }; - -_GLIBCXX_END_NAMESPACE -} - +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif + +#endif // _GLIBCXX_TR1_FUNCTIONAL_HASH_H diff --git a/libstdc++-v3/include/tr1/gamma.tcc b/libstdc++-v3/include/tr1/gamma.tcc index 407bafc..06702e3 100644 --- a/libstdc++-v3/include/tr1/gamma.tcc +++ b/libstdc++-v3/include/tr1/gamma.tcc @@ -56,7 +56,8 @@ namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ /** * @ingroup tr1_math_spec_func @@ -295,9 +296,9 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) = std::numeric_limits<_Tp>::max_exponent10 * std::log(_Tp(10)) - _Tp(1); #if _GLIBCXX_USE_C99_MATH_TR1 - _Tp __coeff = std::_GLIBCXX_TR1::lgamma(_Tp(1 + __n)) - - std::_GLIBCXX_TR1::lgamma(_Tp(1 + __k)) - - std::_GLIBCXX_TR1::lgamma(_Tp(1 + __n - __k)); + _Tp __coeff = std::tr1::lgamma(_Tp(1 + __n)) + - std::tr1::lgamma(_Tp(1 + __k)) + - std::tr1::lgamma(_Tp(1 + __n - __k)); #else _Tp __coeff = __log_gamma(_Tp(1 + __n)) - __log_gamma(_Tp(1 + __k)) @@ -464,7 +465,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { const _Tp __hzeta = __hurwitz_zeta(_Tp(__n + 1), __x); #if _GLIBCXX_USE_C99_MATH_TR1 - const _Tp __ln_nfact = std::_GLIBCXX_TR1::lgamma(_Tp(__n + 1)); + const _Tp __ln_nfact = std::tr1::lgamma(_Tp(__n + 1)); #else const _Tp __ln_nfact = __log_gamma(_Tp(__n + 1)); #endif @@ -479,7 +480,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } #endif // _TR1_GAMMA_TCC diff --git a/libstdc++-v3/include/tr1/hashtable b/libstdc++-v3/include/tr1/hashtable deleted file mode 100644 index 526ebf8..0000000 --- a/libstdc++-v3/include/tr1/hashtable +++ /dev/null @@ -1,1203 +0,0 @@ -// Internal header for TR1 unordered_set and unordered_map -*- C++ -*- - -// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/** @file tr1/hashtable - * This is a TR1 C++ Library header. - */ - -// This header file defines std::tr1::hashtable, which is used to -// implement std::tr1::unordered_set, std::tr1::unordered_map, -// std::tr1::unordered_multiset, and std::tr1::unordered_multimap. -// hashtable has many template parameters, partly to accommodate -// the differences between those four classes and partly to -// accommodate policy choices that go beyond what TR1 calls for. - -// Class template hashtable attempts to encapsulate all reasonable -// variation among hash tables that use chaining. It does not handle -// open addressing. - -// References: -// M. Austern, "A Proposal to Add Hash Tables to the Standard -// Library (revision 4)," WG21 Document N1456=03-0039, 2003. -// D. E. Knuth, The Art of Computer Programming, v. 3, Sorting and Searching. -// A. Tavori and V. Dreizin, "Policy-Based Data Structures", 2004. -// http://gcc.gnu.org/onlinedocs/libstdc++/ext/pb_ds/index.html - -#ifndef _TR1_HASHTABLE -#define _TR1_HASHTABLE 1 - -#include // For std::pair -#include -#include -#include -#include -#include -#include -#include // For true_type and false_type -#include - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // Class template _Hashtable, class definition. - - // Meaning of class template _Hashtable's template parameters - - // _Key and _Value: arbitrary CopyConstructible types. - - // _Allocator: an allocator type ([lib.allocator.requirements]) whose - // value type is Value. As a conforming extension, we allow for - // value type != Value. - - // _ExtractKey: function object that takes a object of type Value - // and returns a value of type _Key. - - // _Equal: function object that takes two objects of type k and returns - // a bool-like value that is true if the two objects are considered equal. - - // _H1: the hash function. A unary function object with argument type - // Key and result type size_t. Return values should be distributed - // over the entire range [0, numeric_limits:::max()]. - - // _H2: the range-hashing function (in the terminology of Tavori and - // Dreizin). A binary function object whose argument types and result - // type are all size_t. Given arguments r and N, the return value is - // in the range [0, N). - - // _Hash: the ranged hash function (Tavori and Dreizin). A binary function - // whose argument types are _Key and size_t and whose result type is - // size_t. Given arguments k and N, the return value is in the range - // [0, N). Default: hash(k, N) = h2(h1(k), N). If _Hash is anything other - // than the default, _H1 and _H2 are ignored. - - // _RehashPolicy: Policy class with three members, all of which govern - // the bucket count. _M_next_bkt(n) returns a bucket count no smaller - // than n. _M_bkt_for_elements(n) returns a bucket count appropriate - // for an element count of n. _M_need_rehash(n_bkt, n_elt, n_ins) - // determines whether, if the current bucket count is n_bkt and the - // current element count is n_elt, we need to increase the bucket - // count. If so, returns make_pair(true, n), where n is the new - // bucket count. If not, returns make_pair(false, ). - - // ??? Right now it is hard-wired that the number of buckets never - // shrinks. Should we allow _RehashPolicy to change that? - - // __cache_hash_code: bool. true if we store the value of the hash - // function along with the value. This is a time-space tradeoff. - // Storing it may improve lookup speed by reducing the number of times - // we need to call the Equal function. - - // __constant_iterators: bool. true if iterator and const_iterator are - // both constant iterator types. This is true for unordered_set and - // unordered_multiset, false for unordered_map and unordered_multimap. - - // __unique_keys: bool. true if the return value of _Hashtable::count(k) - // is always at most one, false if it may be an arbitrary number. This - // true for unordered_set and unordered_map, false for unordered_multiset - // and unordered_multimap. - - template - class _Hashtable - : public __detail::_Rehash_base<_RehashPolicy, - _Hashtable<_Key, _Value, _Allocator, - _ExtractKey, - _Equal, _H1, _H2, _Hash, - _RehashPolicy, - __cache_hash_code, - __constant_iterators, - __unique_keys> >, - public __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, - _H1, _H2, _Hash, __cache_hash_code>, - public __detail::_Map_base<_Key, _Value, _ExtractKey, __unique_keys, - _Hashtable<_Key, _Value, _Allocator, - _ExtractKey, - _Equal, _H1, _H2, _Hash, - _RehashPolicy, - __cache_hash_code, - __constant_iterators, - __unique_keys> > - { - public: - typedef _Allocator allocator_type; - typedef _Value value_type; - typedef _Key key_type; - typedef _Equal key_equal; - // mapped_type, if present, comes from _Map_base. - // hasher, if present, comes from _Hash_code_base. - typedef typename _Allocator::difference_type difference_type; - typedef typename _Allocator::size_type size_type; - typedef typename _Allocator::reference reference; - typedef typename _Allocator::const_reference const_reference; - - typedef __detail::_Node_iterator - local_iterator; - typedef __detail::_Node_const_iterator - const_local_iterator; - - typedef __detail::_Hashtable_iterator - iterator; - typedef __detail::_Hashtable_const_iterator - const_iterator; - - template - friend struct __detail::_Map_base; - - private: - typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node; - typedef typename _Allocator::template rebind<_Node>::other - _Node_allocator_type; - typedef typename _Allocator::template rebind<_Node*>::other - _Bucket_allocator_type; - - typedef typename _Allocator::template rebind<_Value>::other - _Value_allocator_type; - - _Node_allocator_type _M_node_allocator; - _Node** _M_buckets; - size_type _M_bucket_count; - size_type _M_element_count; - _RehashPolicy _M_rehash_policy; - - _Node* - _M_allocate_node(const value_type& __v); - - void - _M_deallocate_node(_Node* __n); - - void - _M_deallocate_nodes(_Node**, size_type); - - _Node** - _M_allocate_buckets(size_type __n); - - void - _M_deallocate_buckets(_Node**, size_type __n); - - public: - // Constructor, destructor, assignment, swap - _Hashtable(size_type __bucket_hint, - const _H1&, const _H2&, const _Hash&, - const _Equal&, const _ExtractKey&, - const allocator_type&); - - template - _Hashtable(_InputIterator __first, _InputIterator __last, - size_type __bucket_hint, - const _H1&, const _H2&, const _Hash&, - const _Equal&, const _ExtractKey&, - const allocator_type&); - - _Hashtable(const _Hashtable&); - - _Hashtable& - operator=(const _Hashtable&); - - ~_Hashtable(); - - void swap(_Hashtable&); - - // Basic container operations - iterator - begin() - { - iterator __i(_M_buckets); - if (!__i._M_cur_node) - __i._M_incr_bucket(); - return __i; - } - - const_iterator - begin() const - { - const_iterator __i(_M_buckets); - if (!__i._M_cur_node) - __i._M_incr_bucket(); - return __i; - } - - iterator - end() - { return iterator(_M_buckets + _M_bucket_count); } - - const_iterator - end() const - { return const_iterator(_M_buckets + _M_bucket_count); } - - size_type - size() const - { return _M_element_count; } - - bool - empty() const - { return size() == 0; } - - allocator_type - get_allocator() const - { return allocator_type(_M_node_allocator); } - - _Value_allocator_type - _M_get_Value_allocator() const - { return _Value_allocator_type(_M_node_allocator); } - - size_type - max_size() const - { return _M_get_Value_allocator().max_size(); } - - // Observers - key_equal - key_eq() const - { return this->_M_eq; } - - // hash_function, if present, comes from _Hash_code_base. - - // Bucket operations - size_type - bucket_count() const - { return _M_bucket_count; } - - size_type - max_bucket_count() const - { return max_size(); } - - size_type - bucket_size(size_type __n) const - { return std::distance(begin(__n), end(__n)); } - - size_type - bucket(const key_type& __k) const - { - return this->_M_bucket_index(__k, this->_M_hash_code(__k), - bucket_count()); - } - - local_iterator - begin(size_type __n) - { return local_iterator(_M_buckets[__n]); } - - local_iterator - end(size_type) - { return local_iterator(0); } - - const_local_iterator - begin(size_type __n) const - { return const_local_iterator(_M_buckets[__n]); } - - const_local_iterator - end(size_type) const - { return const_local_iterator(0); } - - float - load_factor() const - { - return static_cast(size()) / static_cast(bucket_count()); - } - - // max_load_factor, if present, comes from _Rehash_base. - - // Generalization of max_load_factor. Extension, not found in TR1. Only - // useful if _RehashPolicy is something other than the default. - const _RehashPolicy& - __rehash_policy() const - { return _M_rehash_policy; } - - void - __rehash_policy(const _RehashPolicy&); - - // Lookup. - iterator - find(const key_type& __k); - - const_iterator - find(const key_type& __k) const; - - size_type - count(const key_type& __k) const; - - std::pair - equal_range(const key_type& __k); - - std::pair - equal_range(const key_type& __k) const; - - private: // Find, insert and erase helper functions - // ??? This dispatching is a workaround for the fact that we don't - // have partial specialization of member templates; it would be - // better to just specialize insert on __unique_keys. There may be a - // cleaner workaround. - typedef typename __gnu_cxx::__conditional_type<__unique_keys, - std::pair, iterator>::__type - _Insert_Return_Type; - - typedef typename __gnu_cxx::__conditional_type<__unique_keys, - std::_Select1st<_Insert_Return_Type>, - std::_Identity<_Insert_Return_Type> - >::__type - _Insert_Conv_Type; - - _Node* - _M_find_node(_Node*, const key_type&, - typename _Hashtable::_Hash_code_type) const; - - iterator - _M_insert_bucket(const value_type&, size_type, - typename _Hashtable::_Hash_code_type); - - std::pair - _M_insert(const value_type&, std::_GLIBCXX_TR1::true_type); - - iterator - _M_insert(const value_type&, std::_GLIBCXX_TR1::false_type); - - void - _M_erase_node(_Node*, _Node**); - - public: - // Insert and erase - _Insert_Return_Type - insert(const value_type& __v) - { return _M_insert(__v, std::_GLIBCXX_TR1::integral_constant()); } - - iterator - insert(iterator, const value_type& __v) - { return iterator(_Insert_Conv_Type()(this->insert(__v))); } - - const_iterator - insert(const_iterator, const value_type& __v) - { return const_iterator(_Insert_Conv_Type()(this->insert(__v))); } - - template - void - insert(_InputIterator __first, _InputIterator __last); - - iterator - erase(iterator); - - const_iterator - erase(const_iterator); - - size_type - erase(const key_type&); - - iterator - erase(iterator, iterator); - - const_iterator - erase(const_iterator, const_iterator); - - void - clear(); - - // Set number of buckets to be appropriate for container of n element. - void rehash(size_type __n); - - private: - // Unconditionally change size of bucket array to n. - void _M_rehash(size_type __n); - }; - - - // Definitions of class template _Hashtable's out-of-line member functions. - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::_Node* - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_allocate_node(const value_type& __v) - { - _Node* __n = _M_node_allocator.allocate(1); - try - { - _M_get_Value_allocator().construct(&__n->_M_v, __v); - __n->_M_next = 0; - return __n; - } - catch(...) - { - _M_node_allocator.deallocate(__n, 1); - __throw_exception_again; - } - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_deallocate_node(_Node* __n) - { - _M_get_Value_allocator().destroy(&__n->_M_v); - _M_node_allocator.deallocate(__n, 1); - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_deallocate_nodes(_Node** __array, size_type __n) - { - for (size_type __i = 0; __i < __n; ++__i) - { - _Node* __p = __array[__i]; - while (__p) - { - _Node* __tmp = __p; - __p = __p->_M_next; - _M_deallocate_node(__tmp); - } - __array[__i] = 0; - } - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::_Node** - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_allocate_buckets(size_type __n) - { - _Bucket_allocator_type __alloc(_M_node_allocator); - - // We allocate one extra bucket to hold a sentinel, an arbitrary - // non-null pointer. Iterator increment relies on this. - _Node** __p = __alloc.allocate(__n + 1); - std::fill(__p, __p + __n, (_Node*) 0); - __p[__n] = reinterpret_cast<_Node*>(0x1000); - return __p; - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_deallocate_buckets(_Node** __p, size_type __n) - { - _Bucket_allocator_type __alloc(_M_node_allocator); - __alloc.deallocate(__p, __n + 1); - } - - template - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _Hashtable(size_type __bucket_hint, - const _H1& __h1, const _H2& __h2, const _Hash& __h, - const _Equal& __eq, const _ExtractKey& __exk, - const allocator_type& __a) - : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(), - __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, - _H1, _H2, _Hash, __chc>(__exk, __eq, - __h1, __h2, __h), - __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(), - _M_node_allocator(__a), - _M_bucket_count(0), - _M_element_count(0), - _M_rehash_policy() - { - _M_bucket_count = _M_rehash_policy._M_next_bkt(__bucket_hint); - _M_buckets = _M_allocate_buckets(_M_bucket_count); - } - - template - template - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _Hashtable(_InputIterator __f, _InputIterator __l, - size_type __bucket_hint, - const _H1& __h1, const _H2& __h2, const _Hash& __h, - const _Equal& __eq, const _ExtractKey& __exk, - const allocator_type& __a) - : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(), - __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, - _H1, _H2, _Hash, __chc>(__exk, __eq, - __h1, __h2, __h), - __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(), - _M_node_allocator(__a), - _M_bucket_count(0), - _M_element_count(0), - _M_rehash_policy() - { - _M_bucket_count = std::max(_M_rehash_policy._M_next_bkt(__bucket_hint), - _M_rehash_policy. - _M_bkt_for_elements(__detail:: - __distance_fw(__f, - __l))); - _M_buckets = _M_allocate_buckets(_M_bucket_count); - try - { - for (; __f != __l; ++__f) - this->insert(*__f); - } - catch(...) - { - clear(); - _M_deallocate_buckets(_M_buckets, _M_bucket_count); - __throw_exception_again; - } - } - - template - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _Hashtable(const _Hashtable& __ht) - : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(__ht), - __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, - _H1, _H2, _Hash, __chc>(__ht), - __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(__ht), - _M_node_allocator(__ht._M_node_allocator), - _M_bucket_count(__ht._M_bucket_count), - _M_element_count(__ht._M_element_count), - _M_rehash_policy(__ht._M_rehash_policy) - { - _M_buckets = _M_allocate_buckets(_M_bucket_count); - try - { - for (size_type __i = 0; __i < __ht._M_bucket_count; ++__i) - { - _Node* __n = __ht._M_buckets[__i]; - _Node** __tail = _M_buckets + __i; - while (__n) - { - *__tail = _M_allocate_node(__n->_M_v); - this->_M_copy_code(*__tail, __n); - __tail = &((*__tail)->_M_next); - __n = __n->_M_next; - } - } - } - catch(...) - { - clear(); - _M_deallocate_buckets(_M_buckets, _M_bucket_count); - __throw_exception_again; - } - } - - template - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>& - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - operator=(const _Hashtable& __ht) - { - _Hashtable __tmp(__ht); - this->swap(__tmp); - return *this; - } - - template - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - ~_Hashtable() - { - clear(); - _M_deallocate_buckets(_M_buckets, _M_bucket_count); - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - swap(_Hashtable& __x) - { - // The only base class with member variables is hash_code_base. We - // define _Hash_code_base::_M_swap because different specializations - // have different members. - __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, - _H1, _H2, _Hash, __chc>::_M_swap(__x); - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 431. Swapping containers with unequal allocators. - std::__alloc_swap<_Node_allocator_type>::_S_do_it(_M_node_allocator, - __x._M_node_allocator); - - std::swap(_M_rehash_policy, __x._M_rehash_policy); - std::swap(_M_buckets, __x._M_buckets); - std::swap(_M_bucket_count, __x._M_bucket_count); - std::swap(_M_element_count, __x._M_element_count); - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - __rehash_policy(const _RehashPolicy& __pol) - { - _M_rehash_policy = __pol; - size_type __n_bkt = __pol._M_bkt_for_elements(_M_element_count); - if (__n_bkt > _M_bucket_count) - _M_rehash(__n_bkt); - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - find(const key_type& __k) - { - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - _Node* __p = _M_find_node(_M_buckets[__n], __k, __code); - return __p ? iterator(__p, _M_buckets + __n) : this->end(); - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::const_iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - find(const key_type& __k) const - { - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - _Node* __p = _M_find_node(_M_buckets[__n], __k, __code); - return __p ? const_iterator(__p, _M_buckets + __n) : this->end(); - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::size_type - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - count(const key_type& __k) const - { - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - std::size_t __result = 0; - for (_Node* __p = _M_buckets[__n]; __p; __p = __p->_M_next) - if (this->_M_compare(__k, __code, __p)) - ++__result; - return __result; - } - - template - std::pair::iterator, - typename _Hashtable<_Key, _Value, _Allocator, - _ExtractKey, _Equal, _H1, - _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::iterator> - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - equal_range(const key_type& __k) - { - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - _Node** __head = _M_buckets + __n; - _Node* __p = _M_find_node(*__head, __k, __code); - - if (__p) - { - _Node* __p1 = __p->_M_next; - for (; __p1; __p1 = __p1->_M_next) - if (!this->_M_compare(__k, __code, __p1)) - break; - - iterator __first(__p, __head); - iterator __last(__p1, __head); - if (!__p1) - __last._M_incr_bucket(); - return std::make_pair(__first, __last); - } - else - return std::make_pair(this->end(), this->end()); - } - - template - std::pair::const_iterator, - typename _Hashtable<_Key, _Value, _Allocator, - _ExtractKey, _Equal, _H1, - _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::const_iterator> - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - equal_range(const key_type& __k) const - { - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - _Node** __head = _M_buckets + __n; - _Node* __p = _M_find_node(*__head, __k, __code); - - if (__p) - { - _Node* __p1 = __p->_M_next; - for (; __p1; __p1 = __p1->_M_next) - if (!this->_M_compare(__k, __code, __p1)) - break; - - const_iterator __first(__p, __head); - const_iterator __last(__p1, __head); - if (!__p1) - __last._M_incr_bucket(); - return std::make_pair(__first, __last); - } - else - return std::make_pair(this->end(), this->end()); - } - - // Find the node whose key compares equal to k, beginning the search - // at p (usually the head of a bucket). Return nil if no node is found. - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, - _Equal, _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::_Node* - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_find_node(_Node* __p, const key_type& __k, - typename _Hashtable::_Hash_code_type __code) const - { - for (; __p; __p = __p->_M_next) - if (this->_M_compare(__k, __code, __p)) - return __p; - return false; - } - - // Insert v in bucket n (assumes no element with its key already present). - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert_bucket(const value_type& __v, size_type __n, - typename _Hashtable::_Hash_code_type __code) - { - std::pair __do_rehash - = _M_rehash_policy._M_need_rehash(_M_bucket_count, - _M_element_count, 1); - - // Allocate the new node before doing the rehash so that we don't - // do a rehash if the allocation throws. - _Node* __new_node = _M_allocate_node(__v); - - try - { - if (__do_rehash.first) - { - const key_type& __k = this->_M_extract(__v); - __n = this->_M_bucket_index(__k, __code, __do_rehash.second); - _M_rehash(__do_rehash.second); - } - - __new_node->_M_next = _M_buckets[__n]; - this->_M_store_code(__new_node, __code); - _M_buckets[__n] = __new_node; - ++_M_element_count; - return iterator(__new_node, _M_buckets + __n); - } - catch(...) - { - _M_deallocate_node(__new_node); - __throw_exception_again; - } - } - - // Insert v if no element with its key is already present. - template - std::pair::iterator, bool> - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert(const value_type& __v, std::_GLIBCXX_TR1::true_type) - { - const key_type& __k = this->_M_extract(__v); - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - size_type __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - - if (_Node* __p = _M_find_node(_M_buckets[__n], __k, __code)) - return std::make_pair(iterator(__p, _M_buckets + __n), false); - return std::make_pair(_M_insert_bucket(__v, __n, __code), true); - } - - // Insert v unconditionally. - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert(const value_type& __v, std::_GLIBCXX_TR1::false_type) - { - std::pair __do_rehash - = _M_rehash_policy._M_need_rehash(_M_bucket_count, - _M_element_count, 1); - if (__do_rehash.first) - _M_rehash(__do_rehash.second); - - const key_type& __k = this->_M_extract(__v); - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - size_type __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - - // First find the node, avoid leaking new_node if compare throws. - _Node* __prev = _M_find_node(_M_buckets[__n], __k, __code); - _Node* __new_node = _M_allocate_node(__v); - - if (__prev) - { - __new_node->_M_next = __prev->_M_next; - __prev->_M_next = __new_node; - } - else - { - __new_node->_M_next = _M_buckets[__n]; - _M_buckets[__n] = __new_node; - } - this->_M_store_code(__new_node, __code); - - ++_M_element_count; - return iterator(__new_node, _M_buckets + __n); - } - - // For erase(iterator) and erase(const_iterator). - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_erase_node(_Node* __p, _Node** __b) - { - _Node* __cur = *__b; - if (__cur == __p) - *__b = __cur->_M_next; - else - { - _Node* __next = __cur->_M_next; - while (__next != __p) - { - __cur = __next; - __next = __cur->_M_next; - } - __cur->_M_next = __next->_M_next; - } - - _M_deallocate_node(__p); - --_M_element_count; - } - - template - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - insert(_InputIterator __first, _InputIterator __last) - { - size_type __n_elt = __detail::__distance_fw(__first, __last); - std::pair __do_rehash - = _M_rehash_policy._M_need_rehash(_M_bucket_count, - _M_element_count, __n_elt); - if (__do_rehash.first) - _M_rehash(__do_rehash.second); - - for (; __first != __last; ++__first) - this->insert(*__first); - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - erase(iterator __it) - { - iterator __result = __it; - ++__result; - _M_erase_node(__it._M_cur_node, __it._M_cur_bucket); - return __result; - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::const_iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - erase(const_iterator __it) - { - const_iterator __result = __it; - ++__result; - _M_erase_node(__it._M_cur_node, __it._M_cur_bucket); - return __result; - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::size_type - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - erase(const key_type& __k) - { - typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); - std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); - size_type __result = 0; - - _Node** __slot = _M_buckets + __n; - while (*__slot && !this->_M_compare(__k, __code, *__slot)) - __slot = &((*__slot)->_M_next); - - _Node** __saved_slot = 0; - while (*__slot && this->_M_compare(__k, __code, *__slot)) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 526. Is it undefined if a function in the standard changes - // in parameters? - if (&this->_M_extract((*__slot)->_M_v) != &__k) - { - _Node* __p = *__slot; - *__slot = __p->_M_next; - _M_deallocate_node(__p); - --_M_element_count; - ++__result; - } - else - { - __saved_slot = __slot; - __slot = &((*__slot)->_M_next); - } - } - - if (__saved_slot) - { - _Node* __p = *__saved_slot; - *__saved_slot = __p->_M_next; - _M_deallocate_node(__p); - --_M_element_count; - ++__result; - } - - return __result; - } - - // ??? This could be optimized by taking advantage of the bucket - // structure, but it's not clear that it's worth doing. It probably - // wouldn't even be an optimization unless the load factor is large. - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - erase(iterator __first, iterator __last) - { - while (__first != __last) - __first = this->erase(__first); - return __last; - } - - template - typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, - __chc, __cit, __uk>::const_iterator - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - erase(const_iterator __first, const_iterator __last) - { - while (__first != __last) - __first = this->erase(__first); - return __last; - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - clear() - { - _M_deallocate_nodes(_M_buckets, _M_bucket_count); - _M_element_count = 0; - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - rehash(size_type __n) - { - _M_rehash(std::max(_M_rehash_policy._M_next_bkt(__n), - _M_rehash_policy._M_bkt_for_elements(_M_element_count - + 1))); - } - - template - void - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_rehash(size_type __n) - { - _Node** __new_array = _M_allocate_buckets(__n); - try - { - for (size_type __i = 0; __i < _M_bucket_count; ++__i) - while (_Node* __p = _M_buckets[__i]) - { - std::size_t __new_index = this->_M_bucket_index(__p, __n); - _M_buckets[__i] = __p->_M_next; - __p->_M_next = __new_array[__new_index]; - __new_array[__new_index] = __p; - } - _M_deallocate_buckets(_M_buckets, _M_bucket_count); - _M_bucket_count = __n; - _M_buckets = __new_array; - } - catch(...) - { - // A failure here means that a hash function threw an exception. - // We can't restore the previous state without calling the hash - // function again, so the only sensible recovery is to delete - // everything. - _M_deallocate_nodes(__new_array, __n); - _M_deallocate_buckets(__new_array, __n); - _M_deallocate_nodes(_M_buckets, _M_bucket_count); - _M_element_count = 0; - __throw_exception_again; - } - } - -_GLIBCXX_END_NAMESPACE -} // namespace std::tr1 - -#endif // _TR1_HASHTABLE - diff --git a/libstdc++-v3/include/tr1/hashtable.h b/libstdc++-v3/include/tr1/hashtable.h new file mode 100644 index 0000000..b7cf83e --- /dev/null +++ b/libstdc++-v3/include/tr1/hashtable.h @@ -0,0 +1,58 @@ +// TR1 hashtable.h header -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1/hashtable.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#ifndef _GLIBCXX_TR1_HASHTABLE_H +#define _GLIBCXX_TR1_HASHTABLE_H 1 + +#pragma GCC system_header + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 +#endif + +#endif // _GLIBCXX_TR1_HASHTABLE_H diff --git a/libstdc++-v3/include/tr1/hashtable_policy.h b/libstdc++-v3/include/tr1/hashtable_policy.h deleted file mode 100644 index 270380c..0000000 --- a/libstdc++-v3/include/tr1/hashtable_policy.h +++ /dev/null @@ -1,904 +0,0 @@ -// Internal policy header for TR1 unordered_set and unordered_map -*- C++ -*- - -// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/** @file tr1/hashtable_policy.h - * This is a TR1 C++ Library header. - */ - -#ifndef _TR1_HASHTABLE_POLICY_H -#define _TR1_HASHTABLE_POLICY_H 1 - -#include // lower_bound -#include // equal_to, _Identity, _Select1st -#include -#include - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) -namespace __detail -{ - // Helper function: return distance(first, last) for forward - // iterators, or 0 for input iterators. - template - inline typename std::iterator_traits<_Iterator>::difference_type - __distance_fw(_Iterator __first, _Iterator __last, - std::input_iterator_tag) - { return 0; } - - template - inline typename std::iterator_traits<_Iterator>::difference_type - __distance_fw(_Iterator __first, _Iterator __last, - std::forward_iterator_tag) - { return std::distance(__first, __last); } - - template - inline typename std::iterator_traits<_Iterator>::difference_type - __distance_fw(_Iterator __first, _Iterator __last) - { - typedef typename std::iterator_traits<_Iterator>::iterator_category _Tag; - return __distance_fw(__first, __last, _Tag()); - } - - // XXX This is a hack. _Prime_rehash_policy's member functions, and - // certainly the list of primes, should be defined in a .cc file. - // We're temporarily putting them in a header because we don't have a - // place to put TR1 .cc files yet. There's no good reason for any of - // _Prime_rehash_policy's member functions to be inline, and there's - // certainly no good reason for _Primes<> to exist at all. - struct _LessThan - { - template - bool - operator()(_Tp __x, _Up __y) - { return __x < __y; } - }; - - template - struct _Primes - { - static const int __n_primes = __ulongsize != 8 ? 256 : 256 + 48; - static const unsigned long __primes[256 + 48 + 1]; - }; - - template - const int _Primes<__ulongsize>::__n_primes; - - template - const unsigned long _Primes<__ulongsize>::__primes[256 + 48 + 1] = - { - 2ul, 3ul, 5ul, 7ul, 11ul, 13ul, 17ul, 19ul, 23ul, 29ul, 31ul, - 37ul, 41ul, 43ul, 47ul, 53ul, 59ul, 61ul, 67ul, 71ul, 73ul, 79ul, - 83ul, 89ul, 97ul, 103ul, 109ul, 113ul, 127ul, 137ul, 139ul, 149ul, - 157ul, 167ul, 179ul, 193ul, 199ul, 211ul, 227ul, 241ul, 257ul, - 277ul, 293ul, 313ul, 337ul, 359ul, 383ul, 409ul, 439ul, 467ul, - 503ul, 541ul, 577ul, 619ul, 661ul, 709ul, 761ul, 823ul, 887ul, - 953ul, 1031ul, 1109ul, 1193ul, 1289ul, 1381ul, 1493ul, 1613ul, - 1741ul, 1879ul, 2029ul, 2179ul, 2357ul, 2549ul, 2753ul, 2971ul, - 3209ul, 3469ul, 3739ul, 4027ul, 4349ul, 4703ul, 5087ul, 5503ul, - 5953ul, 6427ul, 6949ul, 7517ul, 8123ul, 8783ul, 9497ul, 10273ul, - 11113ul, 12011ul, 12983ul, 14033ul, 15173ul, 16411ul, 17749ul, - 19183ul, 20753ul, 22447ul, 24281ul, 26267ul, 28411ul, 30727ul, - 33223ul, 35933ul, 38873ul, 42043ul, 45481ul, 49201ul, 53201ul, - 57557ul, 62233ul, 67307ul, 72817ul, 78779ul, 85229ul, 92203ul, - 99733ul, 107897ul, 116731ul, 126271ul, 136607ul, 147793ul, - 159871ul, 172933ul, 187091ul, 202409ul, 218971ul, 236897ul, - 256279ul, 277261ul, 299951ul, 324503ul, 351061ul, 379787ul, - 410857ul, 444487ul, 480881ul, 520241ul, 562841ul, 608903ul, - 658753ul, 712697ul, 771049ul, 834181ul, 902483ul, 976369ul, - 1056323ul, 1142821ul, 1236397ul, 1337629ul, 1447153ul, 1565659ul, - 1693859ul, 1832561ul, 1982627ul, 2144977ul, 2320627ul, 2510653ul, - 2716249ul, 2938679ul, 3179303ul, 3439651ul, 3721303ul, 4026031ul, - 4355707ul, 4712381ul, 5098259ul, 5515729ul, 5967347ul, 6456007ul, - 6984629ul, 7556579ul, 8175383ul, 8844859ul, 9569143ul, 10352717ul, - 11200489ul, 12117689ul, 13109983ul, 14183539ul, 15345007ul, - 16601593ul, 17961079ul, 19431899ul, 21023161ul, 22744717ul, - 24607243ul, 26622317ul, 28802401ul, 31160981ul, 33712729ul, - 36473443ul, 39460231ul, 42691603ul, 46187573ul, 49969847ul, - 54061849ul, 58488943ul, 63278561ul, 68460391ul, 74066549ul, - 80131819ul, 86693767ul, 93793069ul, 101473717ul, 109783337ul, - 118773397ul, 128499677ul, 139022417ul, 150406843ul, 162723577ul, - 176048909ul, 190465427ul, 206062531ul, 222936881ul, 241193053ul, - 260944219ul, 282312799ul, 305431229ul, 330442829ul, 357502601ul, - 386778277ul, 418451333ul, 452718089ul, 489790921ul, 529899637ul, - 573292817ul, 620239453ul, 671030513ul, 725980837ul, 785430967ul, - 849749479ul, 919334987ul, 994618837ul, 1076067617ul, 1164186217ul, - 1259520799ul, 1362662261ul, 1474249943ul, 1594975441ul, - 1725587117ul, 1866894511ul, 2019773507ul, 2185171673ul, - 2364114217ul, 2557710269ul, 2767159799ul, 2993761039ul, - 3238918481ul, 3504151727ul, 3791104843ul, 4101556399ul, - 4294967291ul, - // Sentinel, so we don't have to test the result of lower_bound, - // or, on 64-bit machines, rest of the table. - __ulongsize != 8 ? 4294967291ul : (unsigned long)6442450933ull, - (unsigned long)8589934583ull, - (unsigned long)12884901857ull, (unsigned long)17179869143ull, - (unsigned long)25769803693ull, (unsigned long)34359738337ull, - (unsigned long)51539607367ull, (unsigned long)68719476731ull, - (unsigned long)103079215087ull, (unsigned long)137438953447ull, - (unsigned long)206158430123ull, (unsigned long)274877906899ull, - (unsigned long)412316860387ull, (unsigned long)549755813881ull, - (unsigned long)824633720731ull, (unsigned long)1099511627689ull, - (unsigned long)1649267441579ull, (unsigned long)2199023255531ull, - (unsigned long)3298534883309ull, (unsigned long)4398046511093ull, - (unsigned long)6597069766607ull, (unsigned long)8796093022151ull, - (unsigned long)13194139533241ull, (unsigned long)17592186044399ull, - (unsigned long)26388279066581ull, (unsigned long)35184372088777ull, - (unsigned long)52776558133177ull, (unsigned long)70368744177643ull, - (unsigned long)105553116266399ull, (unsigned long)140737488355213ull, - (unsigned long)211106232532861ull, (unsigned long)281474976710597ull, - (unsigned long)562949953421231ull, (unsigned long)1125899906842597ull, - (unsigned long)2251799813685119ull, (unsigned long)4503599627370449ull, - (unsigned long)9007199254740881ull, (unsigned long)18014398509481951ull, - (unsigned long)36028797018963913ull, (unsigned long)72057594037927931ull, - (unsigned long)144115188075855859ull, - (unsigned long)288230376151711717ull, - (unsigned long)576460752303423433ull, - (unsigned long)1152921504606846883ull, - (unsigned long)2305843009213693951ull, - (unsigned long)4611686018427387847ull, - (unsigned long)9223372036854775783ull, - (unsigned long)18446744073709551557ull, - (unsigned long)18446744073709551557ull - }; - - // Auxiliary types used for all instantiations of _Hashtable: nodes - // and iterators. - - // Nodes, used to wrap elements stored in the hash table. A policy - // template parameter of class template _Hashtable controls whether - // nodes also store a hash code. In some cases (e.g. strings) this - // may be a performance win. - template - struct _Hash_node; - - template - struct _Hash_node<_Value, true> - { - _Value _M_v; - std::size_t _M_hash_code; - _Hash_node* _M_next; - }; - - template - struct _Hash_node<_Value, false> - { - _Value _M_v; - _Hash_node* _M_next; - }; - - // Local iterators, used to iterate within a bucket but not between - // buckets. - template - struct _Node_iterator_base - { - _Node_iterator_base(_Hash_node<_Value, __cache>* __p) - : _M_cur(__p) { } - - void - _M_incr() - { _M_cur = _M_cur->_M_next; } - - _Hash_node<_Value, __cache>* _M_cur; - }; - - template - inline bool - operator==(const _Node_iterator_base<_Value, __cache>& __x, - const _Node_iterator_base<_Value, __cache>& __y) - { return __x._M_cur == __y._M_cur; } - - template - inline bool - operator!=(const _Node_iterator_base<_Value, __cache>& __x, - const _Node_iterator_base<_Value, __cache>& __y) - { return __x._M_cur != __y._M_cur; } - - template - struct _Node_iterator - : public _Node_iterator_base<_Value, __cache> - { - typedef _Value value_type; - typedef typename - __gnu_cxx::__conditional_type<__constant_iterators, - const _Value*, _Value*>::__type - pointer; - typedef typename - __gnu_cxx::__conditional_type<__constant_iterators, - const _Value&, _Value&>::__type - reference; - typedef std::ptrdiff_t difference_type; - typedef std::forward_iterator_tag iterator_category; - - _Node_iterator() - : _Node_iterator_base<_Value, __cache>(0) { } - - explicit - _Node_iterator(_Hash_node<_Value, __cache>* __p) - : _Node_iterator_base<_Value, __cache>(__p) { } - - reference - operator*() const - { return this->_M_cur->_M_v; } - - pointer - operator->() const - { return &this->_M_cur->_M_v; } - - _Node_iterator& - operator++() - { - this->_M_incr(); - return *this; - } - - _Node_iterator - operator++(int) - { - _Node_iterator __tmp(*this); - this->_M_incr(); - return __tmp; - } - }; - - template - struct _Node_const_iterator - : public _Node_iterator_base<_Value, __cache> - { - typedef _Value value_type; - typedef const _Value* pointer; - typedef const _Value& reference; - typedef std::ptrdiff_t difference_type; - typedef std::forward_iterator_tag iterator_category; - - _Node_const_iterator() - : _Node_iterator_base<_Value, __cache>(0) { } - - explicit - _Node_const_iterator(_Hash_node<_Value, __cache>* __p) - : _Node_iterator_base<_Value, __cache>(__p) { } - - _Node_const_iterator(const _Node_iterator<_Value, __constant_iterators, - __cache>& __x) - : _Node_iterator_base<_Value, __cache>(__x._M_cur) { } - - reference - operator*() const - { return this->_M_cur->_M_v; } - - pointer - operator->() const - { return &this->_M_cur->_M_v; } - - _Node_const_iterator& - operator++() - { - this->_M_incr(); - return *this; - } - - _Node_const_iterator - operator++(int) - { - _Node_const_iterator __tmp(*this); - this->_M_incr(); - return __tmp; - } - }; - - template - struct _Hashtable_iterator_base - { - _Hashtable_iterator_base(_Hash_node<_Value, __cache>* __node, - _Hash_node<_Value, __cache>** __bucket) - : _M_cur_node(__node), _M_cur_bucket(__bucket) { } - - void - _M_incr() - { - _M_cur_node = _M_cur_node->_M_next; - if (!_M_cur_node) - _M_incr_bucket(); - } - - void - _M_incr_bucket(); - - _Hash_node<_Value, __cache>* _M_cur_node; - _Hash_node<_Value, __cache>** _M_cur_bucket; - }; - - // Global iterators, used for arbitrary iteration within a hash - // table. Larger and more expensive than local iterators. - template - void - _Hashtable_iterator_base<_Value, __cache>:: - _M_incr_bucket() - { - ++_M_cur_bucket; - - // This loop requires the bucket array to have a non-null sentinel. - while (!*_M_cur_bucket) - ++_M_cur_bucket; - _M_cur_node = *_M_cur_bucket; - } - - template - inline bool - operator==(const _Hashtable_iterator_base<_Value, __cache>& __x, - const _Hashtable_iterator_base<_Value, __cache>& __y) - { return __x._M_cur_node == __y._M_cur_node; } - - template - inline bool - operator!=(const _Hashtable_iterator_base<_Value, __cache>& __x, - const _Hashtable_iterator_base<_Value, __cache>& __y) - { return __x._M_cur_node != __y._M_cur_node; } - - template - struct _Hashtable_iterator - : public _Hashtable_iterator_base<_Value, __cache> - { - typedef _Value value_type; - typedef typename - __gnu_cxx::__conditional_type<__constant_iterators, - const _Value*, _Value*>::__type - pointer; - typedef typename - __gnu_cxx::__conditional_type<__constant_iterators, - const _Value&, _Value&>::__type - reference; - typedef std::ptrdiff_t difference_type; - typedef std::forward_iterator_tag iterator_category; - - _Hashtable_iterator() - : _Hashtable_iterator_base<_Value, __cache>(0, 0) { } - - _Hashtable_iterator(_Hash_node<_Value, __cache>* __p, - _Hash_node<_Value, __cache>** __b) - : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { } - - explicit - _Hashtable_iterator(_Hash_node<_Value, __cache>** __b) - : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { } - - reference - operator*() const - { return this->_M_cur_node->_M_v; } - - pointer - operator->() const - { return &this->_M_cur_node->_M_v; } - - _Hashtable_iterator& - operator++() - { - this->_M_incr(); - return *this; - } - - _Hashtable_iterator - operator++(int) - { - _Hashtable_iterator __tmp(*this); - this->_M_incr(); - return __tmp; - } - }; - - template - struct _Hashtable_const_iterator - : public _Hashtable_iterator_base<_Value, __cache> - { - typedef _Value value_type; - typedef const _Value* pointer; - typedef const _Value& reference; - typedef std::ptrdiff_t difference_type; - typedef std::forward_iterator_tag iterator_category; - - _Hashtable_const_iterator() - : _Hashtable_iterator_base<_Value, __cache>(0, 0) { } - - _Hashtable_const_iterator(_Hash_node<_Value, __cache>* __p, - _Hash_node<_Value, __cache>** __b) - : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { } - - explicit - _Hashtable_const_iterator(_Hash_node<_Value, __cache>** __b) - : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { } - - _Hashtable_const_iterator(const _Hashtable_iterator<_Value, - __constant_iterators, __cache>& __x) - : _Hashtable_iterator_base<_Value, __cache>(__x._M_cur_node, - __x._M_cur_bucket) { } - - reference - operator*() const - { return this->_M_cur_node->_M_v; } - - pointer - operator->() const - { return &this->_M_cur_node->_M_v; } - - _Hashtable_const_iterator& - operator++() - { - this->_M_incr(); - return *this; - } - - _Hashtable_const_iterator - operator++(int) - { - _Hashtable_const_iterator __tmp(*this); - this->_M_incr(); - return __tmp; - } - }; - - - // Many of class template _Hashtable's template parameters are policy - // classes. These are defaults for the policies. - - // Default range hashing function: use division to fold a large number - // into the range [0, N). - struct _Mod_range_hashing - { - typedef std::size_t first_argument_type; - typedef std::size_t second_argument_type; - typedef std::size_t result_type; - - result_type - operator()(first_argument_type __num, second_argument_type __den) const - { return __num % __den; } - }; - - // Default ranged hash function H. In principle it should be a - // function object composed from objects of type H1 and H2 such that - // h(k, N) = h2(h1(k), N), but that would mean making extra copies of - // h1 and h2. So instead we'll just use a tag to tell class template - // hashtable to do that composition. - struct _Default_ranged_hash { }; - - // Default value for rehash policy. Bucket size is (usually) the - // smallest prime that keeps the load factor small enough. - struct _Prime_rehash_policy - { - _Prime_rehash_policy(float __z = 1.0); - - float - max_load_factor() const; - - // Return a bucket size no smaller than n. - std::size_t - _M_next_bkt(std::size_t __n) const; - - // Return a bucket count appropriate for n elements - std::size_t - _M_bkt_for_elements(std::size_t __n) const; - - // __n_bkt is current bucket count, __n_elt is current element count, - // and __n_ins is number of elements to be inserted. Do we need to - // increase bucket count? If so, return make_pair(true, n), where n - // is the new bucket count. If not, return make_pair(false, 0). - std::pair - _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt, - std::size_t __n_ins) const; - - float _M_max_load_factor; - float _M_growth_factor; - mutable std::size_t _M_next_resize; - }; - - inline - _Prime_rehash_policy:: - _Prime_rehash_policy(float __z) - : _M_max_load_factor(__z), _M_growth_factor(2.f), _M_next_resize(0) - { } - - inline float - _Prime_rehash_policy:: - max_load_factor() const - { return _M_max_load_factor; } - - // Return a prime no smaller than n. - inline std::size_t - _Prime_rehash_policy:: - _M_next_bkt(std::size_t __n) const - { - const unsigned long* const __last = (_Primes<>::__primes - + _Primes<>::__n_primes); - const unsigned long* __p = std::lower_bound(_Primes<>::__primes, __last, - __n); - _M_next_resize = static_cast(std::ceil(*__p - * _M_max_load_factor)); - return *__p; - } - - // Return the smallest prime p such that alpha p >= n, where alpha - // is the load factor. - inline std::size_t - _Prime_rehash_policy:: - _M_bkt_for_elements(std::size_t __n) const - { - const unsigned long* const __last = (_Primes<>::__primes - + _Primes<>::__n_primes); - const float __min_bkts = __n / _M_max_load_factor; - const unsigned long* __p = std::lower_bound(_Primes<>::__primes, __last, - __min_bkts, _LessThan()); - _M_next_resize = static_cast(std::ceil(*__p - * _M_max_load_factor)); - return *__p; - } - - // Finds the smallest prime p such that alpha p > __n_elt + __n_ins. - // If p > __n_bkt, return make_pair(true, p); otherwise return - // make_pair(false, 0). In principle this isn't very different from - // _M_bkt_for_elements. - - // The only tricky part is that we're caching the element count at - // which we need to rehash, so we don't have to do a floating-point - // multiply for every insertion. - - inline std::pair - _Prime_rehash_policy:: - _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt, - std::size_t __n_ins) const - { - if (__n_elt + __n_ins > _M_next_resize) - { - float __min_bkts = ((float(__n_ins) + float(__n_elt)) - / _M_max_load_factor); - if (__min_bkts > __n_bkt) - { - __min_bkts = std::max(__min_bkts, _M_growth_factor * __n_bkt); - const unsigned long* const __last = (_Primes<>::__primes - + _Primes<>::__n_primes); - const unsigned long* __p = std::lower_bound(_Primes<>::__primes, - __last, __min_bkts, - _LessThan()); - _M_next_resize = - static_cast(std::ceil(*__p * _M_max_load_factor)); - return std::make_pair(true, *__p); - } - else - { - _M_next_resize = - static_cast(std::ceil(__n_bkt - * _M_max_load_factor)); - return std::make_pair(false, 0); - } - } - else - return std::make_pair(false, 0); - } - - // Base classes for std::tr1::_Hashtable. We define these base - // classes because in some cases we want to do different things - // depending on the value of a policy class. In some cases the - // policy class affects which member functions and nested typedefs - // are defined; we handle that by specializing base class templates. - // Several of the base class templates need to access other members - // of class template _Hashtable, so we use the "curiously recurring - // template pattern" for them. - - // class template _Map_base. If the hashtable has a value type of the - // form pair and a key extraction policy that returns the - // first part of the pair, the hashtable gets a mapped_type typedef. - // If it satisfies those criteria and also has unique keys, then it - // also gets an operator[]. - template - struct _Map_base { }; - - template - struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, false, _Hashtable> - { - typedef typename _Pair::second_type mapped_type; - }; - - template - struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable> - { - typedef typename _Pair::second_type mapped_type; - - mapped_type& - operator[](const _Key& __k); - }; - - template - typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, - true, _Hashtable>::mapped_type& - _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: - operator[](const _Key& __k) - { - _Hashtable* __h = static_cast<_Hashtable*>(this); - typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k); - std::size_t __n = __h->_M_bucket_index(__k, __code, - __h->_M_bucket_count); - - typename _Hashtable::_Node* __p = - __h->_M_find_node(__h->_M_buckets[__n], __k, __code); - if (!__p) - return __h->_M_insert_bucket(std::make_pair(__k, mapped_type()), - __n, __code)->second; - return (__p->_M_v).second; - } - - // class template _Rehash_base. Give hashtable the max_load_factor - // functions iff the rehash policy is _Prime_rehash_policy. - template - struct _Rehash_base { }; - - template - struct _Rehash_base<_Prime_rehash_policy, _Hashtable> - { - float - max_load_factor() const - { - const _Hashtable* __this = static_cast(this); - return __this->__rehash_policy().max_load_factor(); - } - - void - max_load_factor(float __z) - { - _Hashtable* __this = static_cast<_Hashtable*>(this); - __this->__rehash_policy(_Prime_rehash_policy(__z)); - } - }; - - // Class template _Hash_code_base. Encapsulates two policy issues that - // aren't quite orthogonal. - // (1) the difference between using a ranged hash function and using - // the combination of a hash function and a range-hashing function. - // In the former case we don't have such things as hash codes, so - // we have a dummy type as placeholder. - // (2) Whether or not we cache hash codes. Caching hash codes is - // meaningless if we have a ranged hash function. - // We also put the key extraction and equality comparison function - // objects here, for convenience. - - // Primary template: unused except as a hook for specializations. - template - struct _Hash_code_base; - - // Specialization: ranged hash function, no caching hash codes. H1 - // and H2 are provided but ignored. We define a dummy hash code type. - template - struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, - _Hash, false> - { - protected: - _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq, - const _H1&, const _H2&, const _Hash& __h) - : _M_extract(__ex), _M_eq(__eq), _M_ranged_hash(__h) { } - - typedef void* _Hash_code_type; - - _Hash_code_type - _M_hash_code(const _Key& __key) const - { return 0; } - - std::size_t - _M_bucket_index(const _Key& __k, _Hash_code_type, - std::size_t __n) const - { return _M_ranged_hash(__k, __n); } - - std::size_t - _M_bucket_index(const _Hash_node<_Value, false>* __p, - std::size_t __n) const - { return _M_ranged_hash(_M_extract(__p->_M_v), __n); } - - bool - _M_compare(const _Key& __k, _Hash_code_type, - _Hash_node<_Value, false>* __n) const - { return _M_eq(__k, _M_extract(__n->_M_v)); } - - void - _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type) const - { } - - void - _M_copy_code(_Hash_node<_Value, false>*, - const _Hash_node<_Value, false>*) const - { } - - void - _M_swap(_Hash_code_base& __x) - { - std::swap(_M_extract, __x._M_extract); - std::swap(_M_eq, __x._M_eq); - std::swap(_M_ranged_hash, __x._M_ranged_hash); - } - - protected: - _ExtractKey _M_extract; - _Equal _M_eq; - _Hash _M_ranged_hash; - }; - - - // No specialization for ranged hash function while caching hash codes. - // That combination is meaningless, and trying to do it is an error. - - - // Specialization: ranged hash function, cache hash codes. This - // combination is meaningless, so we provide only a declaration - // and no definition. - template - struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, - _Hash, true>; - - // Specialization: hash function and range-hashing function, no - // caching of hash codes. H is provided but ignored. Provides - // typedef and accessor required by TR1. - template - struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, - _Default_ranged_hash, false> - { - typedef _H1 hasher; - - hasher - hash_function() const - { return _M_h1; } - - protected: - _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq, - const _H1& __h1, const _H2& __h2, - const _Default_ranged_hash&) - : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { } - - typedef std::size_t _Hash_code_type; - - _Hash_code_type - _M_hash_code(const _Key& __k) const - { return _M_h1(__k); } - - std::size_t - _M_bucket_index(const _Key&, _Hash_code_type __c, - std::size_t __n) const - { return _M_h2(__c, __n); } - - std::size_t - _M_bucket_index(const _Hash_node<_Value, false>* __p, - std::size_t __n) const - { return _M_h2(_M_h1(_M_extract(__p->_M_v)), __n); } - - bool - _M_compare(const _Key& __k, _Hash_code_type, - _Hash_node<_Value, false>* __n) const - { return _M_eq(__k, _M_extract(__n->_M_v)); } - - void - _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type) const - { } - - void - _M_copy_code(_Hash_node<_Value, false>*, - const _Hash_node<_Value, false>*) const - { } - - void - _M_swap(_Hash_code_base& __x) - { - std::swap(_M_extract, __x._M_extract); - std::swap(_M_eq, __x._M_eq); - std::swap(_M_h1, __x._M_h1); - std::swap(_M_h2, __x._M_h2); - } - - protected: - _ExtractKey _M_extract; - _Equal _M_eq; - _H1 _M_h1; - _H2 _M_h2; - }; - - // Specialization: hash function and range-hashing function, - // caching hash codes. H is provided but ignored. Provides - // typedef and accessor required by TR1. - template - struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, - _Default_ranged_hash, true> - { - typedef _H1 hasher; - - hasher - hash_function() const - { return _M_h1; } - - protected: - _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq, - const _H1& __h1, const _H2& __h2, - const _Default_ranged_hash&) - : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { } - - typedef std::size_t _Hash_code_type; - - _Hash_code_type - _M_hash_code(const _Key& __k) const - { return _M_h1(__k); } - - std::size_t - _M_bucket_index(const _Key&, _Hash_code_type __c, - std::size_t __n) const - { return _M_h2(__c, __n); } - - std::size_t - _M_bucket_index(const _Hash_node<_Value, true>* __p, - std::size_t __n) const - { return _M_h2(__p->_M_hash_code, __n); } - - bool - _M_compare(const _Key& __k, _Hash_code_type __c, - _Hash_node<_Value, true>* __n) const - { return __c == __n->_M_hash_code && _M_eq(__k, _M_extract(__n->_M_v)); } - - void - _M_store_code(_Hash_node<_Value, true>* __n, _Hash_code_type __c) const - { __n->_M_hash_code = __c; } - - void - _M_copy_code(_Hash_node<_Value, true>* __to, - const _Hash_node<_Value, true>* __from) const - { __to->_M_hash_code = __from->_M_hash_code; } - - void - _M_swap(_Hash_code_base& __x) - { - std::swap(_M_extract, __x._M_extract); - std::swap(_M_eq, __x._M_eq); - std::swap(_M_h1, __x._M_h1); - std::swap(_M_h2, __x._M_h2); - } - - protected: - _ExtractKey _M_extract; - _Equal _M_eq; - _H1 _M_h1; - _H2 _M_h2; - }; -} // namespace __detail -_GLIBCXX_END_NAMESPACE -} // namespace std::tr1 - -#endif // _TR1_HASHTABLE_POLICY_H - diff --git a/libstdc++-v3/include/tr1/hypergeometric.tcc b/libstdc++-v3/include/tr1/hypergeometric.tcc index c0d676f..17fa959 100644 --- a/libstdc++-v3/include/tr1/hypergeometric.tcc +++ b/libstdc++-v3/include/tr1/hypergeometric.tcc @@ -44,12 +44,13 @@ // Section 6, pp. 555-566 // (2) The Gnu Scientific Library, http://www.gnu.org/software/gsl -#ifndef _TR1_HYPERGEOMETRIC_TCC -#define _TR1_HYPERGEOMETRIC_TCC 1 +#ifndef _GLIBCXX_TR1_HYPERGEOMETRIC_TCC +#define _GLIBCXX_TR1_HYPERGEOMETRIC_TCC 1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -233,7 +234,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) __conf_hyperg(const _Tp __a, const _Tp __c, const _Tp __x) { #if _GLIBCXX_USE_C99_MATH_TR1 - const _Tp __c_nint = std::_GLIBCXX_TR1::nearbyint(__c); + const _Tp __c_nint = std::tr1::nearbyint(__c); #else const _Tp __c_nint = static_cast(__c + _Tp(0.5L)); #endif @@ -735,9 +736,9 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) __hyperg(const _Tp __a, const _Tp __b, const _Tp __c, const _Tp __x) { #if _GLIBCXX_USE_C99_MATH_TR1 - const _Tp __a_nint = std::_GLIBCXX_TR1::nearbyint(__a); - const _Tp __b_nint = std::_GLIBCXX_TR1::nearbyint(__b); - const _Tp __c_nint = std::_GLIBCXX_TR1::nearbyint(__c); + const _Tp __a_nint = std::tr1::nearbyint(__a); + const _Tp __b_nint = std::tr1::nearbyint(__b); + const _Tp __c_nint = std::tr1::nearbyint(__c); #else const _Tp __a_nint = static_cast(__a + _Tp(0.5L)); const _Tp __b_nint = static_cast(__b + _Tp(0.5L)); @@ -782,7 +783,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_HYPERGEOMETRIC_TCC +#endif // _GLIBCXX_TR1_HYPERGEOMETRIC_TCC diff --git a/libstdc++-v3/include/tr1/inttypes.h b/libstdc++-v3/include/tr1/inttypes.h index 720089c..3253247 100644 --- a/libstdc++-v3/include/tr1/inttypes.h +++ b/libstdc++-v3/include/tr1/inttypes.h @@ -1,6 +1,6 @@ // TR1 inttypes.h -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_INTTYPES_H -#define _TR1_INTTYPES_H 1 +#ifndef _GLIBCXX_TR1_INTTYPES_H +#define _GLIBCXX_TR1_INTTYPES_H 1 #include -#endif +#endif // _GLIBCXX_TR1_INTTYPES_H diff --git a/libstdc++-v3/include/tr1/legendre_function.tcc b/libstdc++-v3/include/tr1/legendre_function.tcc index 323bd18..839459f 100644 --- a/libstdc++-v3/include/tr1/legendre_function.tcc +++ b/libstdc++-v3/include/tr1/legendre_function.tcc @@ -47,14 +47,15 @@ // W. T. Vetterling, B. P. Flannery, Cambridge University Press (1992), // 2nd ed, pp. 252-254 -#ifndef _TR1_LEGENDRE_FUNCTION_TCC -#define _TR1_LEGENDRE_FUNCTION_TCC 1 +#ifndef _GLIBCXX_TR1_LEGENDRE_FUNCTION_TCC +#define _GLIBCXX_TR1_LEGENDRE_FUNCTION_TCC 1 #include "special_function_util.h" namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -256,14 +257,14 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) const _Tp __sgn = ( __m % 2 == 1 ? -_Tp(1) : _Tp(1)); const _Tp __y_mp1m_factor = __x * std::sqrt(_Tp(2 * __m + 3)); #if _GLIBCXX_USE_C99_MATH_TR1 - const _Tp __lncirc = std::_GLIBCXX_TR1::log1p(-__x * __x); + const _Tp __lncirc = std::tr1::log1p(-__x * __x); #else const _Tp __lncirc = std::log(_Tp(1) - __x * __x); #endif // Gamma(m+1/2) / Gamma(m) #if _GLIBCXX_USE_C99_MATH_TR1 - const _Tp __lnpoch = std::_GLIBCXX_TR1::lgamma(_Tp(__m + _Tp(0.5L))) - - std::_GLIBCXX_TR1::lgamma(_Tp(__m)); + const _Tp __lnpoch = std::tr1::lgamma(_Tp(__m + _Tp(0.5L))) + - std::tr1::lgamma(_Tp(__m)); #else const _Tp __lnpoch = __log_gamma(_Tp(__m + _Tp(0.5L))) - __log_gamma(_Tp(__m)); @@ -312,7 +313,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_LEGENDRE_FUNCTION_TCC +#endif // _GLIBCXX_TR1_LEGENDRE_FUNCTION_TCC diff --git a/libstdc++-v3/include/tr1/math.h b/libstdc++-v3/include/tr1/math.h index 0698cb2..4e95b9b 100644 --- a/libstdc++-v3/include/tr1/math.h +++ b/libstdc++-v3/include/tr1/math.h @@ -31,161 +31,161 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_MATH_H -#define _TR1_MATH_H 1 +#ifndef _GLIBCXX_TR1_MATH_H +#define _GLIBCXX_TR1_MATH_H 1 #include #if _GLIBCXX_USE_C99_MATH_TR1 -using std::_GLIBCXX_TR1::acos; -using std::_GLIBCXX_TR1::acosh; -using std::_GLIBCXX_TR1::asin; -using std::_GLIBCXX_TR1::asinh; -using std::_GLIBCXX_TR1::atan; -using std::_GLIBCXX_TR1::atan2; -using std::_GLIBCXX_TR1::atanh; -using std::_GLIBCXX_TR1::cbrt; -using std::_GLIBCXX_TR1::ceil; -using std::_GLIBCXX_TR1::copysign; -using std::_GLIBCXX_TR1::cos; -using std::_GLIBCXX_TR1::cosh; -using std::_GLIBCXX_TR1::erf; -using std::_GLIBCXX_TR1::erfc; -using std::_GLIBCXX_TR1::exp; -using std::_GLIBCXX_TR1::exp2; -using std::_GLIBCXX_TR1::expm1; -using std::_GLIBCXX_TR1::fabs; -using std::_GLIBCXX_TR1::fdim; -using std::_GLIBCXX_TR1::floor; -using std::_GLIBCXX_TR1::fma; -using std::_GLIBCXX_TR1::fmax; -using std::_GLIBCXX_TR1::fmin; -using std::_GLIBCXX_TR1::fmod; -using std::_GLIBCXX_TR1::frexp; -using std::_GLIBCXX_TR1::hypot; -using std::_GLIBCXX_TR1::ilogb; -using std::_GLIBCXX_TR1::ldexp; -using std::_GLIBCXX_TR1::lgamma; -using std::_GLIBCXX_TR1::llrint; -using std::_GLIBCXX_TR1::llround; -using std::_GLIBCXX_TR1::log; -using std::_GLIBCXX_TR1::log10; -using std::_GLIBCXX_TR1::log1p; -using std::_GLIBCXX_TR1::log2; -using std::_GLIBCXX_TR1::logb; -using std::_GLIBCXX_TR1::lrint; -using std::_GLIBCXX_TR1::lround; -using std::_GLIBCXX_TR1::nearbyint; -using std::_GLIBCXX_TR1::nextafter; -using std::_GLIBCXX_TR1::nexttoward; -using std::_GLIBCXX_TR1::pow; -using std::_GLIBCXX_TR1::remainder; -using std::_GLIBCXX_TR1::remquo; -using std::_GLIBCXX_TR1::rint; -using std::_GLIBCXX_TR1::round; -using std::_GLIBCXX_TR1::scalbln; -using std::_GLIBCXX_TR1::scalbn; -using std::_GLIBCXX_TR1::sin; -using std::_GLIBCXX_TR1::sinh; -using std::_GLIBCXX_TR1::sqrt; -using std::_GLIBCXX_TR1::tan; -using std::_GLIBCXX_TR1::tanh; -using std::_GLIBCXX_TR1::tgamma; -using std::_GLIBCXX_TR1::trunc; +using std::tr1::acos; +using std::tr1::acosh; +using std::tr1::asin; +using std::tr1::asinh; +using std::tr1::atan; +using std::tr1::atan2; +using std::tr1::atanh; +using std::tr1::cbrt; +using std::tr1::ceil; +using std::tr1::copysign; +using std::tr1::cos; +using std::tr1::cosh; +using std::tr1::erf; +using std::tr1::erfc; +using std::tr1::exp; +using std::tr1::exp2; +using std::tr1::expm1; +using std::tr1::fabs; +using std::tr1::fdim; +using std::tr1::floor; +using std::tr1::fma; +using std::tr1::fmax; +using std::tr1::fmin; +using std::tr1::fmod; +using std::tr1::frexp; +using std::tr1::hypot; +using std::tr1::ilogb; +using std::tr1::ldexp; +using std::tr1::lgamma; +using std::tr1::llrint; +using std::tr1::llround; +using std::tr1::log; +using std::tr1::log10; +using std::tr1::log1p; +using std::tr1::log2; +using std::tr1::logb; +using std::tr1::lrint; +using std::tr1::lround; +using std::tr1::nearbyint; +using std::tr1::nextafter; +using std::tr1::nexttoward; +using std::tr1::pow; +using std::tr1::remainder; +using std::tr1::remquo; +using std::tr1::rint; +using std::tr1::round; +using std::tr1::scalbln; +using std::tr1::scalbn; +using std::tr1::sin; +using std::tr1::sinh; +using std::tr1::sqrt; +using std::tr1::tan; +using std::tr1::tanh; +using std::tr1::tgamma; +using std::tr1::trunc; #endif -using std::_GLIBCXX_TR1::assoc_laguerref; -using std::_GLIBCXX_TR1::assoc_laguerre; -using std::_GLIBCXX_TR1::assoc_laguerrel; +using std::tr1::assoc_laguerref; +using std::tr1::assoc_laguerre; +using std::tr1::assoc_laguerrel; -using std::_GLIBCXX_TR1::assoc_legendref; -using std::_GLIBCXX_TR1::assoc_legendre; -using std::_GLIBCXX_TR1::assoc_legendrel; +using std::tr1::assoc_legendref; +using std::tr1::assoc_legendre; +using std::tr1::assoc_legendrel; -using std::_GLIBCXX_TR1::betaf; -using std::_GLIBCXX_TR1::beta; -using std::_GLIBCXX_TR1::betal; +using std::tr1::betaf; +using std::tr1::beta; +using std::tr1::betal; -using std::_GLIBCXX_TR1::comp_ellint_1f; -using std::_GLIBCXX_TR1::comp_ellint_1; -using std::_GLIBCXX_TR1::comp_ellint_1l; +using std::tr1::comp_ellint_1f; +using std::tr1::comp_ellint_1; +using std::tr1::comp_ellint_1l; -using std::_GLIBCXX_TR1::comp_ellint_2f; -using std::_GLIBCXX_TR1::comp_ellint_2; -using std::_GLIBCXX_TR1::comp_ellint_2l; +using std::tr1::comp_ellint_2f; +using std::tr1::comp_ellint_2; +using std::tr1::comp_ellint_2l; -using std::_GLIBCXX_TR1::comp_ellint_3f; -using std::_GLIBCXX_TR1::comp_ellint_3; -using std::_GLIBCXX_TR1::comp_ellint_3l; +using std::tr1::comp_ellint_3f; +using std::tr1::comp_ellint_3; +using std::tr1::comp_ellint_3l; -using std::_GLIBCXX_TR1::conf_hypergf; -using std::_GLIBCXX_TR1::conf_hyperg; -using std::_GLIBCXX_TR1::conf_hypergl; +using std::tr1::conf_hypergf; +using std::tr1::conf_hyperg; +using std::tr1::conf_hypergl; -using std::_GLIBCXX_TR1::cyl_bessel_if; -using std::_GLIBCXX_TR1::cyl_bessel_i; -using std::_GLIBCXX_TR1::cyl_bessel_il; +using std::tr1::cyl_bessel_if; +using std::tr1::cyl_bessel_i; +using std::tr1::cyl_bessel_il; -using std::_GLIBCXX_TR1::cyl_bessel_jf; -using std::_GLIBCXX_TR1::cyl_bessel_j; -using std::_GLIBCXX_TR1::cyl_bessel_jl; +using std::tr1::cyl_bessel_jf; +using std::tr1::cyl_bessel_j; +using std::tr1::cyl_bessel_jl; -using std::_GLIBCXX_TR1::cyl_bessel_kf; -using std::_GLIBCXX_TR1::cyl_bessel_k; -using std::_GLIBCXX_TR1::cyl_bessel_kl; +using std::tr1::cyl_bessel_kf; +using std::tr1::cyl_bessel_k; +using std::tr1::cyl_bessel_kl; -using std::_GLIBCXX_TR1::cyl_neumannf; -using std::_GLIBCXX_TR1::cyl_neumann; -using std::_GLIBCXX_TR1::cyl_neumannl; +using std::tr1::cyl_neumannf; +using std::tr1::cyl_neumann; +using std::tr1::cyl_neumannl; -using std::_GLIBCXX_TR1::ellint_1f; -using std::_GLIBCXX_TR1::ellint_1; -using std::_GLIBCXX_TR1::ellint_1l; +using std::tr1::ellint_1f; +using std::tr1::ellint_1; +using std::tr1::ellint_1l; -using std::_GLIBCXX_TR1::ellint_2f; -using std::_GLIBCXX_TR1::ellint_2; -using std::_GLIBCXX_TR1::ellint_2l; +using std::tr1::ellint_2f; +using std::tr1::ellint_2; +using std::tr1::ellint_2l; -using std::_GLIBCXX_TR1::ellint_3f; -using std::_GLIBCXX_TR1::ellint_3; -using std::_GLIBCXX_TR1::ellint_3l; +using std::tr1::ellint_3f; +using std::tr1::ellint_3; +using std::tr1::ellint_3l; -using std::_GLIBCXX_TR1::expintf; -using std::_GLIBCXX_TR1::expint; -using std::_GLIBCXX_TR1::expintl; +using std::tr1::expintf; +using std::tr1::expint; +using std::tr1::expintl; -using std::_GLIBCXX_TR1::hermitef; -using std::_GLIBCXX_TR1::hermite; -using std::_GLIBCXX_TR1::hermitel; +using std::tr1::hermitef; +using std::tr1::hermite; +using std::tr1::hermitel; -using std::_GLIBCXX_TR1::hypergf; -using std::_GLIBCXX_TR1::hyperg; -using std::_GLIBCXX_TR1::hypergl; +using std::tr1::hypergf; +using std::tr1::hyperg; +using std::tr1::hypergl; -using std::_GLIBCXX_TR1::laguerref; -using std::_GLIBCXX_TR1::laguerre; -using std::_GLIBCXX_TR1::laguerrel; +using std::tr1::laguerref; +using std::tr1::laguerre; +using std::tr1::laguerrel; -using std::_GLIBCXX_TR1::legendref; -using std::_GLIBCXX_TR1::legendre; -using std::_GLIBCXX_TR1::legendrel; +using std::tr1::legendref; +using std::tr1::legendre; +using std::tr1::legendrel; -using std::_GLIBCXX_TR1::riemann_zetaf; -using std::_GLIBCXX_TR1::riemann_zeta; -using std::_GLIBCXX_TR1::riemann_zetal; +using std::tr1::riemann_zetaf; +using std::tr1::riemann_zeta; +using std::tr1::riemann_zetal; -using std::_GLIBCXX_TR1::sph_besself; -using std::_GLIBCXX_TR1::sph_bessel; -using std::_GLIBCXX_TR1::sph_bessell; +using std::tr1::sph_besself; +using std::tr1::sph_bessel; +using std::tr1::sph_bessell; -using std::_GLIBCXX_TR1::sph_legendref; -using std::_GLIBCXX_TR1::sph_legendre; -using std::_GLIBCXX_TR1::sph_legendrel; +using std::tr1::sph_legendref; +using std::tr1::sph_legendre; +using std::tr1::sph_legendrel; -using std::_GLIBCXX_TR1::sph_neumannf; -using std::_GLIBCXX_TR1::sph_neumann; -using std::_GLIBCXX_TR1::sph_neumannl; +using std::tr1::sph_neumannf; +using std::tr1::sph_neumann; +using std::tr1::sph_neumannl; -#endif +#endif // _GLIBCXX_TR1_MATH_H diff --git a/libstdc++-v3/include/tr1/memory b/libstdc++-v3/include/tr1/memory index f397c98..69f2f57 100644 --- a/libstdc++-v3/include/tr1/memory +++ b/libstdc++-v3/include/tr1/memory @@ -32,24 +32,40 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_MEMORY -#define _TR1_MEMORY 1 +#ifndef _GLIBCXX_TR1_MEMORY +#define _GLIBCXX_TR1_MEMORY 1 -#include // std::size_t +#pragma GCC system_header + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif + +#include #include // std::exception #include // std::bad_alloc #include // std::type_info in get_deleter #include // std::swap #include // std::basic_ostream -#include - #include #include #include #include // std::less #include +#include -#include // tr1::add_reference -#include - +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif + +#endif // _GLIBCXX_TR1_MEMORY diff --git a/libstdc++-v3/include/tr1/modified_bessel_func.tcc b/libstdc++-v3/include/tr1/modified_bessel_func.tcc index c7065a2..912f99f 100644 --- a/libstdc++-v3/include/tr1/modified_bessel_func.tcc +++ b/libstdc++-v3/include/tr1/modified_bessel_func.tcc @@ -49,14 +49,15 @@ // W. T. Vetterling, B. P. Flannery, Cambridge University Press (1992), // 2nd ed, pp. 246-249. -#ifndef _TR1_MODIFIED_BESSEL_FUNC_TCC -#define _TR1_MODIFIED_BESSEL_FUNC_TCC 1 +#ifndef _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC +#define _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC 1 #include "special_function_util.h" namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -444,7 +445,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_MODIFIED_BESSEL_FUNC_TCC +#endif // _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC diff --git a/libstdc++-v3/include/tr1/poly_hermite.tcc b/libstdc++-v3/include/tr1/poly_hermite.tcc index 3a7bf92..2d8ccfe 100644 --- a/libstdc++-v3/include/tr1/poly_hermite.tcc +++ b/libstdc++-v3/include/tr1/poly_hermite.tcc @@ -42,12 +42,13 @@ // Ed. Milton Abramowitz and Irene A. Stegun, // Dover Publications, Section 22 pp. 773-802 -#ifndef _TR1_POLY_HERMITE_TCC -#define _TR1_POLY_HERMITE_TCC 1 +#ifndef _GLIBCXX_TR1_POLY_HERMITE_TCC +#define _GLIBCXX_TR1_POLY_HERMITE_TCC 1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -132,7 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_POLY_HERMITE_TCC +#endif // _GLIBCXX_TR1_POLY_HERMITE_TCC diff --git a/libstdc++-v3/include/tr1/poly_laguerre.tcc b/libstdc++-v3/include/tr1/poly_laguerre.tcc index b99d092..46c51a5 100644 --- a/libstdc++-v3/include/tr1/poly_laguerre.tcc +++ b/libstdc++-v3/include/tr1/poly_laguerre.tcc @@ -44,12 +44,13 @@ // Section 13, pp. 509-510, Section 22 pp. 773-802 // (2) The Gnu Scientific Library, http://www.gnu.org/software/gsl -#ifndef _TR1_POLY_LAGUERRE_TCC -#define _TR1_POLY_LAGUERRE_TCC 1 +#ifndef _GLIBCXX_TR1_POLY_LAGUERRE_TCC +#define _GLIBCXX_TR1_POLY_LAGUERRE_TCC 1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -94,8 +95,8 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) * __eta * __eta * __cos2th * __sin2th; #if _GLIBCXX_USE_C99_MATH_TR1 - const _Tp __lg_b = std::_GLIBCXX_TR1::lgamma(_Tp(__n) + __b); - const _Tp __lnfact = std::_GLIBCXX_TR1::lgamma(_Tp(__n + 1)); + const _Tp __lg_b = std::tr1::lgamma(_Tp(__n) + __b); + const _Tp __lnfact = std::tr1::lgamma(_Tp(__n + 1)); #else const _Tp __lg_b = __log_gamma(_Tp(__n) + __b); const _Tp __lnfact = __log_gamma(_Tp(__n + 1)); @@ -337,7 +338,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_POLY_LAGUERRE_TCC +#endif // _GLIBCXX_TR1_POLY_LAGUERRE_TCC diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random index 1033743..49a3b21 100644 --- a/libstdc++-v3/include/tr1/random +++ b/libstdc++-v3/include/tr1/random @@ -32,8 +32,14 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_RANDOM -#define _TR1_RANDOM 1 +#ifndef _GLIBCXX_TR1_RANDOM +#define _GLIBCXX_TR1_RANDOM 1 + +#pragma GCC system_header + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif #include #include @@ -41,2326 +47,25 @@ #include #include #include -#include -#include #include #include #include #include +#include +#include -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // [5.1] Random number generation - - /** - * @addtogroup tr1_random Random Number Generation - * A facility for generating random numbers on selected distributions. - * @{ - */ - - /* - * Implementation-space details. - */ - namespace __detail - { - template::digits> - struct _Shift - { static const _UIntType __value = 0; }; - - template - struct _Shift<_UIntType, __w, true> - { static const _UIntType __value = _UIntType(1) << __w; }; - - template - struct _Mod; - - // Dispatch based on modulus value to prevent divide-by-zero compile-time - // errors when m == 0. - template - inline _Tp - __mod(_Tp __x) - { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); } - - typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4), - unsigned, unsigned long>::__type _UInt32Type; - - /* - * An adaptor class for converting the output of any Generator into - * the input for a specific Distribution. - */ - template - struct _Adaptor - { - typedef typename _Engine::result_type _Engine_result_type; - typedef typename _Distribution::input_type result_type; - - public: - _Adaptor(const _Engine& __g) - : _M_g(__g) { } - - result_type - min() const - { - result_type __return_value = 0; - if (is_integral<_Engine_result_type>::value - && is_integral::value) - __return_value = _M_g.min(); - else if (!is_integral::value) - __return_value = result_type(0); - return __return_value; - } - - result_type - max() const - { - result_type __return_value = 0; - if (is_integral<_Engine_result_type>::value - && is_integral::value) - __return_value = _M_g.max(); - else if (!is_integral::value) - __return_value = result_type(1); - return __return_value; - } - - result_type - operator()(); - - private: - _Engine _M_g; - }; - - /* - * Converts a value generated by the adapted random number generator into a - * value in the input domain for the dependent random number distribution. - * - * Because the type traits are compile time constants only the appropriate - * clause of the if statements will actually be emitted by the compiler. - */ - template - typename _Adaptor<_Engine, _Distribution>::result_type - _Adaptor<_Engine, _Distribution>:: - operator()() - { - result_type __return_value = 0; - if (is_integral<_Engine_result_type>::value - && is_integral::value) - __return_value = _M_g(); - else if (is_integral<_Engine_result_type>::value - && !is_integral::value) - __return_value = result_type(_M_g() - _M_g.min()) - / result_type(_M_g.max() - _M_g.min() + result_type(1)); - else if (!is_integral<_Engine_result_type>::value - && !is_integral::value) - __return_value = result_type(_M_g() - _M_g.min()) - / result_type(_M_g.max() - _M_g.min()); - return __return_value; - } - } // namespace __detail - - /** - * Produces random numbers on a given disribution function using a un uniform - * random number generation engine. - * - * @todo the engine_value_type needs to be studied more carefully. - */ - template - class variate_generator - { - // Concept requirements. - __glibcxx_class_requires(_Engine, _CopyConstructibleConcept) - // __glibcxx_class_requires(_Engine, _EngineConcept) - // __glibcxx_class_requires(_Dist, _EngineConcept) - - public: - typedef _Engine engine_type; - typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type; - typedef _Dist distribution_type; - typedef typename _Dist::result_type result_type; - - // tr1:5.1.1 table 5.1 requirement - typedef typename __gnu_cxx::__enable_if< - is_arithmetic::value, result_type>::__type _IsValidType; - - /** - * Constructs a variate generator with the uniform random number - * generator @p __eng for the random distribution @p __dist. - * - * @throws Any exceptions which may thrown by the copy constructors of - * the @p _Engine or @p _Dist objects. - */ - variate_generator(engine_type __eng, distribution_type __dist) - : _M_engine(__eng), _M_dist(__dist) { } - - /** - * Gets the next generated value on the distribution. - */ - result_type - operator()() - { return _M_dist(_M_engine); } - - /** - * WTF? - */ - template - result_type - operator()(_Tp __value) - { return _M_dist(_M_engine, __value); } - - /** - * Gets a reference to the underlying uniform random number generator - * object. - */ - engine_value_type& - engine() - { return _M_engine; } - - /** - * Gets a const reference to the underlying uniform random number - * generator object. - */ - const engine_value_type& - engine() const - { return _M_engine; } - - /** - * Gets a reference to the underlying random distribution. - */ - distribution_type& - distribution() - { return _M_dist; } - - /** - * Gets a const reference to the underlying random distribution. - */ - const distribution_type& - distribution() const - { return _M_dist; } - - /** - * Gets the closed lower bound of the distribution interval. - */ - result_type - min() const - { return this->distribution().min(); } - - /** - * Gets the closed upper bound of the distribution interval. - */ - result_type - max() const - { return this->distribution().max(); } - - private: - engine_value_type _M_engine; - distribution_type _M_dist; - }; - - - /** - * @addtogroup tr1_random_generators Random Number Generators - * @ingroup tr1_random - * - * These classes define objects which provide random or pseudorandom - * numbers, either from a discrete or a continuous interval. The - * random number generator supplied as a part of this library are - * all uniform random number generators which provide a sequence of - * random number uniformly distributed over their range. - * - * A number generator is a function object with an operator() that - * takes zero arguments and returns a number. - * - * A compliant random number generator must satisy the following - * requirements. - * - *
Random Number Generator Requirements
To be documented.
- * - * @{ - */ - - /** - * @brief A model of a linear congruential random number generator. - * - * A random number generator that produces pseudorandom numbers using the - * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$. - * - * The template parameter @p _UIntType must be an unsigned integral type - * large enough to store values up to (__m-1). If the template parameter - * @p __m is 0, the modulus @p __m used is - * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template - * parameters @p __a and @p __c must be less than @p __m. - * - * The size of the state is @f$ 1 @f$. - */ - template - class linear_congruential - { - __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) - // __glibcpp_class_requires(__a < __m && __c < __m) - - public: - /** The type of the generated random value. */ - typedef _UIntType result_type; - - /** The multiplier. */ - static const _UIntType multiplier = __a; - /** An increment. */ - static const _UIntType increment = __c; - /** The modulus. */ - static const _UIntType modulus = __m; - - /** - * Constructs a %linear_congruential random number generator engine with - * seed @p __s. The default seed value is 1. - * - * @param __s The initial seed value. - */ - explicit - linear_congruential(unsigned long __x0 = 1) - { this->seed(__x0); } - - /** - * Constructs a %linear_congruential random number generator engine - * seeded from the generator function @p __g. - * - * @param __g The seed generator function. - */ - template - linear_congruential(_Gen& __g) - { this->seed(__g); } - - /** - * Reseeds the %linear_congruential random number generator engine - * sequence to the seed @g __s. - * - * @param __s The new seed. - */ - void - seed(unsigned long __s = 1); - - /** - * Reseeds the %linear_congruential random number generator engine - * sequence using values from the generator function @p __g. - * - * @param __g the seed generator function. - */ - template - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - /** - * Gets the smallest possible value in the output range. - * - * The minumum depends on the @p __c parameter: if it is zero, the - * minimum generated must be > 0, otherwise 0 is allowed. - */ - result_type - min() const - { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; } - - /** - * Gets the largest possible value in the output range. - */ - result_type - max() const - { return __m - 1; } - - /** - * Gets the next random number in the sequence. - */ - result_type - operator()(); - - /** - * Compares two linear congruential random number generator - * objects of the same type for equality. - * - * @param __lhs A linear congruential random number generator object. - * @param __rhs Another linear congruential random number generator obj. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const linear_congruential& __lhs, - const linear_congruential& __rhs) - { return __lhs._M_x == __rhs._M_x; } - - /** - * Compares two linear congruential random number generator - * objects of the same type for inequality. - * - * @param __lhs A linear congruential random number generator object. - * @param __rhs Another linear congruential random number generator obj. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const linear_congruential& __lhs, - const linear_congruential& __rhs) - { return !(__lhs == __rhs); } - - /** - * Writes the textual representation of the state x(i) of x to @p __os. - * - * @param __os The output stream. - * @param __lcr A % linear_congruential random number generator. - * @returns __os. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const linear_congruential<_UIntType1, __a1, __c1, - __m1>& __lcr); - - /** - * Sets the state of the engine by reading its textual - * representation from @p __is. - * - * The textual representation must have been previously written using an - * output stream whose imbued locale and whose type's template - * specialization arguments _CharT and _Traits were the same as those of - * @p __is. - * - * @param __is The input stream. - * @param __lcr A % linear_congruential random number generator. - * @returns __is. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr); - - private: - template - void - seed(_Gen& __g, true_type) - { return seed(static_cast(__g)); } - - template - void - seed(_Gen& __g, false_type); - - _UIntType _M_x; - }; - - /** - * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller. - */ - typedef linear_congruential minstd_rand0; - - /** - * An alternative LCR (Lehmer Generator function) . - */ - typedef linear_congruential minstd_rand; - - - /** - * A generalized feedback shift register discrete random number generator. - * - * This algorithm avoind multiplication and division and is designed to be - * friendly to a pipelined architecture. If the parameters are chosen - * correctly, this generator will produce numbers with a very long period and - * fairly good apparent entropy, although still not cryptographically strong. - * - * The best way to use this generator is with the predefined mt19937 class. - * - * This algorithm was originally invented by Makoto Matsumoto and - * Takuji Nishimura. - * - * @var word_size The number of bits in each element of the state vector. - * @var state_size The degree of recursion. - * @var shift_size The period parameter. - * @var mask_bits The separation point bit index. - * @var parameter_a The last row of the twist matrix. - * @var output_u The first right-shift tempering matrix parameter. - * @var output_s The first left-shift tempering matrix parameter. - * @var output_b The first left-shift tempering matrix mask. - * @var output_t The second left-shift tempering matrix parameter. - * @var output_c The second left-shift tempering matrix mask. - * @var output_l The second right-shift tempering matrix parameter. - */ - template - class mersenne_twister - { - __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) - - public: - // types - typedef _UIntType result_type; - - // parameter values - static const int word_size = __w; - static const int state_size = __n; - static const int shift_size = __m; - static const int mask_bits = __r; - static const _UIntType parameter_a = __a; - static const int output_u = __u; - static const int output_s = __s; - static const _UIntType output_b = __b; - static const int output_t = __t; - static const _UIntType output_c = __c; - static const int output_l = __l; - - // constructors and member function - mersenne_twister() - { seed(); } - - explicit - mersenne_twister(unsigned long __value) - { seed(__value); } - - template - mersenne_twister(_Gen& __g) - { seed(__g); } - - void - seed() - { seed(5489UL); } - - void - seed(unsigned long __value); - - template - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - result_type - min() const - { return 0; }; - - result_type - max() const - { return __detail::_Shift<_UIntType, __w>::__value - 1; } - - result_type - operator()(); - - /** - * Compares two % mersenne_twister random number generator objects of - * the same type for equality. - * - * @param __lhs A % mersenne_twister random number generator object. - * @param __rhs Another % mersenne_twister random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const mersenne_twister& __lhs, - const mersenne_twister& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); } - - /** - * Compares two % mersenne_twister random number generator objects of - * the same type for inequality. - * - * @param __lhs A % mersenne_twister random number generator object. - * @param __rhs Another % mersenne_twister random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const mersenne_twister& __lhs, - const mersenne_twister& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a % mersenne_twister random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A % mersenne_twister random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, - __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); - - /** - * Extracts the current state of a % mersenne_twister random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A % mersenne_twister random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, - __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); - - private: - template - void - seed(_Gen& __g, true_type) - { return seed(static_cast(__g)); } - - template - void - seed(_Gen& __g, false_type); - - _UIntType _M_x[state_size]; - int _M_p; - }; - - /** - * The classic Mersenne Twister. - * - * Reference: - * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally - * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions - * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. - */ - typedef mersenne_twister< - unsigned long, 32, 624, 397, 31, - 0x9908b0dful, 11, 7, - 0x9d2c5680ul, 15, - 0xefc60000ul, 18 - > mt19937; - - - /** - * @brief The Marsaglia-Zaman generator. - * - * This is a model of a Generalized Fibonacci discrete random number - * generator, sometimes referred to as the SWC generator. - * - * A discrete random number generator that produces pseudorandom - * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} - - * carry_{i-1}) \bmod m @f$. - * - * The size of the state is @f$ r @f$ - * and the maximum period of the generator is @f$ m^r - m^s -1 @f$. - * - * N1688[4.13] says "the template parameter _IntType shall denote an integral - * type large enough to store values up to m." - * - * @if maint - * @var _M_x The state of the generator. This is a ring buffer. - * @var _M_carry The carry. - * @var _M_p Current index of x(i - r). - * @endif - */ - template - class subtract_with_carry - { - __glibcxx_class_requires(_IntType, _IntegerConcept) - - public: - /** The type of the generated random value. */ - typedef _IntType result_type; - - // parameter values - static const _IntType modulus = __m; - static const int long_lag = __r; - static const int short_lag = __s; - - /** - * Constructs a default-initialized % subtract_with_carry random number - * generator. - */ - subtract_with_carry() - { this->seed(); } - - /** - * Constructs an explicitly seeded % subtract_with_carry random number - * generator. - */ - explicit - subtract_with_carry(unsigned long __value) - { this->seed(__value); } - - /** - * Constructs a %subtract_with_carry random number generator engine - * seeded from the generator function @p __g. - * - * @param __g The seed generator function. - */ - template - subtract_with_carry(_Gen& __g) - { this->seed(__g); } - - /** - * Seeds the initial state @f$ x_0 @f$ of the random number generator. - * - * N1688[4.19] modifies this as follows. If @p __value == 0, - * sets value to 19780503. In any case, with a linear - * congruential generator lcg(i) having parameters @f$ m_{lcg} = - * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value - * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m - * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$ - * set carry to 1, otherwise sets carry to 0. - */ - void - seed(unsigned long __value = 19780503); - - /** - * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry - * random number generator. - */ - template - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - /** - * Gets the inclusive minimum value of the range of random integers - * returned by this generator. - */ - result_type - min() const - { return 0; } - - /** - * Gets the inclusive maximum value of the range of random integers - * returned by this generator. - */ - result_type - max() const - { return this->modulus - 1; } - - /** - * Gets the next random number in the sequence. - */ - result_type - operator()(); - - /** - * Compares two % subtract_with_carry random number generator objects of - * the same type for equality. - * - * @param __lhs A % subtract_with_carry random number generator object. - * @param __rhs Another % subtract_with_carry random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const subtract_with_carry& __lhs, - const subtract_with_carry& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); } - - /** - * Compares two % subtract_with_carry random number generator objects of - * the same type for inequality. - * - * @param __lhs A % subtract_with_carry random number generator object. - * @param __rhs Another % subtract_with_carry random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const subtract_with_carry& __lhs, - const subtract_with_carry& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a % subtract_with_carry random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A % subtract_with_carry random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry<_IntType1, __m1, __s1, - __r1>& __x); - - /** - * Extracts the current state of a % subtract_with_carry random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A % subtract_with_carry random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x); - - private: - template - void - seed(_Gen& __g, true_type) - { return seed(static_cast(__g)); } - - template - void - seed(_Gen& __g, false_type); - - typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType; - - _UIntType _M_x[long_lag]; - _UIntType _M_carry; - int _M_p; - }; - - - /** - * @brief The Marsaglia-Zaman generator (floats version). - * - * @if maint - * @var _M_x The state of the generator. This is a ring buffer. - * @var _M_carry The carry. - * @var _M_p Current index of x(i - r). - * @var _M_npows Precomputed negative powers of 2. - * @endif - */ - template - class subtract_with_carry_01 - { - public: - /** The type of the generated random value. */ - typedef _RealType result_type; - - // parameter values - static const int word_size = __w; - static const int long_lag = __r; - static const int short_lag = __s; - - /** - * Constructs a default-initialized % subtract_with_carry_01 random - * number generator. - */ - subtract_with_carry_01() - { - this->seed(); - _M_initialize_npows(); - } - - /** - * Constructs an explicitly seeded % subtract_with_carry_01 random number - * generator. - */ - explicit - subtract_with_carry_01(unsigned long __value) - { - this->seed(__value); - _M_initialize_npows(); - } - - /** - * Constructs a % subtract_with_carry_01 random number generator engine - * seeded from the generator function @p __g. - * - * @param __g The seed generator function. - */ - template - subtract_with_carry_01(_Gen& __g) - { - this->seed(__g); - _M_initialize_npows(); - } - - /** - * Seeds the initial state @f$ x_0 @f$ of the random number generator. - */ - void - seed(unsigned long __value = 19780503); - - /** - * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry_01 - * random number generator. - */ - template - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - /** - * Gets the minimum value of the range of random floats - * returned by this generator. - */ - result_type - min() const - { return 0.0; } - - /** - * Gets the maximum value of the range of random floats - * returned by this generator. - */ - result_type - max() const - { return 1.0; } - - /** - * Gets the next random number in the sequence. - */ - result_type - operator()(); - - /** - * Compares two % subtract_with_carry_01 random number generator objects - * of the same type for equality. - * - * @param __lhs A % subtract_with_carry_01 random number - * generator object. - * @param __rhs Another % subtract_with_carry_01 random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const subtract_with_carry_01& __lhs, - const subtract_with_carry_01& __rhs) - { - for (int __i = 0; __i < long_lag; ++__i) - if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n, - __rhs._M_x[__i])) - return false; - return true; - } - - /** - * Compares two % subtract_with_carry_01 random number generator objects - * of the same type for inequality. - * - * @param __lhs A % subtract_with_carry_01 random number - * generator object. - * - * @param __rhs Another % subtract_with_carry_01 random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const subtract_with_carry_01& __lhs, - const subtract_with_carry_01& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a % subtract_with_carry_01 random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A % subtract_with_carry_01 random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry_01<_RealType1, __w1, __s1, - __r1>& __x); - - /** - * Extracts the current state of a % subtract_with_carry_01 random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A % subtract_with_carry_01 random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x); - - private: - template - void - seed(_Gen& __g, true_type) - { return seed(static_cast(__g)); } - - template - void - seed(_Gen& __g, false_type); - - void - _M_initialize_npows(); - - static const int __n = (__w + 31) / 32; - - typedef __detail::_UInt32Type _UInt32Type; - _UInt32Type _M_x[long_lag][__n]; - _RealType _M_npows[__n]; - _UInt32Type _M_carry; - int _M_p; - }; - - typedef subtract_with_carry_01 ranlux_base_01; - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 508. Bad parameters for ranlux64_base_01. - typedef subtract_with_carry_01 ranlux64_base_01; - - - /** - * Produces random numbers from some base engine by discarding blocks of - * data. - * - * 0 <= @p __r <= @p __p - */ - template - class discard_block - { - // __glibcxx_class_requires(typename base_type::result_type, - // ArithmeticTypeConcept) - - public: - /** The type of the underlying generator engine. */ - typedef _UniformRandomNumberGenerator base_type; - /** The type of the generated random value. */ - typedef typename base_type::result_type result_type; - - // parameter values - static const int block_size = __p; - static const int used_block = __r; - - /** - * Constructs a default %discard_block engine. - * - * The underlying engine is default constructed as well. - */ - discard_block() - : _M_n(0) { } - - /** - * Copy constructs a %discard_block engine. - * - * Copies an existing base class random number geenerator. - * @param rng An existing (base class) engine object. - */ - explicit - discard_block(const base_type& __rng) - : _M_b(__rng), _M_n(0) { } - - /** - * Seed constructs a %discard_block engine. - * - * Constructs the underlying generator engine seeded with @p __s. - * @param __s A seed value for the base class engine. - */ - explicit - discard_block(unsigned long __s) - : _M_b(__s), _M_n(0) { } - - /** - * Generator construct a %discard_block engine. - * - * @param __g A seed generator function. - */ - template - discard_block(_Gen& __g) - : _M_b(__g), _M_n(0) { } - - /** - * Reseeds the %discard_block object with the default seed for the - * underlying base class generator engine. - */ - void seed() - { - _M_b.seed(); - _M_n = 0; - } - - /** - * Reseeds the %discard_block object with the given seed generator - * function. - * @param __g A seed generator function. - */ - template - void seed(_Gen& __g) - { - _M_b.seed(__g); - _M_n = 0; - } - - /** - * Gets a const reference to the underlying generator engine object. - */ - const base_type& - base() const - { return _M_b; } - - /** - * Gets the minimum value in the generated random number range. - */ - result_type - min() const - { return _M_b.min(); } - - /** - * Gets the maximum value in the generated random number range. - */ - result_type - max() const - { return _M_b.max(); } - - /** - * Gets the next value in the generated random number sequence. - */ - result_type - operator()(); - - /** - * Compares two %discard_block random number generator objects of - * the same type for equality. - * - * @param __lhs A %discard_block random number generator object. - * @param __rhs Another %discard_block random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const discard_block& __lhs, const discard_block& __rhs) - { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); } - - /** - * Compares two %discard_block random number generator objects of - * the same type for inequality. - * - * @param __lhs A %discard_block random number generator object. - * @param __rhs Another %discard_block random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const discard_block& __lhs, const discard_block& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a %discard_block random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %discard_block random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const discard_block<_UniformRandomNumberGenerator1, - __p1, __r1>& __x); - - /** - * Extracts the current state of a % subtract_with_carry random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %discard_block random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - discard_block<_UniformRandomNumberGenerator1, - __p1, __r1>& __x); - - private: - base_type _M_b; - int _M_n; - }; - - - /** - * James's luxury-level-3 integer adaptation of Luescher's generator. - */ - typedef discard_block< - subtract_with_carry, - 223, - 24 - > ranlux3; - - /** - * James's luxury-level-4 integer adaptation of Luescher's generator. - */ - typedef discard_block< - subtract_with_carry, - 389, - 24 - > ranlux4; - - typedef discard_block< - subtract_with_carry_01, - 223, - 24 - > ranlux3_01; - - typedef discard_block< - subtract_with_carry_01, - 389, - 24 - > ranlux4_01; - - - /** - * A random number generator adaptor class that combines two random number - * generator engines into a single output sequence. - */ - template - class xor_combine - { - // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1:: - // result_type, ArithmeticTypeConcept) - // __glibcxx_class_requires(typename _UniformRandomNumberGenerator2:: - // result_type, ArithmeticTypeConcept) - - public: - /** The type of the the first underlying generator engine. */ - typedef _UniformRandomNumberGenerator1 base1_type; - /** The type of the the second underlying generator engine. */ - typedef _UniformRandomNumberGenerator2 base2_type; - - private: - typedef typename base1_type::result_type _Result_type1; - typedef typename base2_type::result_type _Result_type2; - - public: - /** The type of the generated random value. */ - typedef typename __gnu_cxx::__conditional_type<(sizeof(_Result_type1) - > sizeof(_Result_type2)), - _Result_type1, _Result_type2>::__type result_type; - - // parameter values - static const int shift1 = __s1; - static const int shift2 = __s2; - - // constructors and member function - xor_combine() - : _M_b1(), _M_b2() - { _M_initialize_max(); } - - xor_combine(const base1_type& __rng1, const base2_type& __rng2) - : _M_b1(__rng1), _M_b2(__rng2) - { _M_initialize_max(); } - - xor_combine(unsigned long __s) - : _M_b1(__s), _M_b2(__s + 1) - { _M_initialize_max(); } - - template - xor_combine(_Gen& __g) - : _M_b1(__g), _M_b2(__g) - { _M_initialize_max(); } - - void - seed() - { - _M_b1.seed(); - _M_b2.seed(); - } - - template - void - seed(_Gen& __g) - { - _M_b1.seed(__g); - _M_b2.seed(__g); - } - - const base1_type& - base1() const - { return _M_b1; } - - const base2_type& - base2() const - { return _M_b2; } - - result_type - min() const - { return 0; } - - result_type - max() const - { return _M_max; } - - /** - * Gets the next random number in the sequence. - */ - // NB: Not exactly the TR1 formula, per N2079 instead. - result_type - operator()() - { - return ((result_type(_M_b1() - _M_b1.min()) << shift1) - ^ (result_type(_M_b2() - _M_b2.min()) << shift2)); - } - - /** - * Compares two %xor_combine random number generator objects of - * the same type for equality. - * - * @param __lhs A %xor_combine random number generator object. - * @param __rhs Another %xor_combine random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const xor_combine& __lhs, const xor_combine& __rhs) - { - return (__lhs.base1() == __rhs.base1()) - && (__lhs.base2() == __rhs.base2()); - } - - /** - * Compares two %xor_combine random number generator objects of - * the same type for inequality. - * - * @param __lhs A %xor_combine random number generator object. - * @param __rhs Another %xor_combine random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const xor_combine& __lhs, const xor_combine& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a %xor_combine random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %xor_combine random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const xor_combine<_UniformRandomNumberGenerator11, __s11, - _UniformRandomNumberGenerator21, __s21>& __x); - - /** - * Extracts the current state of a %xor_combine random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %xor_combine random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - xor_combine<_UniformRandomNumberGenerator11, __s11, - _UniformRandomNumberGenerator21, __s21>& __x); - - private: - void - _M_initialize_max(); - - result_type - _M_initialize_max_aux(result_type, result_type, int); - - base1_type _M_b1; - base2_type _M_b2; - result_type _M_max; - }; - - - /** - * A standard interface to a platform-specific non-deterministic - * random number generator (if any are available). - */ - class random_device - { - public: - // types - typedef unsigned int result_type; - - // constructors, destructors and member functions - -#ifdef _GLIBCXX_USE_RANDOM_TR1 - - explicit - random_device(const std::string& __token = "/dev/urandom") - { - if ((__token != "/dev/urandom" && __token != "/dev/random") - || !(_M_file = std::fopen(__token.c_str(), "rb"))) - std::__throw_runtime_error(__N("random_device::" - "random_device(const std::string&)")); - } - - ~random_device() - { std::fclose(_M_file); } - -#else - - explicit - random_device(const std::string& __token = "mt19937") - : _M_mt(_M_strtoul(__token)) { } - - private: - static unsigned long - _M_strtoul(const std::string& __str) - { - unsigned long __ret = 5489UL; - if (__str != "mt19937") - { - const char* __nptr = __str.c_str(); - char* __endptr; - __ret = std::strtoul(__nptr, &__endptr, 0); - if (*__nptr == '\0' || *__endptr != '\0') - std::__throw_runtime_error(__N("random_device::_M_strtoul" - "(const std::string&)")); - } - return __ret; - } - - public: - -#endif - - result_type - min() const - { return std::numeric_limits::min(); } - - result_type - max() const - { return std::numeric_limits::max(); } - - double - entropy() const - { return 0.0; } - - result_type - operator()() - { -#ifdef _GLIBCXX_USE_RANDOM_TR1 - result_type __ret; - std::fread(reinterpret_cast(&__ret), sizeof(result_type), - 1, _M_file); - return __ret; -#else - return _M_mt(); -#endif - } - - private: - random_device(const random_device&); - void operator=(const random_device&); - -#ifdef _GLIBCXX_USE_RANDOM_TR1 - FILE* _M_file; +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include #else - mt19937 _M_mt; +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif - }; - - /* @} */ // group tr1_random_generators - - /** - * @addtogroup tr1_random_distributions Random Number Distributions - * @ingroup tr1_random - * @{ - */ - - /** - * @addtogroup tr1_random_distributions_discrete Discrete Distributions - * @ingroup tr1_random_distributions - * @{ - */ - - /** - * @brief Uniform discrete distribution for random numbers. - * A discrete random distribution on the range @f$[min, max]@f$ with equal - * probability throughout the range. - */ - template - class uniform_int - { - __glibcxx_class_requires(_IntType, _IntegerConcept) - - public: - /** The type of the parameters of the distribution. */ - typedef _IntType input_type; - /** The type of the range of the distribution. */ - typedef _IntType result_type; - - public: - /** - * Constructs a uniform distribution object. - */ - explicit - uniform_int(_IntType __min = 0, _IntType __max = 9) - : _M_min(__min), _M_max(__max) - { - _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); - } - - /** - * Gets the inclusive lower bound of the distribution range. - */ - result_type - min() const - { return _M_min; } - - /** - * Gets the inclusive upper bound of the distribution range. - */ - result_type - max() const - { return _M_max; } - - /** - * Resets the distribution state. - * - * Does nothing for the uniform integer distribution. - */ - void - reset() { } - - /** - * Gets a uniformly distributed random number in the range - * @f$(min, max)@f$. - */ - template - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { - typedef typename _UniformRandomNumberGenerator::result_type - _UResult_type; - return _M_call(__urng, _M_min, _M_max, - typename is_integral<_UResult_type>::type()); - } - - /** - * Gets a uniform random number in the range @f$[0, n)@f$. - * - * This function is aimed at use with std::random_shuffle. - */ - template - result_type - operator()(_UniformRandomNumberGenerator& __urng, result_type __n) - { - typedef typename _UniformRandomNumberGenerator::result_type - _UResult_type; - return _M_call(__urng, 0, __n - 1, - typename is_integral<_UResult_type>::type()); - } - - /** - * Inserts a %uniform_int random number distribution @p __x into the - * output stream @p os. - * - * @param __os An output stream. - * @param __x A %uniform_int random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_int<_IntType1>& __x); - - /** - * Extracts a %unform_int random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %uniform_int random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_int<_IntType1>& __x); - - private: - template - result_type - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, true_type) - { return result_type(__urng() % (__max - __min + 1)) + __min; } - - template - result_type - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, false_type) - { - return result_type((__urng() - __urng.min()) - / (__urng.max() - __urng.min()) - * (__max - __min + 1)) + __min; - } - - _IntType _M_min; - _IntType _M_max; - }; - - - /** - * @brief A Bernoulli random number distribution. - * - * Generates a sequence of true and false values with likelihood @f$ p @f$ - * that true will come up and @f$ (1 - p) @f$ that false will appear. - */ - class bernoulli_distribution - { - public: - typedef int input_type; - typedef bool result_type; - - public: - /** - * Constructs a Bernoulli distribution with likelihood @p p. - * - * @param __p [IN] The likelihood of a true result being returned. Must - * be in the interval @f$ [0, 1] @f$. - */ - explicit - bernoulli_distribution(double __p = 0.5) - : _M_p(__p) - { - _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0)); - } - - /** - * Gets the @p p parameter of the distribution. - */ - double - p() const - { return _M_p; } - - /** - * Resets the distribution state. - * - * Does nothing for a bernoulli distribution. - */ - void - reset() { } - - /** - * Gets the next value in the Bernoullian sequence. - */ - template - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { - if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min())) - return true; - return false; - } - - /** - * Inserts a %bernoulli_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %bernoulli_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const bernoulli_distribution& __x); - - /** - * Extracts a %bernoulli_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %bernoulli_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - bernoulli_distribution& __x) - { return __is >> __x._M_p; } - - private: - double _M_p; - }; - - - /** - * @brief A discrete geometric random number distribution. - * - * The formula for the geometric probability mass function is - * @f$ p(i) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the - * distribution. - */ - template - class geometric_distribution - { - public: - // types - typedef _RealType input_type; - typedef _IntType result_type; - - // constructors and member function - explicit - geometric_distribution(const _RealType& __p = _RealType(0.5)) - : _M_p(__p) - { - _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0)); - _M_initialize(); - } - - /** - * Gets the distribution parameter @p p. - */ - _RealType - p() const - { return _M_p; } - - void - reset() { } - - template - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %geometric_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %geometric_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const geometric_distribution<_IntType1, _RealType1>& __x); - - /** - * Extracts a %geometric_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %geometric_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - geometric_distribution& __x) - { - __is >> __x._M_p; - __x._M_initialize(); - return __is; - } - - private: - void - _M_initialize() - { _M_log_p = std::log(_M_p); } - - _RealType _M_p; - _RealType _M_log_p; - }; - - - template - class normal_distribution; - - /** - * @brief A discrete Poisson random number distribution. - * - * The formula for the poisson probability mass function is - * @f$ p(i) = \frac{mean^i}{i!} e^{-mean} @f$ where @f$ mean @f$ is the - * parameter of the distribution. - */ - template - class poisson_distribution - { - public: - // types - typedef _RealType input_type; - typedef _IntType result_type; - - // constructors and member function - explicit - poisson_distribution(const _RealType& __mean = _RealType(1)) - : _M_mean(__mean), _M_nd() - { - _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0); - _M_initialize(); - } - - /** - * Gets the distribution parameter @p mean. - */ - _RealType - mean() const - { return _M_mean; } - - void - reset() - { _M_nd.reset(); } - - template - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %poisson_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %poisson_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const poisson_distribution<_IntType1, _RealType1>& __x); - - /** - * Extracts a %poisson_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %poisson_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - poisson_distribution<_IntType1, _RealType1>& __x); - - private: - void - _M_initialize(); - - // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. - normal_distribution<_RealType> _M_nd; - - _RealType _M_mean; - - // Hosts either log(mean) or the threshold of the simple method. - _RealType _M_lm_thr; -#if _GLIBCXX_USE_C99_MATH_TR1 - _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb; -#endif - }; - - - /** - * @brief A discrete binomial random number distribution. - * - * The formula for the binomial probability mass function is - * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$ - * and @f$ p @f$ are the parameters of the distribution. - */ - template - class binomial_distribution - { - public: - // types - typedef _RealType input_type; - typedef _IntType result_type; - - // constructors and member function - explicit - binomial_distribution(_IntType __t = 1, - const _RealType& __p = _RealType(0.5)) - : _M_t(__t), _M_p(__p), _M_nd() - { - _GLIBCXX_DEBUG_ASSERT((_M_t >= 0) && (_M_p >= 0.0) && (_M_p <= 1.0)); - _M_initialize(); - } - - /** - * Gets the distribution @p t parameter. - */ - _IntType - t() const - { return _M_t; } - - /** - * Gets the distribution @p p parameter. - */ - _RealType - p() const - { return _M_p; } - - void - reset() - { _M_nd.reset(); } - - template - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %binomial_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %binomial_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const binomial_distribution<_IntType1, _RealType1>& __x); - - /** - * Extracts a %binomial_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %binomial_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - binomial_distribution<_IntType1, _RealType1>& __x); - - private: - void - _M_initialize(); - - template - result_type - _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t); - - // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. - normal_distribution<_RealType> _M_nd; - - _RealType _M_q; -#if _GLIBCXX_USE_C99_MATH_TR1 - _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c, - _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p; -#endif - _RealType _M_p; - _IntType _M_t; - - bool _M_easy; - }; - - /* @} */ // group tr1_random_distributions_discrete - - /** - * @addtogroup tr1_random_distributions_continuous Continuous Distributions - * @ingroup tr1_random_distributions - * @{ - */ - - /** - * @brief Uniform continuous distribution for random numbers. - * - * A continuous random distribution on the range [min, max) with equal - * probability throughout the range. The URNG should be real-valued and - * deliver number in the range [0, 1). - */ - template - class uniform_real - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs a uniform_real object. - * - * @param __min [IN] The lower bound of the distribution. - * @param __max [IN] The upper bound of the distribution. - */ - explicit - uniform_real(_RealType __min = _RealType(0), - _RealType __max = _RealType(1)) - : _M_min(__min), _M_max(__max) - { - _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); - } - - result_type - min() const - { return _M_min; } - - result_type - max() const - { return _M_max; } - - void - reset() { } - - template - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { return (__urng() * (_M_max - _M_min)) + _M_min; } - - /** - * Inserts a %uniform_real random number distribution @p __x into the - * output stream @p __os. - * - * @param __os An output stream. - * @param __x A %uniform_real random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_real<_RealType1>& __x); - - /** - * Extracts a %unform_real random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %uniform_real random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_real<_RealType1>& __x); - - private: - _RealType _M_min; - _RealType _M_max; - }; - - - /** - * @brief An exponential continuous distribution for random numbers. - * - * The formula for the exponential probability mass function is - * @f$ p(x) = \lambda e^{-\lambda x} @f$. - * - * - * - * - * - * - * - * - *
Distribution Statistics
Mean@f$ \frac{1}{\lambda} @f$
Median@f$ \frac{\ln 2}{\lambda} @f$
Mode@f$ zero @f$
Range@f$[0, \infty]@f$
Standard Deviation@f$ \frac{1}{\lambda} @f$
- */ - template - class exponential_distribution - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs an exponential distribution with inverse scale parameter - * @f$ \lambda @f$. - */ - explicit - exponential_distribution(const result_type& __lambda = result_type(1)) - : _M_lambda(__lambda) - { - _GLIBCXX_DEBUG_ASSERT(_M_lambda > 0); - } - - /** - * Gets the inverse scale parameter of the distribution. - */ - _RealType - lambda() const - { return _M_lambda; } - - /** - * Resets the distribution. - * - * Has no effect on exponential distributions. - */ - void - reset() { } - - template - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { return -std::log(__urng()) / _M_lambda; } - - /** - * Inserts a %exponential_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %exponential_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const exponential_distribution<_RealType1>& __x); - - /** - * Extracts a %exponential_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %exponential_distribution random number - * generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - exponential_distribution& __x) - { return __is >> __x._M_lambda; } - - private: - result_type _M_lambda; - }; - - - /** - * @brief A normal continuous distribution for random numbers. - * - * The formula for the normal probability mass function is - * @f$ p(x) = \frac{1}{\sigma \sqrt{2 \pi}} - * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$. - */ - template - class normal_distribution - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs a normal distribution with parameters @f$ mean @f$ and - * @f$ \sigma @f$. - */ - explicit - normal_distribution(const result_type& __mean = result_type(0), - const result_type& __sigma = result_type(1)) - : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(false) - { - _GLIBCXX_DEBUG_ASSERT(_M_sigma > 0); - } - - /** - * Gets the mean of the distribution. - */ - _RealType - mean() const - { return _M_mean; } - - /** - * Gets the @f$ \sigma @f$ of the distribution. - */ - _RealType - sigma() const - { return _M_sigma; } - - /** - * Resets the distribution. - */ - void - reset() - { _M_saved_available = false; } - - template - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %normal_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %normal_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const normal_distribution<_RealType1>& __x); - - /** - * Extracts a %normal_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %normal_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - normal_distribution<_RealType1>& __x); - - private: - result_type _M_mean; - result_type _M_sigma; - result_type _M_saved; - bool _M_saved_available; - }; - - - /** - * @brief A gamma continuous distribution for random numbers. - * - * The formula for the gamma probability mass function is - * @f$ p(x) = \frac{1}{\Gamma(\alpha)} x^{\alpha - 1} e^{-x} @f$. - */ - template - class gamma_distribution - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs a gamma distribution with parameters @f$ \alpha @f$. - */ - explicit - gamma_distribution(const result_type& __alpha_val = result_type(1)) - : _M_alpha(__alpha_val) - { - _GLIBCXX_DEBUG_ASSERT(_M_alpha > 0); - _M_initialize(); - } - - /** - * Gets the @f$ \alpha @f$ of the distribution. - */ - _RealType - alpha() const - { return _M_alpha; } - - /** - * Resets the distribution. - */ - void - reset() { } - - template - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %gamma_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %gamma_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const gamma_distribution<_RealType1>& __x); - - /** - * Extracts a %gamma_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %gamma_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - gamma_distribution& __x) - { - __is >> __x._M_alpha; - __x._M_initialize(); - return __is; - } - - private: - void - _M_initialize(); - - result_type _M_alpha; - - // Hosts either lambda of GB or d of modified Vaduva's. - result_type _M_l_d; - }; - - /* @} */ // group tr1_random_distributions_continuous - /* @} */ // group tr1_random_distributions - /* @} */ // group tr1_random - -_GLIBCXX_END_NAMESPACE -} - -#include -#endif // _TR1_RANDOM +#endif // _GLIBCXX_TR1_RANDOM diff --git a/libstdc++-v3/include/tr1/random.tcc b/libstdc++-v3/include/tr1/random.tcc deleted file mode 100644 index c5ae933..0000000 --- a/libstdc++-v3/include/tr1/random.tcc +++ /dev/null @@ -1,1547 +0,0 @@ -// random number generation (out of line) -*- C++ -*- - -// Copyright (C) 2006, 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/** @file tr1/random.tcc - * This is a TR1 C++ Library header. - */ - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - /* - * (Further) implementation-space details. - */ - namespace __detail - { - // General case for x = (ax + c) mod m -- use Schrage's algorithm to avoid - // integer overflow. - // - // Because a and c are compile-time integral constants the compiler kindly - // elides any unreachable paths. - // - // Preconditions: a > 0, m > 0. - // - template - struct _Mod - { - static _Tp - __calc(_Tp __x) - { - if (__a == 1) - __x %= __m; - else - { - static const _Tp __q = __m / __a; - static const _Tp __r = __m % __a; - - _Tp __t1 = __a * (__x % __q); - _Tp __t2 = __r * (__x / __q); - if (__t1 >= __t2) - __x = __t1 - __t2; - else - __x = __m - __t2 + __t1; - } - - if (__c != 0) - { - const _Tp __d = __m - __x; - if (__d > __c) - __x += __c; - else - __x = __c - __d; - } - return __x; - } - }; - - // Special case for m == 0 -- use unsigned integer overflow as modulo - // operator. - template - struct _Mod<_Tp, __a, __c, __m, true> - { - static _Tp - __calc(_Tp __x) - { return __a * __x + __c; } - }; - } // namespace __detail - - /** - * Seeds the LCR with integral value @p __x0, adjusted so that the - * ring identity is never a member of the convergence set. - */ - template - void - linear_congruential<_UIntType, __a, __c, __m>:: - seed(unsigned long __x0) - { - if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) - && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); - else - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); - } - - /** - * Seeds the LCR engine with a value generated by @p __g. - */ - template - template - void - linear_congruential<_UIntType, __a, __c, __m>:: - seed(_Gen& __g, false_type) - { - _UIntType __x0 = __g(); - if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) - && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); - else - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); - } - - /** - * Gets the next generated value in sequence. - */ - template - typename linear_congruential<_UIntType, __a, __c, __m>::result_type - linear_congruential<_UIntType, __a, __c, __m>:: - operator()() - { - _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x); - return _M_x; - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const linear_congruential<_UIntType, __a, __c, __m>& __lcr) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); - __os.fill(__os.widen(' ')); - - __os << __lcr._M_x; - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - linear_congruential<_UIntType, __a, __c, __m>& __lcr) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec); - - __is >> __lcr._M_x; - - __is.flags(__flags); - return __is; - } - - - template - void - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>:: - seed(unsigned long __value) - { - _M_x[0] = __detail::__mod<_UIntType, 1, 0, - __detail::_Shift<_UIntType, __w>::__value>(__value); - - for (int __i = 1; __i < state_size; ++__i) - { - _UIntType __x = _M_x[__i - 1]; - __x ^= __x >> (__w - 2); - __x *= 1812433253ul; - __x += __i; - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, - __detail::_Shift<_UIntType, __w>::__value>(__x); - } - _M_p = state_size; - } - - template - template - void - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>:: - seed(_Gen& __gen, false_type) - { - for (int __i = 0; __i < state_size; ++__i) - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, - __detail::_Shift<_UIntType, __w>::__value>(__gen()); - _M_p = state_size; - } - - template - typename - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>::result_type - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>:: - operator()() - { - // Reload the vector - cost is O(n) amortized over n calls. - if (_M_p >= state_size) - { - const _UIntType __upper_mask = (~_UIntType()) << __r; - const _UIntType __lower_mask = ~__upper_mask; - - for (int __k = 0; __k < (__n - __m); ++__k) - { - _UIntType __y = ((_M_x[__k] & __upper_mask) - | (_M_x[__k + 1] & __lower_mask)); - _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1) - ^ ((__y & 0x01) ? __a : 0)); - } - - for (int __k = (__n - __m); __k < (__n - 1); ++__k) - { - _UIntType __y = ((_M_x[__k] & __upper_mask) - | (_M_x[__k + 1] & __lower_mask)); - _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1) - ^ ((__y & 0x01) ? __a : 0)); - } - - _UIntType __y = ((_M_x[__n - 1] & __upper_mask) - | (_M_x[0] & __lower_mask)); - _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1) - ^ ((__y & 0x01) ? __a : 0)); - _M_p = 0; - } - - // Calculate o(x(i)). - result_type __z = _M_x[_M_p++]; - __z ^= (__z >> __u); - __z ^= (__z << __s) & __b; - __z ^= (__z << __t) & __c; - __z ^= (__z >> __l); - - return __z; - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const mersenne_twister<_UIntType, __w, __n, __m, - __r, __a, __u, __s, __b, __t, __c, __l>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); - __os.fill(__space); - - for (int __i = 0; __i < __n - 1; ++__i) - __os << __x._M_x[__i] << __space; - __os << __x._M_x[__n - 1]; - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - mersenne_twister<_UIntType, __w, __n, __m, - __r, __a, __u, __s, __b, __t, __c, __l>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - for (int __i = 0; __i < __n; ++__i) - __is >> __x._M_x[__i]; - - __is.flags(__flags); - return __is; - } - - - template - void - subtract_with_carry<_IntType, __m, __s, __r>:: - seed(unsigned long __value) - { - if (__value == 0) - __value = 19780503; - - std::_GLIBCXX_TR1::linear_congruential - __lcg(__value); - - for (int __i = 0; __i < long_lag; ++__i) - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__lcg()); - - _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; - _M_p = 0; - } - - template - template - void - subtract_with_carry<_IntType, __m, __s, __r>:: - seed(_Gen& __gen, false_type) - { - const int __n = (std::numeric_limits<_UIntType>::digits + 31) / 32; - - for (int __i = 0; __i < long_lag; ++__i) - { - _UIntType __tmp = 0; - _UIntType __factor = 1; - for (int __j = 0; __j < __n; ++__j) - { - __tmp += __detail::__mod<__detail::_UInt32Type, 1, 0, 0> - (__gen()) * __factor; - __factor *= __detail::_Shift<_UIntType, 32>::__value; - } - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__tmp); - } - _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; - _M_p = 0; - } - - template - typename subtract_with_carry<_IntType, __m, __s, __r>::result_type - subtract_with_carry<_IntType, __m, __s, __r>:: - operator()() - { - // Derive short lag index from current index. - int __ps = _M_p - short_lag; - if (__ps < 0) - __ps += long_lag; - - // Calculate new x(i) without overflow or division. - // NB: Thanks to the requirements for _IntType, _M_x[_M_p] + _M_carry - // cannot overflow. - _UIntType __xi; - if (_M_x[__ps] >= _M_x[_M_p] + _M_carry) - { - __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry; - _M_carry = 0; - } - else - { - __xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps]; - _M_carry = 1; - } - _M_x[_M_p] = __xi; - - // Adjust current index to loop around in ring buffer. - if (++_M_p >= long_lag) - _M_p = 0; - - return __xi; - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry<_IntType, __m, __s, __r>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); - __os.fill(__space); - - for (int __i = 0; __i < __r; ++__i) - __os << __x._M_x[__i] << __space; - __os << __x._M_carry; - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry<_IntType, __m, __s, __r>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - for (int __i = 0; __i < __r; ++__i) - __is >> __x._M_x[__i]; - __is >> __x._M_carry; - - __is.flags(__flags); - return __is; - } - - - template - void - subtract_with_carry_01<_RealType, __w, __s, __r>:: - _M_initialize_npows() - { - for (int __j = 0; __j < __n; ++__j) -#if _GLIBCXX_USE_C99_MATH_TR1 - _M_npows[__j] = std::_GLIBCXX_TR1::ldexp(_RealType(1), -__w + __j * 32); -#else - _M_npows[__j] = std::pow(_RealType(2), -__w + __j * 32); -#endif - } - - template - void - subtract_with_carry_01<_RealType, __w, __s, __r>:: - seed(unsigned long __value) - { - if (__value == 0) - __value = 19780503; - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 512. Seeding subtract_with_carry_01 from a single unsigned long. - std::_GLIBCXX_TR1::linear_congruential - __lcg(__value); - - this->seed(__lcg); - } - - template - template - void - subtract_with_carry_01<_RealType, __w, __s, __r>:: - seed(_Gen& __gen, false_type) - { - for (int __i = 0; __i < long_lag; ++__i) - { - for (int __j = 0; __j < __n - 1; ++__j) - _M_x[__i][__j] = __detail::__mod<_UInt32Type, 1, 0, 0>(__gen()); - _M_x[__i][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, - __detail::_Shift<_UInt32Type, __w % 32>::__value>(__gen()); - } - - _M_carry = 1; - for (int __j = 0; __j < __n; ++__j) - if (_M_x[long_lag - 1][__j] != 0) - { - _M_carry = 0; - break; - } - - _M_p = 0; - } - - template - typename subtract_with_carry_01<_RealType, __w, __s, __r>::result_type - subtract_with_carry_01<_RealType, __w, __s, __r>:: - operator()() - { - // Derive short lag index from current index. - int __ps = _M_p - short_lag; - if (__ps < 0) - __ps += long_lag; - - _UInt32Type __new_carry; - for (int __j = 0; __j < __n - 1; ++__j) - { - if (_M_x[__ps][__j] > _M_x[_M_p][__j] - || (_M_x[__ps][__j] == _M_x[_M_p][__j] && _M_carry == 0)) - __new_carry = 0; - else - __new_carry = 1; - - _M_x[_M_p][__j] = _M_x[__ps][__j] - _M_x[_M_p][__j] - _M_carry; - _M_carry = __new_carry; - } - - if (_M_x[__ps][__n - 1] > _M_x[_M_p][__n - 1] - || (_M_x[__ps][__n - 1] == _M_x[_M_p][__n - 1] && _M_carry == 0)) - __new_carry = 0; - else - __new_carry = 1; - - _M_x[_M_p][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, - __detail::_Shift<_UInt32Type, __w % 32>::__value> - (_M_x[__ps][__n - 1] - _M_x[_M_p][__n - 1] - _M_carry); - _M_carry = __new_carry; - - result_type __ret = 0.0; - for (int __j = 0; __j < __n; ++__j) - __ret += _M_x[_M_p][__j] * _M_npows[__j]; - - // Adjust current index to loop around in ring buffer. - if (++_M_p >= long_lag) - _M_p = 0; - - return __ret; - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry_01<_RealType, __w, __s, __r>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); - __os.fill(__space); - - for (int __i = 0; __i < __r; ++__i) - for (int __j = 0; __j < __x.__n; ++__j) - __os << __x._M_x[__i][__j] << __space; - __os << __x._M_carry; - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry_01<_RealType, __w, __s, __r>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - for (int __i = 0; __i < __r; ++__i) - for (int __j = 0; __j < __x.__n; ++__j) - __is >> __x._M_x[__i][__j]; - __is >> __x._M_carry; - - __is.flags(__flags); - return __is; - } - - - template - typename discard_block<_UniformRandomNumberGenerator, - __p, __r>::result_type - discard_block<_UniformRandomNumberGenerator, __p, __r>:: - operator()() - { - if (_M_n >= used_block) - { - while (_M_n < block_size) - { - _M_b(); - ++_M_n; - } - _M_n = 0; - } - ++_M_n; - return _M_b(); - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const discard_block<_UniformRandomNumberGenerator, - __p, __r>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed - | __ios_base::left); - __os.fill(__space); - - __os << __x._M_b << __space << __x._M_n; - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - discard_block<_UniformRandomNumberGenerator, __p, __r>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - __is >> __x._M_b >> __x._M_n; - - __is.flags(__flags); - return __is; - } - - - template - void - xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>:: - _M_initialize_max() - { - const int __w = std::numeric_limits::digits; - - const result_type __m1 = - std::min(result_type(_M_b1.max() - _M_b1.min()), - __detail::_Shift::__value - 1); - - const result_type __m2 = - std::min(result_type(_M_b2.max() - _M_b2.min()), - __detail::_Shift::__value - 1); - - // NB: In TR1 s1 is not required to be >= s2. - if (__s1 < __s2) - _M_max = _M_initialize_max_aux(__m2, __m1, __s2 - __s1) << __s1; - else - _M_max = _M_initialize_max_aux(__m1, __m2, __s1 - __s2) << __s2; - } - - template - typename xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>::result_type - xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>:: - _M_initialize_max_aux(result_type __a, result_type __b, int __d) - { - const result_type __two2d = result_type(1) << __d; - const result_type __c = __a * __two2d; - - if (__a == 0 || __b < __two2d) - return __c + __b; - - const result_type __t = std::max(__c, __b); - const result_type __u = std::min(__c, __b); - - result_type __ub = __u; - result_type __p; - for (__p = 0; __ub != 1; __ub >>= 1) - ++__p; - - const result_type __two2p = result_type(1) << __p; - const result_type __k = __t / __two2p; - - if (__k & 1) - return (__k + 1) * __two2p - 1; - - if (__c >= __b) - return (__k + 1) * __two2p + _M_initialize_max_aux((__t % __two2p) - / __two2d, - __u % __two2p, __d); - else - return (__k + 1) * __two2p + _M_initialize_max_aux((__u % __two2p) - / __two2d, - __t % __two2p, __d); - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); - __os.fill(__space); - - __os << __x.base1() << __space << __x.base2(); - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::skipws); - - __is >> __x._M_b1 >> __x._M_b2; - - __is.flags(__flags); - return __is; - } - - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_int<_IntType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - - __os << __x.min() << __space << __x.max(); - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_int<_IntType>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - __is >> __x._M_min >> __x._M_max; - - __is.flags(__flags); - return __is; - } - - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const bernoulli_distribution& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits::__max_digits10); - - __os << __x.p(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - - template - template - typename geometric_distribution<_IntType, _RealType>::result_type - geometric_distribution<_IntType, _RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - // About the epsilon thing see this thread: - // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html - const _RealType __naf = - (1 - std::numeric_limits<_RealType>::epsilon()) / 2; - // The largest _RealType convertible to _IntType. - const _RealType __thr = - std::numeric_limits<_IntType>::max() + __naf; - - _RealType __cand; - do - __cand = std::ceil(std::log(__urng()) / _M_log_p); - while (__cand >= __thr); - - return result_type(__cand + __naf); - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const geometric_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.p(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - - template - void - poisson_distribution<_IntType, _RealType>:: - _M_initialize() - { -#if _GLIBCXX_USE_C99_MATH_TR1 - if (_M_mean >= 12) - { - const _RealType __m = std::floor(_M_mean); - _M_lm_thr = std::log(_M_mean); - _M_lfm = std::_GLIBCXX_TR1::lgamma(__m + 1); - _M_sm = std::sqrt(__m); - - const _RealType __pi_4 = 0.7853981633974483096156608458198757L; - const _RealType __dx = std::sqrt(2 * __m * std::log(32 * __m - / __pi_4)); - _M_d = std::_GLIBCXX_TR1::round(std::max(_RealType(6), - std::min(__m, __dx))); - const _RealType __cx = 2 * __m + _M_d; - _M_scx = std::sqrt(__cx / 2); - _M_1cx = 1 / __cx; - - _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx); - _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2)) / _M_d; - } - else -#endif - _M_lm_thr = std::exp(-_M_mean); - } - - /** - * A rejection algorithm when mean >= 12 and a simple method based - * upon the multiplication of uniform random variates otherwise. - * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 - * is defined. - * - * Reference: - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!). - */ - template - template - typename poisson_distribution<_IntType, _RealType>::result_type - poisson_distribution<_IntType, _RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { -#if _GLIBCXX_USE_C99_MATH_TR1 - if (_M_mean >= 12) - { - _RealType __x; - - // See comments above... - const _RealType __naf = - (1 - std::numeric_limits<_RealType>::epsilon()) / 2; - const _RealType __thr = - std::numeric_limits<_IntType>::max() + __naf; - - const _RealType __m = std::floor(_M_mean); - // sqrt(pi / 2) - const _RealType __spi_2 = 1.2533141373155002512078826424055226L; - const _RealType __c1 = _M_sm * __spi_2; - const _RealType __c2 = _M_c2b + __c1; - const _RealType __c3 = __c2 + 1; - const _RealType __c4 = __c3 + 1; - // e^(1 / 78) - const _RealType __e178 = 1.0129030479320018583185514777512983L; - const _RealType __c5 = __c4 + __e178; - const _RealType __c = _M_cb + __c5; - const _RealType __2cx = 2 * (2 * __m + _M_d); - - bool __reject = true; - do - { - const _RealType __u = __c * __urng(); - const _RealType __e = -std::log(__urng()); - - _RealType __w = 0.0; - - if (__u <= __c1) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = -std::abs(__n) * _M_sm - 1; - __x = std::floor(__y); - __w = -__n * __n / 2; - if (__x < -__m) - continue; - } - else if (__u <= __c2) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = 1 + std::abs(__n) * _M_scx; - __x = std::ceil(__y); - __w = __y * (2 - __y) * _M_1cx; - if (__x > _M_d) - continue; - } - else if (__u <= __c3) - // NB: This case not in the book, nor in the Errata, - // but should be ok... - __x = -1; - else if (__u <= __c4) - __x = 0; - else if (__u <= __c5) - __x = 1; - else - { - const _RealType __v = -std::log(__urng()); - const _RealType __y = _M_d + __v * __2cx / _M_d; - __x = std::ceil(__y); - __w = -_M_d * _M_1cx * (1 + __y / 2); - } - - __reject = (__w - __e - __x * _M_lm_thr - > _M_lfm - std::_GLIBCXX_TR1::lgamma(__x + __m + 1)); - - __reject |= __x + __m >= __thr; - - } while (__reject); - - return result_type(__x + __m + __naf); - } - else -#endif - { - _IntType __x = 0; - _RealType __prod = 1.0; - - do - { - __prod *= __urng(); - __x += 1; - } - while (__prod > _M_lm_thr); - - return __x - 1; - } - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const poisson_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.mean() << __space << __x._M_nd; - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - poisson_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::skipws); - - __is >> __x._M_mean >> __x._M_nd; - __x._M_initialize(); - - __is.flags(__flags); - return __is; - } - - - template - void - binomial_distribution<_IntType, _RealType>:: - _M_initialize() - { - const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; - - _M_easy = true; - -#if _GLIBCXX_USE_C99_MATH_TR1 - if (_M_t * __p12 >= 8) - { - _M_easy = false; - const _RealType __np = std::floor(_M_t * __p12); - const _RealType __pa = __np / _M_t; - const _RealType __1p = 1 - __pa; - - const _RealType __pi_4 = 0.7853981633974483096156608458198757L; - const _RealType __d1x = - std::sqrt(__np * __1p * std::log(32 * __np - / (81 * __pi_4 * __1p))); - _M_d1 = std::_GLIBCXX_TR1::round(std::max(_RealType(1), __d1x)); - const _RealType __d2x = - std::sqrt(__np * __1p * std::log(32 * _M_t * __1p - / (__pi_4 * __pa))); - _M_d2 = std::_GLIBCXX_TR1::round(std::max(_RealType(1), __d2x)); - - // sqrt(pi / 2) - const _RealType __spi_2 = 1.2533141373155002512078826424055226L; - _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np)); - _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p)); - _M_c = 2 * _M_d1 / __np; - _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2; - const _RealType __a12 = _M_a1 + _M_s2 * __spi_2; - const _RealType __s1s = _M_s1 * _M_s1; - _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p)) - * 2 * __s1s / _M_d1 - * std::exp(-_M_d1 * _M_d1 / (2 * __s1s))); - const _RealType __s2s = _M_s2 * _M_s2; - _M_s = (_M_a123 + 2 * __s2s / _M_d2 - * std::exp(-_M_d2 * _M_d2 / (2 * __s2s))); - _M_lf = (std::_GLIBCXX_TR1::lgamma(__np + 1) - + std::_GLIBCXX_TR1::lgamma(_M_t - __np + 1)); - _M_lp1p = std::log(__pa / __1p); - - _M_q = -std::log(1 - (__p12 - __pa) / __1p); - } - else -#endif - _M_q = -std::log(1 - __p12); - } - - template - template - typename binomial_distribution<_IntType, _RealType>::result_type - binomial_distribution<_IntType, _RealType>:: - _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t) - { - _IntType __x = 0; - _RealType __sum = 0; - - do - { - const _RealType __e = -std::log(__urng()); - __sum += __e / (__t - __x); - __x += 1; - } - while (__sum <= _M_q); - - return __x - 1; - } - - /** - * A rejection algorithm when t * p >= 8 and a simple waiting time - * method - the second in the referenced book - otherwise. - * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 - * is defined. - * - * Reference: - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. X, Sect. 4 (+ Errata!). - */ - template - template - typename binomial_distribution<_IntType, _RealType>::result_type - binomial_distribution<_IntType, _RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - result_type __ret; - const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; - -#if _GLIBCXX_USE_C99_MATH_TR1 - if (!_M_easy) - { - _RealType __x; - - // See comments above... - const _RealType __naf = - (1 - std::numeric_limits<_RealType>::epsilon()) / 2; - const _RealType __thr = - std::numeric_limits<_IntType>::max() + __naf; - - const _RealType __np = std::floor(_M_t * __p12); - const _RealType __pa = __np / _M_t; - - // sqrt(pi / 2) - const _RealType __spi_2 = 1.2533141373155002512078826424055226L; - const _RealType __a1 = _M_a1; - const _RealType __a12 = __a1 + _M_s2 * __spi_2; - const _RealType __a123 = _M_a123; - const _RealType __s1s = _M_s1 * _M_s1; - const _RealType __s2s = _M_s2 * _M_s2; - - bool __reject; - do - { - const _RealType __u = _M_s * __urng(); - - _RealType __v; - - if (__u <= __a1) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = _M_s1 * std::abs(__n); - __reject = __y >= _M_d1; - if (!__reject) - { - const _RealType __e = -std::log(__urng()); - __x = std::floor(__y); - __v = -__e - __n * __n / 2 + _M_c; - } - } - else if (__u <= __a12) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = _M_s2 * std::abs(__n); - __reject = __y >= _M_d2; - if (!__reject) - { - const _RealType __e = -std::log(__urng()); - __x = std::floor(-__y); - __v = -__e - __n * __n / 2; - } - } - else if (__u <= __a123) - { - const _RealType __e1 = -std::log(__urng()); - const _RealType __e2 = -std::log(__urng()); - - const _RealType __y = _M_d1 + 2 * __s1s * __e1 / _M_d1; - __x = std::floor(__y); - __v = (-__e2 + _M_d1 * (1 / (_M_t - __np) - -__y / (2 * __s1s))); - __reject = false; - } - else - { - const _RealType __e1 = -std::log(__urng()); - const _RealType __e2 = -std::log(__urng()); - - const _RealType __y = _M_d2 + 2 * __s2s * __e1 / _M_d2; - __x = std::floor(-__y); - __v = -__e2 - _M_d2 * __y / (2 * __s2s); - __reject = false; - } - - __reject = __reject || __x < -__np || __x > _M_t - __np; - if (!__reject) - { - const _RealType __lfx = - std::_GLIBCXX_TR1::lgamma(__np + __x + 1) - + std::_GLIBCXX_TR1::lgamma(_M_t - (__np + __x) + 1); - __reject = __v > _M_lf - __lfx + __x * _M_lp1p; - } - - __reject |= __x + __np >= __thr; - } - while (__reject); - - __x += __np + __naf; - - const _IntType __z = _M_waiting(__urng, _M_t - _IntType(__x)); - __ret = _IntType(__x) + __z; - } - else -#endif - __ret = _M_waiting(__urng, _M_t); - - if (__p12 != _M_p) - __ret = _M_t - __ret; - return __ret; - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const binomial_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.t() << __space << __x.p() - << __space << __x._M_nd; - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - binomial_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - __is >> __x._M_t >> __x._M_p >> __x._M_nd; - __x._M_initialize(); - - __is.flags(__flags); - return __is; - } - - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_real<_RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.min() << __space << __x.max(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_real<_RealType>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::skipws); - - __is >> __x._M_min >> __x._M_max; - - __is.flags(__flags); - return __is; - } - - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const exponential_distribution<_RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.lambda(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - - /** - * Polar method due to Marsaglia. - * - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. V, Sect. 4.4. - */ - template - template - typename normal_distribution<_RealType>::result_type - normal_distribution<_RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - result_type __ret; - - if (_M_saved_available) - { - _M_saved_available = false; - __ret = _M_saved; - } - else - { - result_type __x, __y, __r2; - do - { - __x = result_type(2.0) * __urng() - 1.0; - __y = result_type(2.0) * __urng() - 1.0; - __r2 = __x * __x + __y * __y; - } - while (__r2 > 1.0 || __r2 == 0.0); - - const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2); - _M_saved = __x * __mult; - _M_saved_available = true; - __ret = __y * __mult; - } - - __ret = __ret * _M_sigma + _M_mean; - return __ret; - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const normal_distribution<_RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x._M_saved_available << __space - << __x.mean() << __space - << __x.sigma(); - if (__x._M_saved_available) - __os << __space << __x._M_saved; - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - template - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - normal_distribution<_RealType>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - __is >> __x._M_saved_available >> __x._M_mean - >> __x._M_sigma; - if (__x._M_saved_available) - __is >> __x._M_saved; - - __is.flags(__flags); - return __is; - } - - - template - void - gamma_distribution<_RealType>:: - _M_initialize() - { - if (_M_alpha >= 1) - _M_l_d = std::sqrt(2 * _M_alpha - 1); - else - _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha)) - * (1 - _M_alpha)); - } - - /** - * Cheng's rejection algorithm GB for alpha >= 1 and a modification - * of Vaduva's rejection from Weibull algorithm due to Devroye for - * alpha < 1. - * - * References: - * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral - * Shape Parameter." Applied Statistics, 26, 71-75, 1977. - * - * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection - * and Composition Procedures." Math. Operationsforschung and Statistik, - * Series in Statistics, 8, 545-576, 1977. - * - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!). - */ - template - template - typename gamma_distribution<_RealType>::result_type - gamma_distribution<_RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - result_type __x; - - bool __reject; - if (_M_alpha >= 1) - { - // alpha - log(4) - const result_type __b = _M_alpha - - result_type(1.3862943611198906188344642429163531L); - const result_type __c = _M_alpha + _M_l_d; - const result_type __1l = 1 / _M_l_d; - - // 1 + log(9 / 2) - const result_type __k = 2.5040773967762740733732583523868748L; - - do - { - const result_type __u = __urng(); - const result_type __v = __urng(); - - const result_type __y = __1l * std::log(__v / (1 - __v)); - __x = _M_alpha * std::exp(__y); - - const result_type __z = __u * __v * __v; - const result_type __r = __b + __c * __y - __x; - - __reject = __r < result_type(4.5) * __z - __k; - if (__reject) - __reject = __r < std::log(__z); - } - while (__reject); - } - else - { - const result_type __c = 1 / _M_alpha; - - do - { - const result_type __z = -std::log(__urng()); - const result_type __e = -std::log(__urng()); - - __x = std::pow(__z, __c); - - __reject = __z + __e < _M_l_d + __x; - } - while (__reject); - } - - return __x; - } - - template - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const gamma_distribution<_RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.alpha(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - -_GLIBCXX_END_NAMESPACE -} diff --git a/libstdc++-v3/include/tr1/regex b/libstdc++-v3/include/tr1/regex index 3b8f03f..0282977 100644 --- a/libstdc++-v3/include/tr1/regex +++ b/libstdc++-v3/include/tr1/regex @@ -33,2397 +33,36 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_REGEX -#define _TR1_REGEX 1 +#ifndef _GLIBCXX_TR1_REGEX +#define _GLIBCXX_TR1_REGEX 1 + +#pragma GCC system_header + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif -#include #include #include #include #include #include #include -#include #include +#include -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - -/** - * @addtogroup tr1_regex Regular Expressions - * A facility for performing regular expression pattern matching. - * @{ - */ - -namespace regex_constants -{ - // [7.5.1] Bitmask Type syntax_option_type - enum __syntax_option - { - _S_icase, - _S_nosubs, - _S_optimize, - _S_collate, - _S_ECMAScript, - _S_basic, - _S_extended, - _S_awk, - _S_grep, - _S_egrep, - _S_syntax_last - }; - - /** - * @brief This is a bitmask type indicating how to interpret the regex. - * - * The @c syntax_option_type is implementation defined but it is valid to - * perform bitwise operations on these values and expect the right thing to - * happen. - * - * A valid value of type syntax_option_type shall have exactly one of the - * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep - * set. - */ - typedef unsigned int syntax_option_type; - - /// Specifies that the matching of regular expressions against a character - /// sequence shall be performed without regard to case. - static const syntax_option_type icase = 1 << _S_icase; - - /// Specifies that when a regular expression is matched against a character - /// container sequence, no sub-expression matches are to be stored in the - /// supplied match_results structure. - static const syntax_option_type nosubs = 1 << _S_nosubs; - - /// Specifies that the regular expression engine should pay more attention to - /// the speed with which regular expressions are matched, and less to the - /// speed with which regular expression objects are constructed. Otherwise - /// it has no detectable effect on the program output. - static const syntax_option_type optimize = 1 << _S_optimize; - - /// Specifies that character ranges of the form [a-b] should be locale - /// sensitive. - static const syntax_option_type collate = 1 << _S_collate; - - /// Specifies that the grammar recognized by the regular expression engine is - /// that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript - /// Language Specification, Standard Ecma-262, third edition, 1999], as - /// modified in tr1 section [7.13]. This grammar is similar to that defined - /// in the PERL scripting language but extended with elements found in the - /// POSIX regular expression grammar. - static const syntax_option_type ECMAScript = 1 << _S_ECMAScript; - - /// Specifies that the grammar recognized by the regular expression engine is - /// that used by POSIX basic regular expressions in IEEE Std 1003.1-2001, - /// Portable Operating System Interface (POSIX), Base Definitions and - /// Headers, Section 9, Regular Expressions [IEEE, Information Technology -- - /// Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. - static const syntax_option_type basic = 1 << _S_basic; - - /// Specifies that the grammar recognized by the regular expression engine is - /// that used by POSIX extended regular expressions in IEEE Std 1003.1-2001, - /// Portable Operating System Interface (POSIX), Base Definitions and Headers, - /// Section 9, Regular Expressions. - static const syntax_option_type extended = 1 << _S_extended; - - /// Specifies that the grammar recognized by the regular expression engine is - /// that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is - /// identical to syntax_option_type extended, except that C-style escape - /// sequences are supported. These sequences are, explicitly, '\\', '\a', - /// '\b', '\f', '\n', '\r', '\t' , '\v', '\"', '\\', and '\ddd' (where ddd is - /// one, two, or three octal digits). - static const syntax_option_type awk = 1 << _S_awk; - - /// Specifies that the grammar recognized by the regular expression engine is - /// that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is - /// identical to syntax_option_type basic, except that newlines are treated - /// as whitespace. - static const syntax_option_type grep = 1 << _S_grep; - - /// Specifies that the grammar recognized by the regular expression engine is - /// that used by POSIX utility grep when given the -E option in - /// IEEE Std 1003.1-2001. This option is identical to syntax_option_type - /// extended, except that newlines are treated as whitespace. - static const syntax_option_type egrep = 1 << _S_egrep; - - - // [7.5.2] Bitmask Type match_flag_type - enum __match_flag - { - _S_not_bol, - _S_not_eol, - _S_not_bow, - _S_not_eow, - _S_any, - _S_not_null, - _S_continuous, - _S_prev_avail, - _S_sed, - _S_no_copy, - _S_first_only, - _S_match_flag_last - }; - - /** - * @brief This is a bitmask type indicating regex matching rules. - * - * Matching a regular expression against a sequence of characters [first, - * last) proceeds according to the rules of the grammar specified for the - * regular expression object, modified according to the effects listed - * below for any bitmask elements set. - * - * The @c match_flag_type is implementation defined but it is valid to - * perform bitwise operations on these values and expect the right thing to - * happen. - */ - typedef std::bitset<_S_match_flag_last> match_flag_type; - - static const match_flag_type match_default = 0; - - /// The first character in the sequence [first, last) is treated as though it - /// is not at the beginning of a line, so the character "^" in the regular - /// expression shall not match [first, first). - static const match_flag_type match_not_bol = 1 << _S_not_bol; - - /// The last character in the sequence [first, last) is treated as though it - /// is not at the end of a line, so the character "$" in the regular - /// expression shall not match [last, last). - static const match_flag_type match_not_eol = 1 << _S_not_eol; - - /// The expression "\b" is not matched against the sub-sequence - /// [first,first). - static const match_flag_type match_not_bow = 1 << _S_not_bow; - - /// The expression "\b" should not be matched against the sub-sequence - /// [last,last). - static const match_flag_type match_not_eow = 1 << _S_not_eow; - - /// If more than one match is possible then any match is an acceptable - /// result. - static const match_flag_type match_any = 1 << _S_any; - - /// The expression does not match an empty sequence. - static const match_flag_type match_not_null = 1 << _S_not_null; - - /// The expression only matchs a sub-sequence that begins at first . - static const match_flag_type match_continuous = 1 << _S_continuous; - - /// --first is a valid iterator position. When this flag is set then the - /// flags match_not_bol and match_not_bow are ignored by the regular - /// expression algorithms 7.11 and iterators 7.12. - static const match_flag_type match_prev_avail = 1 << _S_prev_avail; - - /// When a regular expression match is to be replaced by a new string, the - /// new string is constructed using the rules used by the ECMAScript replace - /// function in ECMA- 262 [Ecma International, ECMAScript Language - /// Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11 - /// String.prototype.replace. In addition, during search and replace - /// operations all non-overlapping occurrences of the regular expression - /// are located and replaced, and sections of the input that did not match - /// the expression are copied unchanged to the output string. - /// - /// Format strings (from ECMA-262 [15.5.4.11]): - /// $$ $ - /// $& The matched substring. - /// $` The portion of string that preceeds the matched substring. - /// $' The portion of string that follows the matched substring. - /// $n The nth capture, where n is in [1,9] and $n is not followed by a - /// decimal digit. If n <= m and the nth capture is undefined, use the - /// empty string - /// instead. If n > m, the result is implementation-defined. - /// $nn The nnth capture, where nn is a two-digit decimal number on [01, 99]. - /// If nn <= m and the nth capture is undefined, use the empty string - /// instead. If nn > m, the result is implementation-defined. - /// - static const match_flag_type format_default = 0; - - /// When a regular expression match is to be replaced by a new string, the - /// new string is constructed using the rules used by the POSIX sed utility - /// in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable - /// Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. - static const match_flag_type format_sed = 1 << _S_sed; - - /// During a search and replace operation, sections of the character - /// container sequence being searched that do not match the regular - /// expression shall not be copied to the output string. - static const match_flag_type format_no_copy = 1 << _S_no_copy; - - /// When specified during a search and replace operation, only the first - /// occurrence of the regular expression shall be replaced. - static const match_flag_type format_first_only = 1 << _S_first_only; - - - // [7.5.3] implementation-defined error type - enum error_type - { - _S_error_collate, - _S_error_ctype, - _S_error_escape, - _S_error_backref, - _S_error_brack, - _S_error_paren, - _S_error_brace, - _S_error_badbrace, - _S_error_range, - _S_error_space, - _S_error_badrepeat, - _S_error_complexity, - _S_error_stack, - _S_error_last - }; - - /// The expression contained an invalid collating element name. - static const error_type error_collate(_S_error_collate); - - /// The expression contained an invalid character class name. - static const error_type error_ctype(_S_error_ctype); - - /// The expression contained an invalid escaped character, or a trailing - /// escape. - static const error_type error_escape(_S_error_escape); - - /// The expression contained an invalid back reference. - static const error_type error_backref(_S_error_backref); - - /// The expression contained mismatched [ and ]. - static const error_type error_brack(_S_error_brack); - - /// The expression contained mismatched ( and ). - static const error_type error_paren(_S_error_paren); - - /// The expression contained mismatched { and } - static const error_type error_brace(_S_error_brace); - - /// The expression contained an invalid range in a {} expression. - static const error_type error_badbrace(_S_error_badbrace); - - /// The expression contained an invalid character range, - /// such as [b-a] in most encodings. - static const error_type error_range(_S_error_range); - - /// There was insufficient memory to convert the expression into a - /// finite state machine. - static const error_type error_space(_S_error_space); - - /// One of *?+{ was not preceded by a valid regular expression. - static const error_type error_badrepeat(_S_error_badrepeat); - - /// The complexity of an attempted match against a regular expression - /// exceeded a pre-set level. - static const error_type error_complexity(_S_error_complexity); - - /// There was insufficient memory to determine whether the - /// regular expression could match the specified character sequence. - static const error_type error_stack(_S_error_stack); -} - - - // [7.8] Class regex_error - /** - * Defines the type of objects thrown as exceptions to report errors from the - * regular expression library. - */ - class regex_error - : public std::runtime_error - { - public: - /** - * @brief constructs a regex_error object. - * - * @param ecode the regex error code. - */ - explicit - regex_error(regex_constants::error_type __ecode) - : std::runtime_error("regex_error"), _M_code(__ecode) - { } - - /** - * @brief gets the regex error code. - * - * @returns the regex error code. - */ - regex_constants::error_type - code() const - { return _M_code; } - - protected: - regex_constants::error_type _M_code; - }; - - - // [7.7] Class regex_traits - /** - * A regular expression traits class that satisfies the requirements of tr1 - * section [7.2]. - * - * The class %regex is parameterized around a set of related types and - * functions used to complete the definition of its semantics. This class - * satisfies the requirements of such a traits class. - */ - template - struct regex_traits - { - public: - typedef _Ch_type char_type; - typedef std::basic_string string_type; - typedef std::locale locale_type; - typedef std::ctype_base::mask char_class_type; - - public: - /** - * @brief Constructs a default traits object. - */ - regex_traits() - { } - - /** - * @brief Gives the length of a C-style string starting at @p __p. - * - * @param __p a pointer to the start of a character sequence. - * - * @returns the number of characters between @p *__p and the first - * default-initialized value of type @p char_type. In other words, uses - * the C-string algorithm for determiining the length of a sequence of - * characters. - */ - static std::size_t - length(const char_type* __p) - { return string_type::traits_type::length(__p); } - - /** - * @brief Performs the identity translation. - * - * @param c A character to the locale-specific character set. - * - * @returns c. - */ - char_type - translate(char_type __c) const - { return __c; } - - /** - * @brief Translates a character into a case-insensitive equivalent. - * - * @param c A character to the locale-specific character set. - * - * @returns the locale-specific lower-case equivalent of c. - * @throws std::bad_cast if the imbued locale does not support the ctype - * facet. - */ - char_type - translate_nocase(char_type __c) const - { - using std::ctype; - using std::use_facet; - return use_facet >(_M_locale).tolower(__c); - } - - /** - * @brief Gets a sort key for a character sequence. - * - * @param first beginning of the character sequence. - * @param last one-past-the-end of the character sequence. - * - * Returns a sort key for the character sequence designated by the - * iterator range [F1, F2) such that if the character sequence [G1, G2) - * sorts before the character sequence [H1, H2) then - * v.transform(G1, G2) < v.transform(H1, H2). - * - * What this really does is provide a more efficient way to compare a - * string to multiple other strings in locales with fancy collation - * rules and equivalence classes. - * - * @returns a locale-specific sort key equivalent to the input range. - * - * @throws std::bad_cast if the current locale does not have a collate - * facet. - */ - template - string_type - transform(_Fwd_iter __first, _Fwd_iter __last) const - { - using std::collate; - using std::use_facet; - const collate<_Ch_type>& __c(use_facet< - collate<_Ch_type> >(_M_locale)); - string_type __s(__first, __last); - return __c.transform(__s.data(), __s.data() + __s.size()); - } - - /** - * @brief Dunno. - * - * @param first beginning of the character sequence. - * @param last one-past-the-end of the character sequence. - * - * Effects: if typeid(use_facet >) == - * typeid(collate_byname<_Ch_type>) and the form of the sort key - * returned by collate_byname<_Ch_type>::transform(first, last) is known - * and can be converted into a primary sort key then returns that key, - * otherwise returns an empty string. WTF?? - * - * @todo Implement this function. - */ - template - string_type - transform_primary(_Fwd_iter __first, _Fwd_iter __last) const - { return string_type(); } - - /** - * @breief Gets a collation element by name. - * - * @param first beginning of the collation element name. - * @param last one-past-the-end of the collation element name. - * - * @returns a sequence of one or more characters that represents the - * collating element consisting of the character sequence designated by - * the iterator range [first, last). Returns an empty string if the - * character sequence is not a valid collating element. - * - * @todo Implement this function. - */ - template - string_type - lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const - { return string_type(); } - - /** - * @brief Maps one or mire characters to a named character - * classification. - * - * @param first beginning of the character sequence. - * @param last one-past-the-end of the character sequence. - * - * @returns an unspecified value that represents the character - * classification named by the character sequence designated by the - * iterator range [first, last). The value returned shall be independent - * of the case of the characters in the character sequence. If the name - * is not recognized then returns a value that compares equal to 0. - * - * At least the following names (or their wide-character equivalent) are - * supported. - * - d - * - w - * - s - * - alnum - * - alpha - * - blank - * - cntrl - * - digit - * - graph - * - lower - * - print - * - punct - * - space - * - upper - * - xdigit - * - * @todo Implement this function. - */ - template - char_class_type - lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const - { return 0; } - - /** - * @brief Determines if @p c is a member of an identified class. - * - * @param c a character. - * @param f a class type (as returned from lookup_classname). - * - * @returns true if the character @p c is a member of the classification - * represented by @p f, false otherwise. - * - * @throws std::bad_cast if the current locale does not have a ctype - * facet. - */ - bool - isctype(_Ch_type __c, char_class_type __f) const - { - using std::ctype; - using std::use_facet; - const ctype<_Ch_type>& __ctype(use_facet< - ctype<_Ch_type> >(_M_locale)); - - if (__ctype.is(__c, __f)) - return true; - - // special case of underscore in [[:w:]] - if (__c == __ctype.widen('_')) - { - const char* const __wb[] = "w"; - char_class_type __wt = this->lookup_classname(__wb, - __wb + sizeof(__wb)); - if (__f | __wt) - return true; - } - - // special case of [[:space:]] in [[:blank:]] - if (__c == __ctype.isspace(__c)) - { - const char* const __bb[] = "blank"; - char_class_type __bt = this->lookup_classname(__bb, - __bb + sizeof(__bb)); - if (__f | __bt) - return true; - } - - return false; - } - - /** - * @brief Converts a digit to an int. - * - * @param ch a character representing a digit. - * @param radix the radix if the numeric conversion (limited to 8, 10, - * or 16). - * - * @returns the value represented by the digit ch in base radix if the - * character ch is a valid digit in base radix; otherwise returns -1. - * - * @todo Implement this function. - */ - int - value(_Ch_type __ch, int __radix) const; - - /** - * @brief Imbues the regex_traits object with a copy of a new locale. - * - * @param loc A locale. - * - * @returns a copy of the previous locale in use by the regex_traits - * object. - * - * @note Calling imbue with a different locale than the one currently in - * use invalidates all cached data held by *this. - */ - locale_type - imbue(locale_type __loc) - { - std::swap(_M_locale, __loc); - return __loc; - } - - /** - * @brief Gets a copy of the current locale in use by the regex_traits - * object. - */ - locale_type - getloc() const - { return _M_locale; } - - protected: - locale_type _M_locale; - }; - - - // [7.8] Class basic_regex - /** - * Objects of specializations of this class represent regular expressions - * constructed from sequences of character type @p _Ch_type. - * - * Storage for the regular expression is allocated and deallocated as - * necessary by the member functions of this class. - */ - template > - class basic_regex - { - public: - // types: - typedef _Ch_type value_type; - typedef regex_constants::syntax_option_type flag_type; - typedef typename _Rx_traits::locale_type locale_type; - typedef typename _Rx_traits::string_type string_type; - - // [7.8.1] constants - static const regex_constants::syntax_option_type icase - = regex_constants::icase; - static const regex_constants::syntax_option_type nosubs - = regex_constants::nosubs; - static const regex_constants::syntax_option_type optimize - = regex_constants::optimize; - static const regex_constants::syntax_option_type collate - = regex_constants::collate; - static const regex_constants::syntax_option_type ECMAScript - = regex_constants::ECMAScript; - static const regex_constants::syntax_option_type basic - = regex_constants::basic; - static const regex_constants::syntax_option_type extended - = regex_constants::extended; - static const regex_constants::syntax_option_type awk - = regex_constants::awk; - static const regex_constants::syntax_option_type grep - = regex_constants::grep; - static const regex_constants::syntax_option_type egrep - = regex_constants::egrep; - - // [7.8.2] construct/copy/destroy - /** - * Constructs a basic regular expression that does not match any - * character sequence. - */ - basic_regex() - : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0) - { _M_compile(); } - - /** - * @brief Constructs a basic regular expression from the sequence - * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the - * flags in @p f. - * - * @param p A pointer to the start of a C-style null-terminated string - * containing a regular expression. - * @param f Flags indicating the syntax rules and options. - * - * @throws regex_error if @p p is not a valid regular expression. - */ - explicit - basic_regex(const _Ch_type* __p, - flag_type __f = regex_constants::ECMAScript) - : _M_flags(__f), _M_pattern(__p), _M_mark_count(0) - { _M_compile(); } - - /** - * @brief Constructs a basic regular expression from the sequence - * [p, p + len) interpreted according to the flags in @p f. - * - * @param p A pointer to the start of a string containing a regular - * expression. - * @param len The length of the string containing the regular expression. - * @param f Flags indicating the syntax rules and options. - * - * @throws regex_error if @p p is not a valid regular expression. - */ - basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f) - : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0) - { _M_compile(); } - - /** - * @brief Copy-contructs a basic regular expression. - * - * @param rhs A @p regex object. - */ - basic_regex(const basic_regex& __rhs) - : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern), - _M_mark_count(__rhs._M_mark_count) - { _M_compile(); } - - /** - * @brief Constructs a basic regular expression from the string - * @p interpreted according to the flags in @p f. - * - * @param p A string containing a regular expression. - * @param f Flags indicating the syntax rules and options. - * - * @throws regex_error if @p p is not a valid regular expression. - */ - template - explicit - basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, - flag_type __f = regex_constants::ECMAScript) - : _M_flags(__f), _M_pattern(__s), _M_mark_count(0) - { _M_compile(); } - - /** - * @brief Constructs a basic regular expression from the range - * [first, last) interpreted according to the flags in @p f. - * - * @param first The start of arange containing a valid regular - * expression. - * @param last The end of a range containing a valid regular - * expression. - * @param f The format flags of the regular expression. - * - * @throws regex_error if @p p is not a valid regular expression. - */ - template - basic_regex(_InputIterator __first, _InputIterator __last, - flag_type __f = regex_constants::ECMAScript) - : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0) - { _M_compile(); } - - /** - * @brief Destroys a basic regular expression. - */ - ~basic_regex() - { } - - /** - * @brief Assigns one regular expression to another. - */ - basic_regex& - operator=(const basic_regex& __rhs) - { return this->assign(__rhs); } - - /** - * @brief Replaces a regular expression with a new one constructed from - * a C-style null-terminated string. - * - * @param A pointer to the start of a null-terminated C-style string - * containing a regular expression. - */ - basic_regex& - operator=(const _Ch_type* __p) - { return this->assign(__p, flags()); } - - /** - * @brief Replaces a regular expression with a new one constructed from - * a string. - * - * @param A pointer to a string containing a regular expression. - */ - template - basic_regex& - operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s) - { return this->assign(__s, flags()); } - - // [7.8.3] assign - /** - * @brief the real assignment operator. - * - * @param that Another regular expression object. - */ - basic_regex& - assign(const basic_regex& __that) - { - basic_regex __tmp(__that); - this->swap(__tmp); - return *this; - } - - /** - * @brief Assigns a new regular expression to a regex object from a - * C-style null-terminated string containing a regular expression - * pattern. - * - * @param p A pointer to a C-style null-terminated string containing - * a regular expression pattern. - * @param flags Syntax option flags. - * - * @throws regex_error if p does not contain a valid regular expression - * pattern interpreted according to @p flags. If regex_error is thrown, - * *this remains unchanged. - */ - basic_regex& - assign(const _Ch_type* __p, - flag_type __flags = regex_constants::ECMAScript) - { return this->assign(string_type(__p), __flags); } - - /** - * @brief Assigns a new regular expression to a regex object from a - * C-style string containing a regular expression pattern. - * - * @param p A pointer to a C-style string containing a - * regular expression pattern. - * @param len The length of the regular expression pattern string. - * @param flags Syntax option flags. - * - * @throws regex_error if p does not contain a valid regular expression - * pattern interpreted according to @p flags. If regex_error is thrown, - * *this remains unchanged. - */ - basic_regex& - assign(const _Ch_type* __p, std::size_t __len, flag_type __flags) - { return this->assign(string_type(__p, __len), __flags); } - - /** - * @brief Assigns a new regular expression to a regex object from a - * string containing a regular expression pattern. - * - * @param s A string containing a regular expression pattern. - * @param flags Syntax option flags. - * - * @throws regex_error if p does not contain a valid regular expression - * pattern interpreted according to @p flags. If regex_error is thrown, - * *this remains unchanged. - */ - template - basic_regex& - assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s, - flag_type __f = regex_constants::ECMAScript) - { - basic_regex __tmp(__s, __f); - this->swap(__tmp); - return *this; - } - - /** - * @brief Assigns a new regular expression to a regex object. - * - * @param first The start of a range containing a valid regular - * expression. - * @param last The end of a range containing a valid regular - * expression. - * @param flags Syntax option flags. - * - * @throws regex_error if p does not contain a valid regular expression - * pattern interpreted according to @p flags. If regex_error is thrown, - * *this remains unchanged. - */ - template - basic_regex& - assign(_InputIterator __first, _InputIterator __last, - flag_type __flags = regex_constants::ECMAScript) - { return this->assign(string_type(__first, __last), __flags); } - - // [7.8.4] const operations - /** - * @brief Gets the number of marked subexpressions within the regular - * expresison. - */ - unsigned int - mark_count() const - { return _M_mark_count; } - - /** - * @brief Gets the flags used to construct the regular expression - * or in the last call to assign(). - */ - flag_type - flags() const - { return _M_flags; } - - // [7.8.5] locale - /** - * @brief Imbues the regular expression object with the given locale. - * - * @param loc A locale. - */ - locale_type - imbue(locale_type __loc) - { return _M_traits.imbue(__loc); } - - /** - * @brief Gets the locale currently imbued in the regular expression - * object. - */ - locale_type - getloc() const - { return _M_traits.getloc(); } - - // [7.8.6] swap - /** - * @brief Swaps the contents of two regular expression obects. - * - * @param rhs Another regular expression object. - */ - void - swap(basic_regex& __rhs) - { - std::swap(_M_flags, __rhs._M_flags); - std::swap(_M_pattern, __rhs._M_pattern); - std::swap(_M_mark_count, __rhs._M_mark_count); - std::swap(_M_traits, __rhs._M_traits); - } - - private: - /** - * @brief Compiles a regular expression pattern into a NFA. - * @todo Implement this function. - */ - void _M_compile() - { } - - protected: - flag_type _M_flags; - string_type _M_pattern; - unsigned int _M_mark_count; - _Rx_traits _M_traits; - }; - - typedef basic_regex regex; -#ifdef _GLIBCXX_USE_WCHAR_T - typedef basic_regex wregex; -#endif - - - // [7.8.6] basic_regex swap - /** - * @brief Swaps the contents of two regular expression objects. - * @param lhs First regular expression. - * @param rhs Second regular expression. - */ - template - inline void - swap(basic_regex<_Ch_type, _Rx_traits>& __lhs, - basic_regex<_Ch_type, _Rx_traits>& __rhs) - { return __lhs.swap(__rhs); } - - - // [7.9] Class template sub_match - /** - * A sequence of characters matched by a particular marked sub-expression. - * - * An object of this class is essentially a pair of iterators marking a - * matched subexpression within a regular expression pattern match. Such - * objects can be converted to and compared with std::basic_string objects - * of a similar base character type as the pattern matched by the regular - * expression. - * - * The iterators that make up the pair are the usual half-open interval - * referencing the actual original pattern matched. - */ - template - class sub_match : public std::pair<_BiIter, _BiIter> - { - public: - typedef typename iterator_traits<_BiIter>::value_type value_type; - typedef typename iterator_traits<_BiIter>::difference_type - difference_type; - typedef _BiIter iterator; - - public: - bool matched; - - /** - * Gets the length of the matching sequence. - */ - difference_type - length() const - { return this->matched ? std::distance(this->first, this->second) : 0; } - - /** - * @brief Gets the matching sequence as a string. - * - * @returns the matching sequence as a string. - * - * This is the implicit conversion operator. It is identical to the - * str() member function except that it will want to pop up in - * unexpected places and cause a great deal of confusion and cursing - * from the unwary. - */ - operator basic_string() const - { - return this->matched - ? std::basic_string(this->first, this->second) - : std::basic_string(); - } - - /** - * @brief Gets the matching sequence as a string. - * - * @returns the matching sequence as a string. - */ - basic_string - str() const - { - return this->matched - ? std::basic_string(this->first, this->second) - : std::basic_string(); - } - - /** - * @brief Compares this and another matched sequence. - * - * @param s Another matched sequence to compare to this one. - * - * @retval <0 this matched sequence will collate before @p s. - * @retval =0 this matched sequence is equivalent to @p s. - * @retval <0 this matched sequence will collate after @p s. - */ - int - compare(const sub_match& __s) const - { return this->str().compare(__s.str()); } - - /** - * @brief Compares this sub_match to a string. - * - * @param s A string to compare to this sub_match. - * - * @retval <0 this matched sequence will collate before @p s. - * @retval =0 this matched sequence is equivalent to @p s. - * @retval <0 this matched sequence will collate after @p s. - */ - int - compare(const basic_string& __s) const - { return this->str().compare(__s); } - - /** - * @brief Compares this sub_match to a C-style string. - * - * @param s A C-style string to compare to this sub_match. - * - * @retval <0 this matched sequence will collate before @p s. - * @retval =0 this matched sequence is equivalent to @p s. - * @retval <0 this matched sequence will collate after @p s. - */ - int - compare(const value_type* __s) const - { return this->str().compare(__s); } - }; - - - typedef sub_match csub_match; - typedef sub_match ssub_match; -#ifdef _GLIBCXX_USE_WCHAR_T - typedef sub_match wcsub_match; - typedef sub_match wssub_match; -#endif - - // [7.9.2] sub_match non-member operators - - /** - * @brief Tests the equivalence of two regular expression submatches. - * @param lhs First regular expression submatch. - * @param rhs Second regular expression submatch. - * @returns true if @a lhs is equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator==(const sub_match<_BiIter>& __lhs, - const sub_match<_BiIter>& __rhs) - { return __lhs.compare(__rhs) == 0; } - - /** - * @brief Tests the inequivalence of two regular expression submatches. - * @param lhs First regular expression submatch. - * @param rhs Second regular expression submatch. - * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator!=(const sub_match<_BiIter>& __lhs, - const sub_match<_BiIter>& __rhs) - { return __lhs.compare(__rhs) != 0; } - - /** - * @brief Tests the ordering of two regular expression submatches. - * @param lhs First regular expression submatch. - * @param rhs Second regular expression submatch. - * @returns true if @a lhs precedes @a rhs, false otherwise. - */ - template - inline bool - operator<(const sub_match<_BiIter>& __lhs, - const sub_match<_BiIter>& __rhs) - { return __lhs.compare(__rhs) < 0; } - - /** - * @brief Tests the ordering of two regular expression submatches. - * @param lhs First regular expression submatch. - * @param rhs Second regular expression submatch. - * @returns true if @a lhs does not succeed @a rhs, false otherwise. - */ - template - inline bool - operator<=(const sub_match<_BiIter>& __lhs, - const sub_match<_BiIter>& __rhs) - { return __lhs.compare(__rhs) <= 0; } - - /** - * @brief Tests the ordering of two regular expression submatches. - * @param lhs First regular expression submatch. - * @param rhs Second regular expression submatch. - * @returns true if @a lhs does not preceed @a rhs, false otherwise. - */ - template - inline bool - operator>=(const sub_match<_BiIter>& __lhs, - const sub_match<_BiIter>& __rhs) - { return __lhs.compare(__rhs) >= 0; } - - /** - * @brief Tests the ordering of two regular expression submatches. - * @param lhs First regular expression submatch. - * @param rhs Second regular expression submatch. - * @returns true if @a lhs succeeds @a rhs, false otherwise. - */ - template - inline bool - operator>(const sub_match<_BiIter>& __lhs, - const sub_match<_BiIter>& __rhs) - { return __lhs.compare(__rhs) > 0; } - - /** - * @brief Tests the equivalence of a string and a regular expression - * submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs is equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator==(const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs == __rhs.str(); } - - /** - * @brief Tests the inequivalence of a string and a regular expression - * submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator!=(const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) - { return __lhs != __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs precedes @a rhs, false otherwise. - */ - template - inline bool - operator<(const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) - { return __lhs < __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs succeeds @a rhs, false otherwise. - */ - template - inline bool - operator>(const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) - { return __lhs > __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs does not preceed @a rhs, false otherwise. - */ - template - inline bool - operator>=(const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) - { return __lhs >= __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs does not succeed @a rhs, false otherwise. - */ - template - inline bool - operator<=(const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) - { return __lhs <= __rhs.str(); } - - /** - * @brief Tests the equivalence of a regular expression submatch and a - * string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs is equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator==(const sub_match<_Bi_iter>& __lhs, - const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __rhs) - { return __lhs.str() == __rhs; } - - /** - * @brief Tests the inequivalence of a regular expression submatch and a - * string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator!=(const sub_match<_Bi_iter>& __lhs, - const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __rhs) - { return __lhs.str() != __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs precedes @a rhs, false otherwise. - */ - template - inline bool - operator<(const sub_match<_Bi_iter>& __lhs, - const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __rhs) - { return __lhs.str() < __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs succeeds @a rhs, false otherwise. - */ - template - inline bool - operator>(const sub_match<_Bi_iter>& __lhs, - const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __rhs) - { return __lhs.str() > __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs does not preceed @a rhs, false otherwise. - */ - template - inline bool - operator>=(const sub_match<_Bi_iter>& __lhs, - const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __rhs) - { return __lhs.str() >= __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs does not succeed @a rhs, false otherwise. - */ - template - inline bool - operator<=(const sub_match<_Bi_iter>& __lhs, - const basic_string< - typename iterator_traits<_Bi_iter>::value_type, - _Ch_traits, _Ch_alloc>& __rhs) - { return __lhs.str() <= __rhs; } - - /** - * @brief Tests the equivalence of a C string and a regular expression - * submatch. - * @param lhs A C string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs is equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs == __rhs.str(); } - - /** - * @brief Tests the inequivalence of an iterator value and a regular - * expression submatch. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs != __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs precedes @a rhs, false otherwise. - */ - template - inline bool - operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs < __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs succeeds @a rhs, false otherwise. - */ - template - inline bool - operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs > __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs does not preceed @a rhs, false otherwise. - */ - template - inline bool - operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs >= __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs does not succeed @a rhs, false otherwise. - */ - template - inline bool - operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs <= __rhs.str(); } - - /** - * @brief Tests the equivalence of a regular expression submatch and a - * string. - * @param lhs A regular expression submatch. - * @param rhs A pointer to a string? - * @returns true if @a lhs is equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator==(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const* __rhs) - { return __lhs.str() == __rhs; } - - /** - * @brief Tests the inequivalence of a regular expression submatch and a - * string. - * @param lhs A regular expression submatch. - * @param rhs A pointer to a string. - * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator!=(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const* __rhs) - { return __lhs.str() != __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs precedes @a rhs, false otherwise. - */ - template - inline bool - operator<(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const* __rhs) - { return __lhs.str() < __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs succeeds @a rhs, false otherwise. - */ - template - inline bool - operator>(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const* __rhs) - { return __lhs.str() > __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs does not precede @a rhs, false otherwise. - */ - template - inline bool - operator>=(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const* __rhs) - { return __lhs.str() >= __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A string. - * @returns true if @a lhs does not succeed @a rhs, false otherwise. - */ - template - inline bool - operator<=(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const* __rhs) - { return __lhs.str() <= __rhs; } - - /** - * @brief Tests the equivalence of a string and a regular expression - * submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs is equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs == __rhs.str(); } - - /** - * @brief Tests the inequivalence of a string and a regular expression - * submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs != __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs precedes @a rhs, false otherwise. - */ - template - inline bool - operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs < __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs succeeds @a rhs, false otherwise. - */ - template - inline bool - operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs > __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs does not preceed @a rhs, false otherwise. - */ - template - inline bool - operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs >= __rhs.str(); } - - /** - * @brief Tests the ordering of a string and a regular expression submatch. - * @param lhs A string. - * @param rhs A regular expression submatch. - * @returns true if @a lhs does not succeed @a rhs, false otherwise. - */ - template - inline bool - operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, - const sub_match<_Bi_iter>& __rhs) - { return __lhs <= __rhs.str(); } - - /** - * @brief Tests the equivalence of a regular expression submatch and a - * string. - * @param lhs A regular expression submatch. - * @param rhs A const string reference. - * @returns true if @a lhs is equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator==(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const& __rhs) - { return __lhs.str() == __rhs; } - - /** - * @brief Tests the inequivalence of a regular expression submatch and a - * string. - * @param lhs A regular expression submatch. - * @param rhs A const string reference. - * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. - */ - template - inline bool - operator!=(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const& __rhs) - { return __lhs.str() != __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A const string reference. - * @returns true if @a lhs preceeds @a rhs, false otherwise. - */ - template - inline bool - operator<(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const& __rhs) - { return __lhs.str() < __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A const string reference. - * @returns true if @a lhs succeeds @a rhs, false otherwise. - */ - template - inline bool - operator>(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const& __rhs) - { return __lhs.str() > __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A const string reference. - * @returns true if @a lhs does not preceed @a rhs, false otherwise. - */ - template - inline bool - operator>=(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const& __rhs) - { return __lhs.str() >= __rhs; } - - /** - * @brief Tests the ordering of a regular expression submatch and a string. - * @param lhs A regular expression submatch. - * @param rhs A const string reference. - * @returns true if @a lhs does not succeed @a rhs, false otherwise. - */ - template - inline bool - operator<=(const sub_match<_Bi_iter>& __lhs, - typename iterator_traits<_Bi_iter>::value_type const& __rhs) - { return __lhs.str() <= __rhs; } - - /** - * @brief Inserts a matched string into an output stream. - * - * @param os The output stream. - * @param m A submatch string. - * - * @returns the output stream with the submatch string inserted. - */ - template - inline - basic_ostream<_Ch_type, _Ch_traits>& - operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os, - const sub_match<_Bi_iter>& __m) - { return __os << __m.str(); } - - // [7.10] Class template match_results - /** - * A collection of character sequences representing the result of a regular - * expression match. Storage for the collection is allocated and freed as - * necessary by the member functions of class template match_results. - * - * This class satisfies the Sequence requirements, with the exception that - * only the operations defined for a const-qualified Sequence are supported. - * - * The sub_match object stored at index 0 represents sub-expression 0, i.e. - * the whole match. In this case the sub_match member matched is always true. - * The sub_match object stored at index n denotes what matched the marked - * sub-expression n within the matched expression. If the sub-expression n - * participated in a regular expression match then the sub_match member - * matched evaluates to true, and members first and second denote the range - * of characters [first, second) which formed that match. Otherwise matched - * is false, and members first and second point to the end of the sequence - * that was searched. - */ - template > > - class match_results - : private std::vector, _Allocator> - { - private: - typedef std::vector, _Allocator> - _Base_type; - - public: - typedef sub_match<_Bi_iter> value_type; - typedef typename _Allocator::const_reference const_reference; - typedef const_reference reference; - typedef typename _Base_type::const_iterator const_iterator; - typedef const_iterator iterator; - typedef typename iterator_traits<_Bi_iter>::difference_type - difference_type; - typedef typename _Allocator::size_type size_type; - typedef _Allocator allocator_type; - typedef typename iterator_traits<_Bi_iter>::value_type char_type; - typedef basic_string string_type; - - public: - // [7.10.1] construct/copy/destroy - /** - * @brief Constructs a default match_results container. - */ - explicit - match_results(const _Allocator& __a = _Allocator()) - : _Base_type(__a), _M_matched(false) - { } - - /** - * @brief Copy constructs a match_result. - */ - match_results(const match_results& __rhs) - : _Base_type(__rhs), _M_matched(__rhs._M_matched), - _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix) - { } - - /** - * @brief Assigns rhs to *this. - */ - match_results& - operator=(const match_results& __rhs) - { - match_results __tmp(__rhs); - this->swap(__tmp); - } - - /** - * @todo Implement this function. - */ - ~match_results() - { } - - // [7.10.2] size - /** - * @todo Document this function. - */ - size_type - size() const - { return _M_matched ? _Base_type::size() + 1 : 0; } - - /** - * @todo Implement this function. - */ - //size_type - //max_size() const; - using _Base_type::max_size; - - /** - * @todo Document this function. - */ - bool - empty() const - { return size() == 0; } - - // [7.10.3] element access - /** - * @brief Gets the length of the indicated submatch. - * @param sub indicates the submatch. - */ - difference_type - length(size_type __sub = 0) const - { return _M_matched ? this->str(__sub).length() : 0; } - - /** - * @todo Document this function. - */ - difference_type - position(size_type __sub = 0) const - { - return _M_matched ? std::distance(this->prefix().first, - (*this)[__sub].first) : 0; - } - - /** - * @todo Document this function. - */ - string_type - str(size_type __sub = 0) const - { return _M_matched ? (*this)[__sub].str() : string_type(); } - - /** - * @todo Document this function. - */ - const_reference - operator[](size_type __n) const - { return _Base_type::operator[](__n); } - - /** - * @todo Document this function. - */ - const_reference - prefix() const - { return _M_prefix; } - - /** - * @todo Document this function. - */ - const_reference - suffix() const - { return _M_suffix; } - - /** - * @todo Document this function. - */ - const_iterator - begin() const - { return _Base_type::begin(); } - - /** - * @todo Document this function. - */ - const_iterator - end() const - { return _Base_type::end(); } - - // [7.10.4] format - /** - * @todo Implement this function. - */ - template - _Out_iter - format(_Out_iter __out, const string_type& __fmt, - regex_constants::match_flag_type __flags - = regex_constants::format_default) const - { return __out; } - - /** - * @todo Implement this function. - */ - string_type - format(const string_type& __fmt, - regex_constants::match_flag_type __flags - = regex_constants::format_default) const; - - // [7.10.5] allocator - /** - * @todo Document this function. - */ - //allocator_type - //get_allocator() const; - using _Base_type::get_allocator; - - // [7.10.6] swap - /** - * @todo Document this function. - */ - void - swap(match_results& __that) - { - _Base_type::swap(__that); - std::swap(_M_matched, __that._M_matched); - std::swap(_M_prefix, __that._M_prefix); - std::swap(_M_suffix, __that._M_suffix); - } - - private: - bool _M_matched; - value_type _M_prefix; - value_type _M_suffix; - }; - - typedef match_results cmatch; - typedef match_results smatch; -#ifdef _GLIBCXX_USE_WCHAR_T - typedef match_results wcmatch; - typedef match_results wsmatch; -#endif - - // match_results comparisons - /** - * @todo Implement this function. - */ - template - inline bool - operator==(const match_results<_Bi_iter, _Allocator>& __m1, - const match_results<_Bi_iter, _Allocator>& __m2); - - /** - * @todo Implement this function. - */ - template - inline bool - operator!=(const match_results<_Bi_iter, _Allocator>& __m1, - const match_results<_Bi_iter, _Allocator>& __m2); - - // [7.10.6] match_results swap - /** - * @brief Swaps two match results. - * @param lhs A match result. - * @param rhs A match result. - * - * The contents of the two match_results objects are swapped. - */ - template - inline void - swap(match_results<_Bi_iter, _Allocator>& __lhs, - match_results<_Bi_iter, _Allocator>& __rhs) - { return __lhs.swap(__rhs); } - - // [7.11.2] Function template regex_match - /** - * @brief Determines if there is a match between the regular expression @p e - * and all of the character sequence [first, last). - * - * @param first Beginning of the character sequence to match. - * @param last One-past-the-end of the character sequence to match. - * @param m The match results. - * @param re The regular expression. - * @param flags Controls how the regular expression is matched. - * - * @retval true A match exists. - * @retval false Otherwise. - * - * @todo Implement this function. - */ - template - bool - regex_match(_Bi_iter __first, _Bi_iter __last, - match_results<_Bi_iter, _Allocator>& __m, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { return false; } - - /** - * @brief Indicates if there is a match between the regular expression @p e - * and all of the character sequence [first, last). - * - * @param first Beginning of the character sequence to match. - * @param last One-past-the-end of the character sequence to match. - * @param re The regular expression. - * @param flags Controls how the regular expression is matched. - * - * @retval true A match exists. - * @retval false Otherwise. - */ - template - bool - regex_match(_Bi_iter __first, _Bi_iter __last, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { - match_results<_Bi_iter> __what; - return regex_match(__first, __last, __what, __re, __flags); - } - - /** - * @brief Determines if there is a match between the regular expression @p e - * and a C-style null-terminated string. - * - * @param s The C-style null-terminated string to match. - * @param m The match results. - * @param re The regular expression. - * @param f Controls how the regular expression is matched. - * - * @retval true A match exists. - * @retval false Otherwise. - */ - template - inline bool - regex_match(const _Ch_type* __s, - match_results& __m, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __f - = regex_constants::match_default) - { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); } - - /** - * @brief Determines if there is a match between the regular expression @p e - * and a string. - * - * @param s The string to match. - * @param m The match results. - * @param re The regular expression. - * @param flags Controls how the regular expression is matched. - * - * @retval true A match exists. - * @retval false Otherwise. - */ - template - inline bool - regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, - match_results::const_iterator, _Allocator>& __m, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); } - - /** - * @brief Indicates if there is a match between the regular expression @p e - * and a C-style null-terminated string. - * - * @param s The C-style null-terminated string to match. - * @param re The regular expression. - * @param f Controls how the regular expression is matched. - * - * @retval true A match exists. - * @retval false Otherwise. - */ - template - inline bool - regex_match(const _Ch_type* __s, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __f - = regex_constants::match_default) - { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); } - - /** - * @brief Indicates if there is a match between the regular expression @p e - * and a string. - * - * @param s [IN] The string to match. - * @param re [IN] The regular expression. - * @param flags [IN] Controls how the regular expression is matched. - * - * @retval true A match exists. - * @retval false Otherwise. - */ - template - inline bool - regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { return regex_match(__s.begin(), __s.end(), __re, __flags); } - - // [7.11.3] Function template regex_search - /** - * Searches for a regular expression within a range. - * @param first [IN] The start of the string to search. - * @param last [IN] One-past-the-end of the string to search. - * @param m [OUT] The match results. - * @param re [IN] The regular expression to search for. - * @param flags [IN] Search policy flags. - * @retval true A match was found within the string. - * @retval false No match was found within the string, the content of %m is - * undefined. - * @todo Implement this function. - */ - template - inline bool - regex_search(_Bi_iter __first, _Bi_iter __last, - match_results<_Bi_iter, _Allocator>& __m, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { return false; } - - /** - * Searches for a regular expression within a range. - * @param first [IN] The start of the string to search. - * @param last [IN] One-past-the-end of the string to search. - * @param re [IN] The regular expression to search for. - * @param flags [IN] Search policy flags. - * @retval true A match was found within the string. - * @retval false No match was found within the string. - * @todo Document me. - */ - template - inline bool - regex_search(_Bi_iter __first, _Bi_iter __last, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { - match_results<_Bi_iter> __what; - return regex_search(__first, __last, __what, __re, __flags); - } - - /** - * @brief Searches for a regular expression within a C-string. - * @param s [IN] A C-string to search for the regex. - * @param m [OUT] The set of regex mnatches. - * @param e [IN] The regex to search for in @p s. - * @param f [IN] The search flags. - * @retval true A match was found within the string. - * @retval false No match was found within the string, the content of %m is - * undefined. - * @todo Document me. - */ - template - inline bool - regex_search(const _Ch_type* __s, - match_results& __m, - const basic_regex<_Ch_type, _Rx_traits>& __e, - regex_constants::match_flag_type __f - = regex_constants::match_default) - { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); } - - /** - * @brief Searches for a regular expression within a C-string. - * @param s [IN] The C-string to search. - * @param e [IN] The regular expressioon to search for. - * @param f [IN] Search policy flags. - * @retval true A match was found within the string. - * @retval false No match was found within the string. - * @todo Document me. - */ - template - inline bool - regex_search(const _Ch_type* __s, - const basic_regex<_Ch_type, _Rx_traits>& __e, - regex_constants::match_flag_type __f - = regex_constants::match_default) - { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); } - - /** - * @brief Searches for a regular expression within a string. - * @param s [IN] The string to search. - * @param e [IN] The regular expressioon to search for. - * @param flags [IN] Search policy flags. - * @retval true A match was found within the string. - * @retval false No match was found within the string. - * @todo Document me. - */ - template - inline bool - regex_search(const basic_string<_Ch_type, _Ch_traits, - _String_allocator>& __s, - const basic_regex<_Ch_type, _Rx_traits>& __e, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { return regex_search(__s.begin(), __s.end(), __e, __flags); } - - /** - * @brief Searches for a regular expression within a string. - * @param s [IN] A C++ string to search for the regex. - * @param m [OUT] The set of regex mnatches. - * @param e [IN] The regex to search for in @p s. - * @param f [IN] The search flags. - * @retval true A match was found within the string. - * @retval false No match was found within the string, the content of %m is - * undefined. - */ - template - inline bool - regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, - match_results::const_iterator, _Allocator>& __m, - const basic_regex<_Ch_type, _Rx_traits>& __e, - regex_constants::match_flag_type __f - = regex_constants::match_default) - { return regex_search(__s.begin(), __s.end(), __m, __e, __f); } - - // [7.11.4] Function template regex_replace - /** - * @todo Implement this function. - * @todo Document this function. - */ - template - inline _Out_iter - regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, - const basic_regex<_Ch_type, _Rx_traits>& __e, - const basic_string<_Ch_type>& __fmt, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { return __out; } - - /** - * @todo Document me. - */ - template - inline basic_string<_Ch_type> - regex_replace(const basic_string<_Ch_type>& __s, - const basic_regex<_Ch_type, _Rx_traits>& __e, - const basic_string<_Ch_type>& __fmt, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { - std::string __result; - regex_replace(std::back_inserter(__result), - __s.begin(), __s.end(), __e, __fmt, __flags); - return __result; - } - - // [7.12.1] Class template regex_iterator - /** - * An iterator adaptor that will provide repeated calls of regex_search over - * a range until no more matches remain. - */ - template::value_type, - typename _Rx_traits = regex_traits<_Ch_type> > - class regex_iterator - { - public: - typedef basic_regex<_Ch_type, _Rx_traits> regex_type; - typedef match_results<_Bi_iter> value_type; - typedef std::ptrdiff_t difference_type; - typedef const value_type* pointer; - typedef const value_type& reference; - typedef std::forward_iterator_tag iterator_category; - - public: - /** - * @brief Provides a singular iterator, useful for indicating - * one-past-the-end of a range. - * @todo Implement this function. - * @todo Document this function. - */ - regex_iterator(); - - /** - * Constructs a %regex_iterator... - * @param a [IN] The start of a text range to search. - * @param b [IN] One-past-the-end of the text range to search. - * @param re [IN] The regular expression to match. - * @param m [IN] Policy flags for match rules. - * @todo Implement this function. - * @todo Document this function. - */ - regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, - regex_constants::match_flag_type __m - = regex_constants::match_default); - - /** - * Copy constructs a %regex_iterator. - * @todo Implement this function. - * @todo Document this function. - */ - regex_iterator(const regex_iterator& __rhs); - - /** - * @todo Implement this function. - * @todo Document this function. - */ - regex_iterator& - operator=(const regex_iterator& __rhs); - - /** - * @todo Implement this function. - * @todo Document this function. - */ - bool - operator==(const regex_iterator& __rhs); - - /** - * @todo Implement this function. - * @todo Document this function. - */ - bool - operator!=(const regex_iterator& __rhs); - - /** - * @todo Implement this function. - * @todo Document this function. - */ - const value_type& - operator*(); - - /** - * @todo Implement this function. - * @todo Document this function. - */ - const value_type* - operator->(); - - /** - * @todo Implement this function. - * @todo Document this function. - */ - regex_iterator& - operator++(); - - /** - * @todo Implement this function. - * @todo Document this function. - */ - regex_iterator - operator++(int); - - private: - // these members are shown for exposition only: - _Bi_iter begin; - _Bi_iter end; - const regex_type* pregex; - regex_constants::match_flag_type flags; - match_results<_Bi_iter> match; - }; - - typedef regex_iterator cregex_iterator; - typedef regex_iterator sregex_iterator; -#ifdef _GLIBCXX_USE_WCHAR_T - typedef regex_iterator wcregex_iterator; - typedef regex_iterator wsregex_iterator; -#endif - - // [7.12.2] Class template regex_token_iterator - /** - * Iterates over submatches in a range (or "splits" a text string). - * - * The purpose of this iterator is to enumerate all, or all specified, - * matches of a regular expression within a text range. The dereferenced - * value of an iterator of this class is a std::tr1::sub_match object. - */ - template::value_type, - typename _Rx_traits = regex_traits<_Ch_type> > - class regex_token_iterator - { - public: - typedef basic_regex<_Ch_type, _Rx_traits> regex_type; - typedef sub_match<_Bi_iter> value_type; - typedef std::ptrdiff_t difference_type; - typedef const value_type* pointer; - typedef const value_type& reference; - typedef std::forward_iterator_tag iterator_category; - - public: - /** - * @brief Default constructs a %regex_token_iterator. - * @todo Implement this function. - * - * A default-constructed %regex_token_iterator is a singular iterator - * that will compare equal to the one-past-the-end value for any - * iterator of the same type. - */ - regex_token_iterator(); - - /** - * Constrcts a %regex_token_iterator... - * @param a [IN] The start of the text to search. - * @param b [IN] One-past-the-eend of the text to search. - * @param re [IN] The regular expression to search for. - * @param submatch [IN] Which submatch to return. There are some - * special values for thsi parameter: - * - -1 each enumerated subexpression does NOT - * match the regular expression (aka field - * splitting) - * - 0 the entire string matching the - * subexpression is returned for each match - * within the text. - * - >0 enumerates only the indicated - * subexpression from a match within the text. - * @param m [IN] Policy flags for match rules. - * - * @todo Implement this function. - * @todo Document this function. - */ - regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, - int __submatch = 0, - regex_constants::match_flag_type __m - = regex_constants::match_default); - - /** - * Constrcts a %regex_token_iterator... - * @param a [IN] The start of the text to search. - * @param b [IN] One-past-the-eend of the text to search. - * @param re [IN] The regular expression to search for. - * @param submatches [IN] A list of subexpressions to return for each - * regular expression match within the text. - * @param m [IN] Policy flags for match rules. - * - * @todo Implement this function. - * @todo Document this function. - */ - regex_token_iterator(_Bi_iter __a, _Bi_iter __b, - const regex_type& __re, - const std::vector& __submatches, - regex_constants::match_flag_type __m - = regex_constants::match_default); - - /** - * Constrcts a %regex_token_iterator... - * @param a [IN] The start of the text to search. - * @param b [IN] One-past-the-eend of the text to search. - * @param re [IN] The regular expression to search for. - * @param submatches [IN] A list of subexpressions to return for each - * regular expression match within the text. - * @param m [IN] Policy flags for match rules. - - * @todo Implement this function. - * @todo Document this function. - */ - template - regex_token_iterator(_Bi_iter __a, _Bi_iter __b, - const regex_type& __re, - const int (&__submatches)[_Nm], - regex_constants::match_flag_type __m - = regex_constants::match_default); - - /** - * @brief Copy constructs a %regex_token_iterator. - * @param rhs [IN] A %regex_token_iterator to copy. - * @todo Implement this function. - */ - regex_token_iterator(const regex_token_iterator& __rhs); - - /** - * @brief Assigns a %regex_token_iterator to another. - * @param rhs [IN] A %regex_token_iterator to copy. - * @todo Implement this function. - */ - regex_token_iterator& - operator=(const regex_token_iterator& __rhs); - - /** - * @brief Compares a %regex_token_iterator to another for equality. - * @todo Implement this function. - */ - bool - operator==(const regex_token_iterator& __rhs); - - /** - * @brief Compares a %regex_token_iterator to another for inequality. - * @todo Implement this function. - */ - bool - operator!=(const regex_token_iterator& __rhs); - - /** - * @brief Dereferences a %regex_token_iterator. - * @todo Implement this function. - */ - const value_type& - operator*(); - - /** - * @brief Selects a %regex_token_iterator member. - * @todo Implement this function. - */ - const value_type* - operator->(); - - /** - * @brief Increments a %regex_token_iterator. - * @todo Implement this function. - */ - regex_token_iterator& - operator++(); - - /** - * @brief Postincrements a %regex_token_iterator. - * @todo Implement this function. - */ - regex_token_iterator - operator++(int); - - private: // data members for exposition only: - typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator; - - position_iterator __position; - const value_type* __result; - value_type __suffix; - std::size_t __n; - std::vector __subs; - }; - - typedef regex_token_iterator cregex_token_iterator; - typedef regex_token_iterator sregex_token_iterator; -#ifdef _GLIBCXX_USE_WCHAR_T - typedef regex_token_iterator wcregex_token_iterator; - typedef regex_token_iterator wsregex_token_iterator; +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif - - /** @} */ // group tr1_regex - -_GLIBCXX_END_NAMESPACE -} -#endif // _TR1_REGEX +#endif // _GLIBCXX_TR1_REGEX diff --git a/libstdc++-v3/include/tr1/riemann_zeta.tcc b/libstdc++-v3/include/tr1/riemann_zeta.tcc index 598d73e..40277c0 100644 --- a/libstdc++-v3/include/tr1/riemann_zeta.tcc +++ b/libstdc++-v3/include/tr1/riemann_zeta.tcc @@ -45,14 +45,15 @@ // (3) Gamma, Exploring Euler's Constant, Julian Havil, // Princeton, 2003. -#ifndef _TR1_RIEMANN_ZETA_TCC -#define _TR1_RIEMANN_ZETA_TCC 1 +#ifndef _GLIBCXX_TR1_RIEMANN_ZETA_TCC +#define _GLIBCXX_TR1_RIEMANN_ZETA_TCC 1 #include "special_function_util.h" namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ // [5.2] Special functions @@ -175,7 +176,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) if (__s < _Tp(0)) { #if _GLIBCXX_USE_C99_MATH_TR1 - if (std::_GLIBCXX_TR1::fmod(__s,_Tp(2)) == _Tp(0)) + if (std::tr1::fmod(__s,_Tp(2)) == _Tp(0)) return _Tp(0); else #endif @@ -185,7 +186,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) * __numeric_constants<_Tp>::__pi(), __s) * std::sin(__numeric_constants<_Tp>::__pi_2() * __s) #if _GLIBCXX_USE_C99_MATH_TR1 - * std::exp(std::_GLIBCXX_TR1::lgamma(_Tp(1) - __s)) + * std::exp(std::tr1::lgamma(_Tp(1) - __s)) #else * std::exp(__log_gamma(_Tp(1) - __s)) #endif @@ -204,9 +205,9 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) for (unsigned int __j = 0; __j <= __i; ++__j) { #if _GLIBCXX_USE_C99_MATH_TR1 - _Tp __bincoeff = std::_GLIBCXX_TR1::lgamma(_Tp(1 + __i)) - - std::_GLIBCXX_TR1::lgamma(_Tp(1 + __j)) - - std::_GLIBCXX_TR1::lgamma(_Tp(1 + __i - __j)); + _Tp __bincoeff = std::tr1::lgamma(_Tp(1 + __i)) + - std::tr1::lgamma(_Tp(1 + __j)) + - std::tr1::lgamma(_Tp(1 + __i - __j)); #else _Tp __bincoeff = __log_gamma(_Tp(1 + __i)) - __log_gamma(_Tp(1 + __j)) @@ -309,7 +310,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) __zeta *= std::pow(_Tp(2) * __numeric_constants<_Tp>::__pi(), __s) * std::sin(__numeric_constants<_Tp>::__pi_2() * __s) #if _GLIBCXX_USE_C99_MATH_TR1 - * std::exp(std::_GLIBCXX_TR1::lgamma(_Tp(1) - __s)) + * std::exp(std::tr1::lgamma(_Tp(1) - __s)) #else * std::exp(__log_gamma(_Tp(1) - __s)) #endif @@ -332,7 +333,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) * __numeric_constants<_Tp>::__pi(), __s) * std::sin(__numeric_constants<_Tp>::__pi_2() * __s) #if _GLIBCXX_USE_C99_MATH_TR1 - * std::_GLIBCXX_TR1::tgamma(_Tp(1) - __s) + * std::tr1::tgamma(_Tp(1) - __s) #else * std::exp(__log_gamma(_Tp(1) - __s)) #endif @@ -387,9 +388,9 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) for (unsigned int __j = 0; __j <= __i; ++__j) { #if _GLIBCXX_USE_C99_MATH_TR1 - _Tp __bincoeff = std::_GLIBCXX_TR1::lgamma(_Tp(1 + __i)) - - std::_GLIBCXX_TR1::lgamma(_Tp(1 + __j)) - - std::_GLIBCXX_TR1::lgamma(_Tp(1 + __i - __j)); + _Tp __bincoeff = std::tr1::lgamma(_Tp(1 + __i)) + - std::tr1::lgamma(_Tp(1 + __j)) + - std::tr1::lgamma(_Tp(1 + __i - __j)); #else _Tp __bincoeff = __log_gamma(_Tp(1 + __i)) - __log_gamma(_Tp(1 + __j)) @@ -443,7 +444,7 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) /* @} */ // group tr1_math_spec_func -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_RIEMANN_ZETA_TCC +#endif // _GLIBCXX_TR1_RIEMANN_ZETA_TCC diff --git a/libstdc++-v3/include/tr1/special_function_util.h b/libstdc++-v3/include/tr1/special_function_util.h index ac55165..2f33c39 100644 --- a/libstdc++-v3/include/tr1/special_function_util.h +++ b/libstdc++-v3/include/tr1/special_function_util.h @@ -39,13 +39,14 @@ // Written by Edward Smith-Rowland based on numerous mathematics books. -#ifndef _TR1_SPECIAL_FUNCTION_UTIL_H -#define _TR1_SPECIAL_FUNCTION_UTIL_H 1 +#ifndef _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H +#define _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 1 // namespace std::tr1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) +namespace tr1 +{ namespace __detail { @@ -148,8 +149,8 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) } // namespace __detail -_GLIBCXX_END_NAMESPACE +} } -#endif // _TR1_SPECIAL_FUNCTION_UTIL_H +#endif // _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H diff --git a/libstdc++-v3/include/tr1/stdlib.h b/libstdc++-v3/include/tr1/stdlib.h index 0075cc7..50c5e21 100644 --- a/libstdc++-v3/include/tr1/stdlib.h +++ b/libstdc++-v3/include/tr1/stdlib.h @@ -31,8 +31,8 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_STDLIB_H -#define _TR1_STDLIB_H 1 +#ifndef _GLIBCXX_TR1_STDLIB_H +#define _GLIBCXX_TR1_STDLIB_H 1 #include @@ -40,17 +40,18 @@ #if _GLIBCXX_USE_C99 -using std::_GLIBCXX_TR1::atoll; -using std::_GLIBCXX_TR1::strtoll; -using std::_GLIBCXX_TR1::strtoull; +using std::tr1::atoll; +using std::tr1::strtoll; +using std::tr1::strtoull; -using std::_GLIBCXX_TR1::abs; +using std::tr1::abs; #if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC -using std::_GLIBCXX_TR1::div; +using std::tr1::div; #endif #endif #endif -#endif +#endif // _GLIBCXX_TR1_STDLIB_H + diff --git a/libstdc++-v3/include/tr1/tgmath.h b/libstdc++-v3/include/tr1/tgmath.h index 90c8a63..1bf9321 100644 --- a/libstdc++-v3/include/tr1/tgmath.h +++ b/libstdc++-v3/include/tr1/tgmath.h @@ -1,6 +1,6 @@ // TR1 tgmath.h -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_TGMATH_H -#define _TR1_TGMATH_H 1 +#ifndef _GLIBCXX_TR1_TGMATH_H +#define _GLIBCXX_TR1_TGMATH_H 1 #include -#endif +#endif // _GLIBCXX_TR1_TGMATH_H diff --git a/libstdc++-v3/include/tr1/tuple b/libstdc++-v3/include/tr1/tuple index 7beef19..0c7ed3f 100644 --- a/libstdc++-v3/include/tr1/tuple +++ b/libstdc++-v3/include/tr1/tuple @@ -34,405 +34,29 @@ // Chris Jefferson // Variadic Templates support by Douglas Gregor -#ifndef _TR1_TUPLE -#define _TR1_TUPLE 1 +#ifndef _GLIBCXX_TR1_TUPLE +#define _GLIBCXX_TR1_TUPLE 1 #pragma GCC system_header -#include - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - template - class reference_wrapper; - - // Adds a const reference to a non-reference type. - template - struct __add_c_ref - { typedef const _Tp& type; }; - - template - struct __add_c_ref<_Tp&> - { typedef _Tp& type; }; - - // Adds a reference to a non-reference type. - template - struct __add_ref - { typedef _Tp& type; }; - - template - struct __add_ref<_Tp&> - { typedef _Tp& type; }; - - /** - * @if maint - * Contains the actual implementation of the @c tuple template, stored - * as a recursive inheritance hierarchy from the first element (most - * derived class) to the last (least derived class). The @c Idx - * parameter gives the 0-based index of the element stored at this - * point in the hierarchy; we use it to implement a constant-time - * get() operation. - * @endif - */ - template - struct _Tuple_impl; - - /** - * @if maint - * Zero-element tuple implementation. This is the basis case for the - * inheritance recursion. - * @endif maint - */ - template - struct _Tuple_impl<_Idx> { }; - - /** - * @if maint - * Recursive tuple implementation. Here we store the @c Head element - * and derive from a @c Tuple_impl containing the remaining elements - * (which contains the @c Tail). - * @endif - */ - template - struct _Tuple_impl<_Idx, _Head, _Tail...> - : public _Tuple_impl<_Idx + 1, _Tail...> - { - typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited; - - _Head _M_head; - - _Inherited& _M_tail() { return *this; } - const _Inherited& _M_tail() const { return *this; } - - _Tuple_impl() : _Inherited(), _M_head() { } - - explicit - _Tuple_impl(typename __add_c_ref<_Head>::type __head, - typename __add_c_ref<_Tail>::type... __tail) - : _Inherited(__tail...), _M_head(__head) { } - - template - _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in) - : _Inherited(__in._M_tail()), _M_head(__in._M_head) { } - - _Tuple_impl(const _Tuple_impl& __in) - : _Inherited(__in._M_tail()), _M_head(__in._M_head) { } - - template - _Tuple_impl& - operator=(const _Tuple_impl<_Idx, _UElements...>& __in) - { - _M_head = __in._M_head; - _M_tail() = __in._M_tail(); - return *this; - } - - _Tuple_impl& - operator=(const _Tuple_impl& __in) - { - _M_head = __in._M_head; - _M_tail() = __in._M_tail(); - return *this; - } - }; - - template - class tuple : public _Tuple_impl<0, _Elements...> - { - typedef _Tuple_impl<0, _Elements...> _Inherited; - - public: - tuple() : _Inherited() { } - - explicit - tuple(typename __add_c_ref<_Elements>::type... __elements) - : _Inherited(__elements...) { } - - template - tuple(const tuple<_UElements...>& __in) - : _Inherited(__in) { } - - tuple(const tuple& __in) - : _Inherited(__in) { } - - template - tuple& - operator=(const tuple<_UElements...>& __in) - { - static_cast<_Inherited&>(*this) = __in; - return *this; - } - - tuple& - operator=(const tuple& __in) - { - static_cast<_Inherited&>(*this) = __in; - return *this; - } - }; - - template<> class tuple<> { }; - - // 2-element tuple, with construction and assignment from a pair. - template - class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2> - { - typedef _Tuple_impl<0, _T1, _T2> _Inherited; - - public: - tuple() : _Inherited() { } - - explicit - tuple(typename __add_c_ref<_T1>::type __a1, - typename __add_c_ref<_T2>::type __a2) - : _Inherited(__a1, __a2) { } - - template - tuple(const tuple<_U1, _U2>& __in) - : _Inherited(__in) { } - - tuple(const tuple& __in) - : _Inherited(__in) { } - - template - tuple(const pair<_U1, _U2>& __in) - : _Inherited(_Tuple_impl<0, - typename __add_c_ref<_U1>::type, - typename __add_c_ref<_U2>::type>(__in.first, - __in.second)) - { } - - template - tuple& - operator=(const tuple<_U1, _U2>& __in) - { - static_cast<_Inherited&>(*this) = __in; - return *this; - } - - tuple& - operator=(const tuple& __in) - { - static_cast<_Inherited&>(*this) = __in; - return *this; - } - - template - tuple& - operator=(const pair<_U1, _U2>& __in) - { - this->_M_head = __in.first; - this->_M_tail()._M_head = __in.second; - return *this; - } - }; - - - /// Gives the type of the ith element of a given tuple type. - template - struct tuple_element; - - /** - * @if maint - * Recursive case for tuple_element: strip off the first element in - * the tuple and retrieve the (i-1)th element of the remaining tuple. - * @endif - */ - template - struct tuple_element<__i, tuple<_Head, _Tail...> > - : tuple_element<__i - 1, tuple<_Tail...> > { }; - - /** - * @if maint - * Basis case for tuple_element: The first element is the one we're seeking. - * @endif - */ - template - struct tuple_element<0, tuple<_Head, _Tail...> > - { - typedef _Head type; - }; - - /// Finds the size of a given tuple type. - template - struct tuple_size; - - /// @brief class tuple_size - template - struct tuple_size > - { - static const int value = sizeof...(_Elements); - }; - - template - const int tuple_size >::value; - - template - inline typename __add_ref<_Head>::type - __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) - { - return __t._M_head; - } - - template - inline typename __add_c_ref<_Head>::type - __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) - { - return __t._M_head; - } - - // Return a reference (const reference) to the ith element of a tuple. - // Any const or non-const ref elements are returned with their original type. - template - inline typename __add_ref< - typename tuple_element<__i, tuple<_Elements...> >::type - >::type - get(tuple<_Elements...>& __t) - { - return __get_helper<__i>(__t); - } - - template - inline typename __add_c_ref< - typename tuple_element<__i, tuple<_Elements...> >::type - >::type - get(const tuple<_Elements...>& __t) - { - return __get_helper<__i>(__t); - } - - // This class helps construct the various comparison operations on tuples - template - struct __tuple_compare; - - template - struct __tuple_compare<0, __i, __j, _Tp, _Up> - { - static bool __eq(const _Tp& __t, const _Up& __u) - { - return (get<__i>(__t) == get<__i>(__u) && - __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u)); - } - - static bool __less(const _Tp& __t, const _Up& __u) - { - return ((get<__i>(__t) < get<__i>(__u)) - || !(get<__i>(__u) < get<__i>(__t)) && - __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u)); - } - }; - - template - struct __tuple_compare<0, __i, __i, _Tp, _Up> - { - static bool __eq(const _Tp&, const _Up&) - { return true; } - - static bool __less(const _Tp&, const _Up&) - { return false; } - }; - - template - bool - operator==(const tuple<_TElements...>& __t, - const tuple<_UElements...>& __u) - { - typedef tuple<_TElements...> _Tp; - typedef tuple<_UElements...> _Up; - return (__tuple_compare::value - tuple_size<_Tp>::value, - 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u)); - } - - template - bool - operator<(const tuple<_TElements...>& __t, - const tuple<_UElements...>& __u) - { - typedef tuple<_TElements...> _Tp; - typedef tuple<_UElements...> _Up; - return (__tuple_compare::value - tuple_size<_Tp>::value, - 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u)); - } - - template - bool - operator!=(const tuple<_TElements...>& __t, - const tuple<_UElements...>& __u) - { return !(__t == __u); } - - template - bool - operator>(const tuple<_TElements...>& __t, - const tuple<_UElements...>& __u) - { return __u < __t; } - - template - bool - operator<=(const tuple<_TElements...>& __t, - const tuple<_UElements...>& __u) - { return !(__u < __t); } - - template - bool - operator>=(const tuple<_TElements...>& __t, - const tuple<_UElements...>& __u) - { return !(__t < __u); } - - // Helper which adds a reference to a type when given a reference_wrapper - template - struct __strip_reference_wrapper - { - typedef _Tp __type; - }; - - template - struct __strip_reference_wrapper > - { - typedef _Tp& __type; - }; - - template - struct __strip_reference_wrapper > - { - typedef _Tp& __type; - }; - - template - inline tuple::__type...> - make_tuple(_Elements... __args) - { - typedef tuple::__type...> - __result_type; - return __result_type(__args...); - } - - template - inline tuple<_Elements&...> - tie(_Elements&... __args) - { - return tuple<_Elements&...>(__args...); - } - - // A class (and instance) which can be used in 'tie' when an element - // of a tuple is not required - struct _Swallow_assign - { - template - _Swallow_assign& - operator=(const _Tp&) - { return *this; } - }; - - // TODO: Put this in some kind of shared file. - namespace - { - _Swallow_assign ignore; - }; // anonymous namespace +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif -_GLIBCXX_END_NAMESPACE -} +#include +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif + +#endif // _GLIBCXX_TR1_TUPLE diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 41edc3a..709cbd9 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -31,26 +31,35 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_TYPE_TRAITS -#define _TR1_TYPE_TRAITS 1 +#ifndef _GLIBCXX_TR1_TYPE_TRAITS +#define _GLIBCXX_TR1_TYPE_TRAITS 1 #pragma GCC system_header -#include -#include +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif + +#include + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 +#endif -// namespace std::tr1 namespace std { -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // For use in __is_convertible_simple. - struct __sfinae_types - { - typedef char __one; - typedef struct { char __arr[2]; } __two; - }; - +namespace tr1 +{ #define _DEFINE_SPEC_BODY(_Value) \ : public integral_constant { }; @@ -59,193 +68,29 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) struct _Spec \ _DEFINE_SPEC_BODY(_Value) -#define _DEFINE_SPEC_1_HELPER(_Spec, _Value) \ - template \ - struct _Spec \ - _DEFINE_SPEC_BODY(_Value) - -#define _DEFINE_SPEC_2_HELPER(_Spec, _Value) \ - template \ - struct _Spec \ - _DEFINE_SPEC_BODY(_Value) - #define _DEFINE_SPEC(_Order, _Trait, _Type, _Value) \ _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type>, _Value) \ _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const>, _Value) \ _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type volatile>, _Value) \ _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const volatile>, _Value) - /// @brief helper classes [4.3]. - template - struct integral_constant - { - static const _Tp value = __v; - typedef _Tp value_type; - typedef integral_constant<_Tp, __v> type; - }; - typedef integral_constant true_type; - typedef integral_constant false_type; - - template - const _Tp integral_constant<_Tp, __v>::value; - - /// @brief primary type categories [4.5.1]. template - struct is_void - : public false_type { }; - _DEFINE_SPEC(0, is_void, void, true) - - template - struct is_integral - : public false_type { }; - _DEFINE_SPEC(0, is_integral, bool, true) - _DEFINE_SPEC(0, is_integral, char, true) - _DEFINE_SPEC(0, is_integral, signed char, true) - _DEFINE_SPEC(0, is_integral, unsigned char, true) -#ifdef _GLIBCXX_USE_WCHAR_T - _DEFINE_SPEC(0, is_integral, wchar_t, true) -#endif - _DEFINE_SPEC(0, is_integral, short, true) - _DEFINE_SPEC(0, is_integral, unsigned short, true) - _DEFINE_SPEC(0, is_integral, int, true) - _DEFINE_SPEC(0, is_integral, unsigned int, true) - _DEFINE_SPEC(0, is_integral, long, true) - _DEFINE_SPEC(0, is_integral, unsigned long, true) - _DEFINE_SPEC(0, is_integral, long long, true) - _DEFINE_SPEC(0, is_integral, unsigned long long, true) - - template - struct is_floating_point - : public false_type { }; - _DEFINE_SPEC(0, is_floating_point, float, true) - _DEFINE_SPEC(0, is_floating_point, double, true) - _DEFINE_SPEC(0, is_floating_point, long double, true) - - template - struct is_array - : public false_type { }; - - template - struct is_array<_Tp[_Size]> - : public true_type { }; - - template - struct is_array<_Tp[]> - : public true_type { }; - - template - struct is_pointer - : public false_type { }; - _DEFINE_SPEC(1, is_pointer, _Tp*, true) - - template - struct is_reference - : public false_type { }; - - template - struct is_reference<_Tp&> - : public true_type { }; - - template - struct is_member_object_pointer - : public false_type { }; - _DEFINE_SPEC(2, is_member_object_pointer, _Tp _Cp::*, - !is_function<_Tp>::value) - - template - struct is_member_function_pointer - : public false_type { }; - _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*, - is_function<_Tp>::value) - - template - struct is_enum - : public integral_constant - { }; - - template - struct is_union - : public integral_constant - { }; - - template - struct is_class - : public integral_constant - { }; - - template - struct __is_function_helper - : public false_type { }; - - template - struct __is_function_helper<_Res(_ArgTypes...)> - : public true_type { }; - - template - struct __is_function_helper<_Res(_ArgTypes......)> - : public true_type { }; - - template - struct is_function - : public integral_constant::type>::value)> - { }; - - /// @brief composite type traits [4.5.2]. - template - struct is_arithmetic - : public integral_constant::value - || is_floating_point<_Tp>::value)> - { }; - - template - struct is_fundamental - : public integral_constant::value - || is_void<_Tp>::value)> - { }; - - template - struct is_object - : public integral_constant::value - || is_reference<_Tp>::value - || is_void<_Tp>::value)> - { }; - - template - struct is_scalar - : public integral_constant::value - || is_enum<_Tp>::value - || is_pointer<_Tp>::value - || is_member_pointer<_Tp>::value)> - { }; - - template - struct is_compound - : public integral_constant::value> { }; - - template - struct is_member_pointer - : public integral_constant::value - || is_member_function_pointer<_Tp>::value)> - { }; - - /// @brief type properties [4.5.3]. - template - struct is_const + struct is_signed : public false_type { }; + _DEFINE_SPEC(0, is_signed, signed char, true) + _DEFINE_SPEC(0, is_signed, short, true) + _DEFINE_SPEC(0, is_signed, int, true) + _DEFINE_SPEC(0, is_signed, long, true) + _DEFINE_SPEC(0, is_signed, long long, true) - template - struct is_const<_Tp const> - : public true_type { }; - template - struct is_volatile + struct is_unsigned : public false_type { }; - - template - struct is_volatile<_Tp volatile> - : public true_type { }; + _DEFINE_SPEC(0, is_unsigned, unsigned char, true) + _DEFINE_SPEC(0, is_unsigned, unsigned short, true) + _DEFINE_SPEC(0, is_unsigned, unsigned int, true) + _DEFINE_SPEC(0, is_unsigned, unsigned long, true) + _DEFINE_SPEC(0, is_unsigned, unsigned long long, true) template struct is_pod @@ -253,113 +98,39 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) { }; template - struct is_empty - : public integral_constant - { }; - - template - struct is_polymorphic - : public integral_constant - { }; - - template - struct is_abstract - : public integral_constant - { }; - - template struct has_trivial_constructor - : public integral_constant::value> { }; + : public integral_constant::value> + { }; template struct has_trivial_copy - : public integral_constant::value> { }; + : public integral_constant::value> + { }; template struct has_trivial_assign - : public integral_constant::value> { }; + : public integral_constant::value> + { }; template struct has_trivial_destructor - : public integral_constant::value> { }; + : public integral_constant::value> + { }; template struct has_nothrow_constructor - : public integral_constant::value> { }; + : public integral_constant::value> + { }; template struct has_nothrow_copy - : public integral_constant::value> { }; - - template - struct has_nothrow_assign - : public integral_constant::value> { }; - - template - struct has_virtual_destructor - : public integral_constant + : public integral_constant::value> { }; - template - struct is_signed - : public false_type { }; - _DEFINE_SPEC(0, is_signed, signed char, true) - _DEFINE_SPEC(0, is_signed, short, true) - _DEFINE_SPEC(0, is_signed, int, true) - _DEFINE_SPEC(0, is_signed, long, true) - _DEFINE_SPEC(0, is_signed, long long, true) - - template - struct is_unsigned - : public false_type { }; - _DEFINE_SPEC(0, is_unsigned, unsigned char, true) - _DEFINE_SPEC(0, is_unsigned, unsigned short, true) - _DEFINE_SPEC(0, is_unsigned, unsigned int, true) - _DEFINE_SPEC(0, is_unsigned, unsigned long, true) - _DEFINE_SPEC(0, is_unsigned, unsigned long long, true) - template - struct alignment_of - : public integral_constant { }; - - template - struct rank - : public integral_constant { }; - - template - struct rank<_Tp[_Size]> - : public integral_constant::value> { }; - - template - struct rank<_Tp[]> - : public integral_constant::value> { }; - - template - struct extent - : public integral_constant { }; - - template - struct extent<_Tp[_Size], _Uint> - : public integral_constant::value> - { }; - - template - struct extent<_Tp[], _Uint> - : public integral_constant::value> + struct has_nothrow_assign + : public integral_constant::value> { }; - - /// @brief relationships between types [4.6]. - template - struct is_same - : public false_type { }; - - template - struct is_same<_Tp, _Tp> - : public true_type { }; template struct __is_base_of_helper @@ -427,188 +198,10 @@ _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) __is_convertible_helper<_From, _To>::__value> { }; - /// @brief const-volatile modifications [4.7.1]. - template - struct remove_const - { typedef _Tp type; }; - - template - struct remove_const<_Tp const> - { typedef _Tp type; }; - - template - struct remove_volatile - { typedef _Tp type; }; - - template - struct remove_volatile<_Tp volatile> - { typedef _Tp type; }; - - template - struct remove_cv - { - typedef typename - remove_const::type>::type type; - }; - - template - struct add_const - { typedef _Tp const type; }; - - template - struct add_volatile - { typedef _Tp volatile type; }; - - template - struct add_cv - { - typedef typename - add_const::type>::type type; - }; - - /// @brief reference modifications [4.7.2]. - template - struct remove_reference - { typedef _Tp type; }; - - template - struct remove_reference<_Tp&> - { typedef _Tp type; }; - - // NB: Careful with reference to void. - template::value - || is_reference<_Tp>::value)> - struct __add_reference_helper - { typedef _Tp& type; }; - - template - struct __add_reference_helper<_Tp, true> - { typedef _Tp type; }; - - template - struct add_reference - : public __add_reference_helper<_Tp> - { }; - - /// @brief array modifications [4.7.3]. - template - struct remove_extent - { typedef _Tp type; }; - - template - struct remove_extent<_Tp[_Size]> - { typedef _Tp type; }; - - template - struct remove_extent<_Tp[]> - { typedef _Tp type; }; - - template - struct remove_all_extents - { typedef _Tp type; }; - - template - struct remove_all_extents<_Tp[_Size]> - { typedef typename remove_all_extents<_Tp>::type type; }; - - template - struct remove_all_extents<_Tp[]> - { typedef typename remove_all_extents<_Tp>::type type; }; - - /// @brief pointer modifications [4.7.4]. -#undef _DEFINE_SPEC_BODY -#define _DEFINE_SPEC_BODY(_Value) \ - { typedef _Tp type; }; - - template - struct remove_pointer - { typedef _Tp type; }; - _DEFINE_SPEC(1, remove_pointer, _Tp*, false) - - template - struct add_pointer - { typedef typename remove_reference<_Tp>::type* type; }; - - /// @brief other transformations [4.8]. - - // Due to c++/19163 and c++/17743, for the time being we cannot use - // the correct, neat implementation :-( - // - // template - // struct aligned_storage - // { typedef char type[_Len] __attribute__((__aligned__(_Align))); } - // - // Temporary workaround, useful for Align up to 32: - template - struct aligned_storage { }; - - template - struct aligned_storage<_Len, 1> - { - union type - { - unsigned char __data[_Len]; - char __align __attribute__((__aligned__(1))); - }; - }; - - template - struct aligned_storage<_Len, 2> - { - union type - { - unsigned char __data[_Len]; - char __align __attribute__((__aligned__(2))); - }; - }; - - template - struct aligned_storage<_Len, 4> - { - union type - { - unsigned char __data[_Len]; - char __align __attribute__((__aligned__(4))); - }; - }; - - template - struct aligned_storage<_Len, 8> - { - union type - { - unsigned char __data[_Len]; - char __align __attribute__((__aligned__(8))); - }; - }; - - template - struct aligned_storage<_Len, 16> - { - union type - { - unsigned char __data[_Len]; - char __align __attribute__((__aligned__(16))); - }; - }; - - template - struct aligned_storage<_Len, 32> - { - union type - { - unsigned char __data[_Len]; - char __align __attribute__((__aligned__(32))); - }; - }; - #undef _DEFINE_SPEC_0_HELPER -#undef _DEFINE_SPEC_1_HELPER -#undef _DEFINE_SPEC_2_HELPER #undef _DEFINE_SPEC #undef _DEFINE_SPEC_BODY - -_GLIBCXX_END_NAMESPACE +} } -#endif +#endif // _GLIBCXX_TR1_TYPE_TRAITS diff --git a/libstdc++-v3/include/tr1/type_traitsfwd.h b/libstdc++-v3/include/tr1/type_traitsfwd.h deleted file mode 100644 index 9cf2de6..0000000 --- a/libstdc++-v3/include/tr1/type_traitsfwd.h +++ /dev/null @@ -1,222 +0,0 @@ -// TR1 type_traits -*- C++ -*- - -// Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/** @file tr1/type_traitsfwd.h - * This is an internal header file, included by other library headers. - * You should not attempt to use it directly. - */ - -#ifndef _TYPE_TRAITSFWD_H -#define _TYPE_TRAITSFWD_H 1 - -#include - -// namespace std::tr1 -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - /// @brief helper classes [4.3]. - template - struct integral_constant; - typedef integral_constant true_type; - typedef integral_constant false_type; - - /// @brief primary type categories [4.5.1]. - template - struct is_void; - - template - struct is_integral; - - template - struct is_floating_point; - - template - struct is_array; - - template - struct is_pointer; - - template - struct is_reference; - - template - struct is_member_object_pointer; - - template - struct is_member_function_pointer; - - template - struct is_enum; - - template - struct is_union; - - template - struct is_class; - - template - struct is_function; - - /// @brief composite type traits [4.5.2]. - template - struct is_arithmetic; - - template - struct is_fundamental; - - template - struct is_object; - - template - struct is_scalar; - - template - struct is_compound; - - template - struct is_member_pointer; - - /// @brief type properties [4.5.3]. - template - struct is_const; - - template - struct is_volatile; - - template - struct is_pod; - - template - struct is_empty; - - template - struct is_polymorphic; - - template - struct is_abstract; - - template - struct has_trivial_constructor; - - template - struct has_trivial_copy; - - template - struct has_trivial_assign; - - template - struct has_trivial_destructor; - - template - struct has_nothrow_constructor; - - template - struct has_nothrow_copy; - - template - struct has_nothrow_assign; - - template - struct has_virtual_destructor; - - template - struct is_signed; - - template - struct is_unsigned; - - template - struct alignment_of; - - template - struct rank; - - template - struct extent; - - /// @brief relationships between types [4.6]. - template - struct is_same; - - template - struct is_convertible; - - template - struct is_base_of; - - /// @brief const-volatile modifications [4.7.1]. - template - struct remove_const; - - template - struct remove_volatile; - - template - struct remove_cv; - - template - struct add_const; - - template - struct add_volatile; - - template - struct add_cv; - - /// @brief reference modifications [4.7.2]. - template - struct remove_reference; - - template - struct add_reference; - - /// @brief array modifications [4.7.3]. - template - struct remove_extent; - - template - struct remove_all_extents; - - /// @brief pointer modifications [4.7.4]. - template - struct remove_pointer; - - template - struct add_pointer; - - /// @brief other transformations [4.8]. - template - struct aligned_storage; - -_GLIBCXX_END_NAMESPACE -} - -#endif diff --git a/libstdc++-v3/include/tr1/unordered_map b/libstdc++-v3/include/tr1/unordered_map index 3aca9f5..85e8f00 100644 --- a/libstdc++-v3/include/tr1/unordered_map +++ b/libstdc++-v3/include/tr1/unordered_map @@ -31,206 +31,37 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_UNORDERED_MAP -#define _TR1_UNORDERED_MAP 1 - -#include +#ifndef _GLIBCXX_TR1_UNORDERED_MAP +#define _GLIBCXX_TR1_UNORDERED_MAP 1 + +#pragma GCC system_header + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif + +#include +#include +#include +#include // lower_bound +#include +#include // equal_to, _Identity, _Select1st +#include #include - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // XXX When we get typedef templates these class definitions - // will be unnecessary. - template, - class _Pred = std::equal_to<_Key>, - class _Alloc = std::allocator >, - bool __cache_hash_code = false> - class __unordered_map - : public _Hashtable<_Key, std::pair, _Alloc, - std::_Select1st >, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, false, true> - { - typedef _Hashtable<_Key, std::pair, _Alloc, - std::_Select1st >, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, false, true> - _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - __unordered_map(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), - __eql, std::_Select1st >(), __a) - { } - - template - __unordered_map(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), - __eql, std::_Select1st >(), __a) - { } - }; - - template, - class _Pred = std::equal_to<_Key>, - class _Alloc = std::allocator >, - bool __cache_hash_code = false> - class __unordered_multimap - : public _Hashtable<_Key, std::pair, - _Alloc, - std::_Select1st >, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, false, false> - { - typedef _Hashtable<_Key, std::pair, - _Alloc, - std::_Select1st >, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, false, false> - _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - __unordered_multimap(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), - __eql, std::_Select1st >(), __a) - { } - - - template - __unordered_multimap(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), - __eql, std::_Select1st >(), __a) - { } - }; - - template - inline void - swap(__unordered_map<_Key, _Tp, _Hash, _Pred, - _Alloc, __cache_hash_code>& __x, - __unordered_map<_Key, _Tp, _Hash, _Pred, - _Alloc, __cache_hash_code>& __y) - { __x.swap(__y); } - - template - inline void - swap(__unordered_multimap<_Key, _Tp, _Hash, _Pred, - _Alloc, __cache_hash_code>& __x, - __unordered_multimap<_Key, _Tp, _Hash, _Pred, - _Alloc, __cache_hash_code>& __y) - { __x.swap(__y); } - - - template, - class _Pred = std::equal_to<_Key>, - class _Alloc = std::allocator > > - class unordered_map - : public __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> - { - typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - unordered_map(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __eql, __a) - { } - - template - unordered_map(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __eql, __a) - { } - }; - - template, - class _Pred = std::equal_to<_Key>, - class _Alloc = std::allocator > > - class unordered_multimap - : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> - { - typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - unordered_multimap(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __eql, __a) - { } - - - template - unordered_multimap(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __eql, __a) - { } - }; - -_GLIBCXX_END_NAMESPACE -} - -#endif // _TR1_UNORDERED_MAP +#include + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 +#endif + +#endif // _GLIBCXX_TR1_UNORDERED_MAP diff --git a/libstdc++-v3/include/tr1/unordered_set b/libstdc++-v3/include/tr1/unordered_set index bd56ead..35c605f 100644 --- a/libstdc++-v3/include/tr1/unordered_set +++ b/libstdc++-v3/include/tr1/unordered_set @@ -31,204 +31,37 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_UNORDERED_SET -#define _TR1_UNORDERED_SET 1 - -#include +#ifndef _GLIBCXX_TR1_UNORDERED_SET +#define _GLIBCXX_TR1_UNORDERED_SET 1 + +#pragma GCC system_header + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif + +#include +#include +#include +#include // lower_bound +#include +#include // equal_to, _Identity, _Select1st +#include #include - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - // XXX When we get typedef templates these class definitions - // will be unnecessary. - template, - class _Pred = std::equal_to<_Value>, - class _Alloc = std::allocator<_Value>, - bool __cache_hash_code = false> - class __unordered_set - : public _Hashtable<_Value, _Value, _Alloc, - std::_Identity<_Value>, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, true, true> - { - typedef _Hashtable<_Value, _Value, _Alloc, - std::_Identity<_Value>, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, true, true> - _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - __unordered_set(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), __eql, - std::_Identity<_Value>(), __a) - { } - - template - __unordered_set(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), __eql, - std::_Identity<_Value>(), __a) - { } - }; - - template, - class _Pred = std::equal_to<_Value>, - class _Alloc = std::allocator<_Value>, - bool __cache_hash_code = false> - class __unordered_multiset - : public _Hashtable<_Value, _Value, _Alloc, - std::_Identity<_Value>, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, true, false> - { - typedef _Hashtable<_Value, _Value, _Alloc, - std::_Identity<_Value>, _Pred, - _Hash, __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, - __cache_hash_code, true, false> - _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - __unordered_multiset(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), __eql, - std::_Identity<_Value>(), __a) - { } - - - template - __unordered_multiset(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), - __detail::_Default_ranged_hash(), __eql, - std::_Identity<_Value>(), __a) - { } - }; - - template - inline void - swap (__unordered_set<_Value, _Hash, _Pred, - _Alloc, __cache_hash_code>& __x, - __unordered_set<_Value, _Hash, _Pred, - _Alloc, __cache_hash_code>& __y) - { __x.swap(__y); } - - template - inline void - swap(__unordered_multiset<_Value, _Hash, _Pred, - _Alloc, __cache_hash_code>& __x, - __unordered_multiset<_Value, _Hash, _Pred, - _Alloc, __cache_hash_code>& __y) - { __x.swap(__y); } - - - template, - class _Pred = std::equal_to<_Value>, - class _Alloc = std::allocator<_Value> > - class unordered_set - : public __unordered_set<_Value, _Hash, _Pred, _Alloc> - { - typedef __unordered_set<_Value, _Hash, _Pred, _Alloc> _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - unordered_set(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __eql, __a) - { } - - template - unordered_set(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __eql, __a) - { } - }; - - template, - class _Pred = std::equal_to<_Value>, - class _Alloc = std::allocator<_Value> > - class unordered_multiset - : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc> - { - typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc> _Base; - - public: - typedef typename _Base::size_type size_type; - typedef typename _Base::hasher hasher; - typedef typename _Base::key_equal key_equal; - typedef typename _Base::allocator_type allocator_type; - - explicit - unordered_multiset(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__n, __hf, __eql, __a) - { } - - - template - unordered_multiset(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) - : _Base(__f, __l, __n, __hf, __eql, __a) - { } - }; - -_GLIBCXX_END_NAMESPACE -} - -#endif // _TR1_UNORDERED_SET +#include + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 +#endif + +#endif // _GLIBCXX_TR1_UNORDERED_SET diff --git a/libstdc++-v3/include/tr1/utility b/libstdc++-v3/include/tr1/utility index efe2503..549411f 100644 --- a/libstdc++-v3/include/tr1/utility +++ b/libstdc++-v3/include/tr1/utility @@ -31,72 +31,31 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_UTILITY -#define _TR1_UTILITY 1 +#ifndef _GLIBCXX_TR1_UTILITY +#define _GLIBCXX_TR1_UTILITY 1 -#include +#pragma GCC system_header -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1) - - template class tuple_size; - template class tuple_element; - - // Various functions which give std::pair a tuple-like interface. - template - struct tuple_size > - { static const int value = 2; }; - - template - const int tuple_size >::value; - - template - struct tuple_element<0, std::pair<_Tp1, _Tp2> > - { typedef _Tp1 type; }; - - template - struct tuple_element<1, std::pair<_Tp1, _Tp2> > - { typedef _Tp2 type; }; - - - template struct __pair_get; - - template<> - struct __pair_get<0> - { - template - static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair) - { return __pair.first; } - - template - static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair) - { return __pair.first; } - }; - - template<> - struct __pair_get<1> - { - template - static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair) - { return __pair.second; } - - template - static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair) - { return __pair.second; } - }; - - template - inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& - get(std::pair<_Tp1, _Tp2>& __in) - { return __pair_get<_Int>::__get(__in); } - - template - inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& - get(const std::pair<_Tp1, _Tp2>& __in) - { return __pair_get<_Int>::__const_get(__in); } - -_GLIBCXX_END_NAMESPACE -} +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif +#include +#include +#include + +#if defined(_GLIBCXX_INCLUDE_AS_TR1) +# include +#else +# define _GLIBCXX_INCLUDE_AS_TR1 +# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { +# define _GLIBCXX_END_NAMESPACE_TR1 } +# define _GLIBCXX_TR1 tr1:: +# include +# undef _GLIBCXX_TR1 +# undef _GLIBCXX_END_NAMESPACE_TR1 +# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 +# undef _GLIBCXX_INCLUDE_AS_TR1 #endif + +#endif // _GLIBCXX_TR1_UTILITY diff --git a/libstdc++-v3/include/tr1/wchar.h b/libstdc++-v3/include/tr1/wchar.h index 00fb8a0..f14a47d 100644 --- a/libstdc++-v3/include/tr1/wchar.h +++ b/libstdc++-v3/include/tr1/wchar.h @@ -1,6 +1,6 @@ // TR1 wchar.h -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_WCHAR_H -#define _TR1_WCHAR_H 1 +#ifndef _GLIBCXX_TR1_WCHAR_H +#define _GLIBCXX_TR1_WCHAR_H 1 #include -#endif +#endif // _GLIBCXX_TR1_WCHAR_H diff --git a/libstdc++-v3/include/tr1/wctype.h b/libstdc++-v3/include/tr1/wctype.h index 9ef23cd..1337c9b 100644 --- a/libstdc++-v3/include/tr1/wctype.h +++ b/libstdc++-v3/include/tr1/wctype.h @@ -1,6 +1,6 @@ // TR1 wctype.h -*- C++ -*- -// Copyright (C) 2006 Free Software Foundation, Inc. +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,9 +31,9 @@ * This is a TR1 C++ Library header. */ -#ifndef _TR1_WCTYPE_H -#define _TR1_WCTYPE_H 1 +#ifndef _GLIBCXX_TR1_WCTYPE_H +#define _GLIBCXX_TR1_WCTYPE_H 1 #include -#endif +#endif // _GLIBCXX_TR1_WCTYPE_H diff --git a/libstdc++-v3/include/tr1_impl/array b/libstdc++-v3/include/tr1_impl/array new file mode 100644 index 0000000..0fda088 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/array @@ -0,0 +1,239 @@ +// class template array -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/array + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + /// @brief struct array [6.2.2]. + /// NB: Requires complete type _Tp. + template + struct array + { + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + // Support for zero-sized arrays mandatory. + value_type _M_instance[_Nm ? _Nm : 1] __attribute__((__aligned__)); + + // No explicit construct/copy/destroy for aggregate type. + + void + assign(const value_type& __u) + { std::fill_n(begin(), size(), __u); } + + void + swap(array& __other) + { std::swap_ranges(begin(), end(), __other.begin()); } + + // Iterators. + iterator + begin() + { return iterator(&_M_instance[0]); } + + const_iterator + begin() const + { return const_iterator(&_M_instance[0]); } + + iterator + end() + { return iterator(&_M_instance[_Nm]); } + + const_iterator + end() const + { return const_iterator(&_M_instance[_Nm]); } + + reverse_iterator + rbegin() + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + + // Capacity. + size_type + size() const { return _Nm; } + + size_type + max_size() const { return _Nm; } + + bool + empty() const { return size() == 0; } + + // Element access. + reference + operator[](size_type __n) + { return _M_instance[__n]; } + + const_reference + operator[](size_type __n) const + { return _M_instance[__n]; } + + reference + at(size_type __n) + { + _M_check<_Nm>(__n); + return _M_instance[__n]; + } + + const_reference + at(size_type __n) const + { + _M_check<_Nm>(__n); + return _M_instance[__n]; + } + + reference + front() + { return *begin(); } + + const_reference + front() const + { return *begin(); } + + reference + back() + { return _Nm ? *(end() - 1) : *end(); } + + const_reference + back() const + { return _Nm ? *(end() - 1) : *end(); } + + _Tp* + data() + { return &_M_instance[0]; } + + const _Tp* + data() const + { return &_M_instance[0]; } + + private: + template + typename __gnu_cxx::__enable_if<_Mm, void>::__type + _M_check(size_type __n) const + { + if (__builtin_expect(__n >= _Mm, false)) + std::__throw_out_of_range(__N("array::_M_check")); + } + + // Avoid "unsigned comparison with zero" warnings. + template + typename __gnu_cxx::__enable_if::__type + _M_check(size_type) const + { std::__throw_out_of_range(__N("array::_M_check")); } + }; + + // Array comparisons. + template + inline bool + operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return std::equal(__one.begin(), __one.end(), __two.begin()); } + + template + inline bool + operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one == __two); } + + template + inline bool + operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) + { + return std::lexicographical_compare(__a.begin(), __a.end(), + __b.begin(), __b.end()); + } + + template + inline bool + operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return __two < __one; } + + template + inline bool + operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one > __two); } + + template + inline bool + operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one < __two); } + + // Specialized algorithms [6.2.2.2]. + template + inline void + swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) + { std::swap_ranges(__one.begin(), __one.end(), __two.begin()); } + + // Tuple interface to class template array [6.2.2.5]. + template class tuple_size; + template class tuple_element; + + template + struct tuple_size > + { static const int value = _Nm; }; + + template + const int tuple_size >::value; + + template + struct tuple_element<_Int, array<_Tp, _Nm> > + { typedef _Tp type; }; + + template + inline _Tp& + get(array<_Tp, _Nm>& __arr) + { return __arr[_Int]; } + + template + inline const _Tp& + get(const array<_Tp, _Nm>& __arr) + { return __arr[_Int]; } + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/boost_shared_ptr.h b/libstdc++-v3/include/tr1_impl/boost_shared_ptr.h new file mode 100644 index 0000000..1a1af5c --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/boost_shared_ptr.h @@ -0,0 +1,1142 @@ +// -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// shared_count.hpp +// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. + +// shared_ptr.hpp +// Copyright (C) 1998, 1999 Greg Colvin and Beman Dawes. +// Copyright (C) 2001, 2002, 2003 Peter Dimov + +// weak_ptr.hpp +// Copyright (C) 2001, 2002, 2003 Peter Dimov + +// enable_shared_from_this.hpp +// Copyright (C) 2002 Peter Dimov + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// GCC Note: based on version 1.32.0 of the Boost library. + +/** @file tr1_impl/boost_shared_ptr.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + class bad_weak_ptr : public std::exception + { + public: + virtual char const* + what() const throw() + { return "tr1::bad_weak_ptr"; } + }; + + // Substitute for bad_weak_ptr object in the case of -fno-exceptions. + inline void + __throw_bad_weak_ptr() + { +#if __EXCEPTIONS + throw bad_weak_ptr(); +#else + __builtin_abort(); +#endif + } + + using __gnu_cxx::_Lock_policy; + using __gnu_cxx::__default_lock_policy; + using __gnu_cxx::_S_single; + using __gnu_cxx::_S_mutex; + using __gnu_cxx::_S_atomic; + + template + struct _Sp_deleter + { + typedef void result_type; + typedef _Tp* argument_type; + + void + operator()(_Tp* __p) const + { delete __p; } + }; + + // Empty helper class except when the template argument is _S_mutex. + template<_Lock_policy _Lp> + class _Mutex_base + { }; + + template<> + class _Mutex_base<_S_mutex> + : public __gnu_cxx::__mutex + { }; + + template<_Lock_policy _Lp = __default_lock_policy> + class _Sp_counted_base + : public _Mutex_base<_Lp> + { + public: + _Sp_counted_base() + : _M_use_count(1), _M_weak_count(1) { } + + virtual + ~_Sp_counted_base() // nothrow + { } + + // Called when _M_use_count drops to zero, to release the resources + // managed by *this. + virtual void + _M_dispose() = 0; // nothrow + + // Called when _M_weak_count drops to zero. + virtual void + _M_destroy() // nothrow + { delete this; } + + virtual void* + _M_get_deleter(const std::type_info&) = 0; + + void + _M_add_ref_copy() + { __gnu_cxx::__atomic_add_dispatch(&_M_use_count, 1); } + + void + _M_add_ref_lock(); + + void + _M_release() // nothrow + { + if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, + -1) == 1) + { + _M_dispose(); +#ifdef __GTHREADS + _GLIBCXX_READ_MEM_BARRIER; + _GLIBCXX_WRITE_MEM_BARRIER; +#endif + if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, + -1) == 1) + _M_destroy(); + } + } + + void + _M_weak_add_ref() // nothrow + { __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1); } + + void + _M_weak_release() // nothrow + { + if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1) + { +#ifdef __GTHREADS + _GLIBCXX_READ_MEM_BARRIER; + _GLIBCXX_WRITE_MEM_BARRIER; +#endif + _M_destroy(); + } + } + + long + _M_get_use_count() const // nothrow + { return _M_use_count; } // XXX is this MT safe? + + private: + _Sp_counted_base(_Sp_counted_base const&); + _Sp_counted_base& operator=(_Sp_counted_base const&); + + _Atomic_word _M_use_count; // #shared + _Atomic_word _M_weak_count; // #weak + (#shared != 0) + }; + + template<> + inline void + _Sp_counted_base<_S_single>:: + _M_add_ref_lock() + { + if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0) + { + _M_use_count = 0; + __throw_bad_weak_ptr(); + } + } + + template<> + inline void + _Sp_counted_base<_S_mutex>:: + _M_add_ref_lock() + { + __gnu_cxx::__scoped_lock sentry(*this); + if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0) + { + _M_use_count = 0; + __throw_bad_weak_ptr(); + } + } + + template<> + inline void + _Sp_counted_base<_S_atomic>:: + _M_add_ref_lock() + { + // Perform lock-free add-if-not-zero operation. + _Atomic_word __count; + do + { + __count = _M_use_count; + if (__count == 0) + __throw_bad_weak_ptr(); + + // Replace the current counter value with the old value + 1, as + // long as it's not changed meanwhile. + } + while (!__sync_bool_compare_and_swap(&_M_use_count, __count, + __count + 1)); + } + + template + class _Sp_counted_base_impl + : public _Sp_counted_base<_Lp> + { + public: + /** + * @brief + * @pre __d(__p) must not throw. + */ + _Sp_counted_base_impl(_Ptr __p, _Deleter __d) + : _M_ptr(__p), _M_del(__d) { } + + virtual void + _M_dispose() // nothrow + { _M_del(_M_ptr); } + + virtual void* + _M_get_deleter(const std::type_info& __ti) + { return __ti == typeid(_Deleter) ? &_M_del : 0; } + + private: + _Sp_counted_base_impl(const _Sp_counted_base_impl&); + _Sp_counted_base_impl& operator=(const _Sp_counted_base_impl&); + + _Ptr _M_ptr; // copy constructor must not throw + _Deleter _M_del; // copy constructor must not throw + }; + + template<_Lock_policy _Lp = __default_lock_policy> + class __weak_count; + + template<_Lock_policy _Lp = __default_lock_policy> + class __shared_count + { + public: + __shared_count() + : _M_pi(0) // nothrow + { } + + template + __shared_count(_Ptr __p, _Deleter __d) : _M_pi(0) + { + try + { + _M_pi = new _Sp_counted_base_impl<_Ptr, _Deleter, _Lp>(__p, __d); + } + catch(...) + { + __d(__p); // Call _Deleter on __p. + __throw_exception_again; + } + } + + // Special case for auto_ptr<_Tp> to provide the strong guarantee. + template + explicit + __shared_count(std::auto_ptr<_Tp>& __r) + : _M_pi(new _Sp_counted_base_impl<_Tp*, + _Sp_deleter<_Tp>, _Lp >(__r.get(), _Sp_deleter<_Tp>())) + { __r.release(); } + + // Throw bad_weak_ptr when __r._M_get_use_count() == 0. + explicit + __shared_count(const __weak_count<_Lp>& __r); + + ~__shared_count() // nothrow + { + if (_M_pi != 0) + _M_pi->_M_release(); + } + + __shared_count(const __shared_count& __r) + : _M_pi(__r._M_pi) // nothrow + { + if (_M_pi != 0) + _M_pi->_M_add_ref_copy(); + } + + __shared_count& + operator=(const __shared_count& __r) // nothrow + { + _Sp_counted_base<_Lp>* __tmp = __r._M_pi; + if (__tmp != _M_pi) + { + if (__tmp != 0) + __tmp->_M_add_ref_copy(); + if (_M_pi != 0) + _M_pi->_M_release(); + _M_pi = __tmp; + } + return *this; + } + + void + _M_swap(__shared_count& __r) // nothrow + { + _Sp_counted_base<_Lp>* __tmp = __r._M_pi; + __r._M_pi = _M_pi; + _M_pi = __tmp; + } + + long + _M_get_use_count() const // nothrow + { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; } + + bool + _M_unique() const // nothrow + { return this->_M_get_use_count() == 1; } + + friend inline bool + operator==(const __shared_count& __a, const __shared_count& __b) + { return __a._M_pi == __b._M_pi; } + + friend inline bool + operator<(const __shared_count& __a, const __shared_count& __b) + { return std::less<_Sp_counted_base<_Lp>*>()(__a._M_pi, __b._M_pi); } + + void* + _M_get_deleter(const std::type_info& __ti) const + { return _M_pi ? _M_pi->_M_get_deleter(__ti) : 0; } + + private: + friend class __weak_count<_Lp>; + + _Sp_counted_base<_Lp>* _M_pi; + }; + + template<_Lock_policy _Lp> + class __weak_count + { + public: + __weak_count() + : _M_pi(0) // nothrow + { } + + __weak_count(const __shared_count<_Lp>& __r) + : _M_pi(__r._M_pi) // nothrow + { + if (_M_pi != 0) + _M_pi->_M_weak_add_ref(); + } + + __weak_count(const __weak_count<_Lp>& __r) + : _M_pi(__r._M_pi) // nothrow + { + if (_M_pi != 0) + _M_pi->_M_weak_add_ref(); + } + + ~__weak_count() // nothrow + { + if (_M_pi != 0) + _M_pi->_M_weak_release(); + } + + __weak_count<_Lp>& + operator=(const __shared_count<_Lp>& __r) // nothrow + { + _Sp_counted_base<_Lp>* __tmp = __r._M_pi; + if (__tmp != 0) + __tmp->_M_weak_add_ref(); + if (_M_pi != 0) + _M_pi->_M_weak_release(); + _M_pi = __tmp; + return *this; + } + + __weak_count<_Lp>& + operator=(const __weak_count<_Lp>& __r) // nothrow + { + _Sp_counted_base<_Lp>* __tmp = __r._M_pi; + if (__tmp != 0) + __tmp->_M_weak_add_ref(); + if (_M_pi != 0) + _M_pi->_M_weak_release(); + _M_pi = __tmp; + return *this; + } + + void + _M_swap(__weak_count<_Lp>& __r) // nothrow + { + _Sp_counted_base<_Lp>* __tmp = __r._M_pi; + __r._M_pi = _M_pi; + _M_pi = __tmp; + } + + long + _M_get_use_count() const // nothrow + { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; } + + friend inline bool + operator==(const __weak_count<_Lp>& __a, const __weak_count<_Lp>& __b) + { return __a._M_pi == __b._M_pi; } + + friend inline bool + operator<(const __weak_count<_Lp>& __a, const __weak_count<_Lp>& __b) + { return std::less<_Sp_counted_base<_Lp>*>()(__a._M_pi, __b._M_pi); } + + private: + friend class __shared_count<_Lp>; + + _Sp_counted_base<_Lp>* _M_pi; + }; + + template<_Lock_policy _Lp> + inline + __shared_count<_Lp>:: + __shared_count(const __weak_count<_Lp>& __r) + : _M_pi(__r._M_pi) + { + if (_M_pi != 0) + _M_pi->_M_add_ref_lock(); + else + __throw_bad_weak_ptr(); + } + + + // Forward declarations. + template + class __shared_ptr; + + template + class __weak_ptr; + + template + class __enable_shared_from_this; + + template + class shared_ptr; + + template + class weak_ptr; + + template + class enable_shared_from_this; + + // Support for enable_shared_from_this. + + // Friend of __enable_shared_from_this. + template<_Lock_policy _Lp, typename _Tp1, typename _Tp2> + void + __enable_shared_from_this_helper(const __shared_count<_Lp>&, + const __enable_shared_from_this<_Tp1, + _Lp>*, const _Tp2*); + + // Friend of enable_shared_from_this. + template + void + __enable_shared_from_this_helper(const __shared_count<>&, + const enable_shared_from_this<_Tp1>*, + const _Tp2*); + + template<_Lock_policy _Lp> + inline void + __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...) + { } + + + struct __static_cast_tag { }; + struct __const_cast_tag { }; + struct __dynamic_cast_tag { }; + + /** + * @class shared_ptr + * + * A smart pointer with reference-counted copy semantics. + * The object pointed to is deleted when the last shared_ptr pointing to + * it is destroyed or reset. + */ + template + class __shared_ptr + { + public: + typedef _Tp element_type; + + /** @brief Construct an empty %__shared_ptr. + * @post use_count()==0 && get()==0 + */ + __shared_ptr() + : _M_ptr(0), _M_refcount() // never throws + { } + + /** @brief Construct a %__shared_ptr that owns the pointer @a __p. + * @param __p A pointer that is convertible to element_type*. + * @post use_count() == 1 && get() == __p + * @throw std::bad_alloc, in which case @c delete @a __p is called. + */ + template + explicit + __shared_ptr(_Tp1* __p) + : _M_ptr(__p), _M_refcount(__p, _Sp_deleter<_Tp1>()) + { + __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) + // __glibcxx_function_requires(_CompleteConcept<_Tp1*>) + __enable_shared_from_this_helper(_M_refcount, __p, __p); + } + + // + // Requirements: _Deleter' copy constructor and destructor must not throw + // + // __shared_ptr will release __p by calling __d(__p) + // + /** @brief Construct a %__shared_ptr that owns the pointer @a __p + * and the deleter @a __d. + * @param __p A pointer. + * @param __d A deleter. + * @post use_count() == 1 && get() == __p + * @throw std::bad_alloc, in which case @a __d(__p) is called. + */ + template + __shared_ptr(_Tp1* __p, _Deleter __d) + : _M_ptr(__p), _M_refcount(__p, __d) + { + __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) + // TODO requires _Deleter CopyConstructible and __d(__p) well-formed + __enable_shared_from_this_helper(_M_refcount, __p, __p); + } + + // generated copy constructor, assignment, destructor are fine. + + /** @brief If @a __r is empty, constructs an empty %__shared_ptr; + * otherwise construct a %__shared_ptr that shares ownership + * with @a __r. + * @param __r A %__shared_ptr. + * @post get() == __r.get() && use_count() == __r.use_count() + * @throw std::bad_alloc, in which case + */ + template + __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) + : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws + { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } + + /** @brief Constructs a %__shared_ptr that shares ownership with @a __r + * and stores a copy of the pointer stored in @a __r. + * @param __r A weak_ptr. + * @post use_count() == __r.use_count() + * @throw bad_weak_ptr when __r.expired(), + * in which case the constructor has no effect. + */ + template + explicit + __shared_ptr(const __weak_ptr<_Tp1, _Lp>& __r) + : _M_refcount(__r._M_refcount) // may throw + { + __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) + // It is now safe to copy __r._M_ptr, as _M_refcount(__r._M_refcount) + // did not throw. + _M_ptr = __r._M_ptr; + } + + /** + * @post use_count() == 1 and __r.get() == 0 + */ + template + explicit + __shared_ptr(std::auto_ptr<_Tp1>& __r) + : _M_ptr(__r.get()), _M_refcount() + { + // TODO requires __r.release() convertible to _Tp*, _Tp1 is complete, + // delete __r.release() well-formed + _Tp1* __tmp = __r.get(); + _M_refcount = __shared_count<_Lp>(__r); + __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp); + } + + template + __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, __static_cast_tag) + : _M_ptr(static_cast(__r._M_ptr)), + _M_refcount(__r._M_refcount) + { } + + template + __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, __const_cast_tag) + : _M_ptr(const_cast(__r._M_ptr)), + _M_refcount(__r._M_refcount) + { } + + template + __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, __dynamic_cast_tag) + : _M_ptr(dynamic_cast(__r._M_ptr)), + _M_refcount(__r._M_refcount) + { + if (_M_ptr == 0) // need to allocate new counter -- the cast failed + _M_refcount = __shared_count<_Lp>(); + } + + template + __shared_ptr& + operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws + { + _M_ptr = __r._M_ptr; + _M_refcount = __r._M_refcount; // __shared_count::op= doesn't throw + return *this; + } + + template + __shared_ptr& + operator=(std::auto_ptr<_Tp1>& __r) + { + __shared_ptr(__r).swap(*this); + return *this; + } + + void + reset() // never throws + { __shared_ptr().swap(*this); } + + template + void + reset(_Tp1* __p) // _Tp1 must be complete. + { + // Catch self-reset errors. + _GLIBCXX_DEBUG_ASSERT(__p == 0 || __p != _M_ptr); + __shared_ptr(__p).swap(*this); + } + + template + void + reset(_Tp1* __p, _Deleter __d) + { __shared_ptr(__p, __d).swap(*this); } + + // Allow class instantiation when _Tp is [cv-qual] void. + typename add_reference<_Tp>::type + operator*() const // never throws + { + _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); + return *_M_ptr; + } + + _Tp* + operator->() const // never throws + { + _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); + return _M_ptr; + } + + _Tp* + get() const // never throws + { return _M_ptr; } + + // Implicit conversion to "bool" + private: + typedef _Tp* __shared_ptr::*__unspecified_bool_type; + + public: + operator __unspecified_bool_type() const // never throws + { return _M_ptr == 0 ? 0 : &__shared_ptr::_M_ptr; } + + bool + unique() const // never throws + { return _M_refcount._M_unique(); } + + long + use_count() const // never throws + { return _M_refcount._M_get_use_count(); } + + void + swap(__shared_ptr<_Tp, _Lp>& __other) // never throws + { + std::swap(_M_ptr, __other._M_ptr); + _M_refcount._M_swap(__other._M_refcount); + } + + private: + void* + _M_get_deleter(const std::type_info& __ti) const + { return _M_refcount._M_get_deleter(__ti); } + + template + bool + _M_less(const __shared_ptr<_Tp1, _Lp1>& __rhs) const + { return _M_refcount < __rhs._M_refcount; } + + template friend class __shared_ptr; + template friend class __weak_ptr; + + template + friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&); + + // Friends injected into enclosing namespace and found by ADL: + template + friend inline bool + operator==(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b) + { return __a.get() == __b.get(); } + + template + friend inline bool + operator!=(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b) + { return __a.get() != __b.get(); } + + template + friend inline bool + operator<(const __shared_ptr& __a, const __shared_ptr<_Tp1, _Lp>& __b) + { return __a._M_less(__b); } + + _Tp* _M_ptr; // Contained pointer. + __shared_count<_Lp> _M_refcount; // Reference counter. + }; + + // 2.2.3.8 shared_ptr specialized algorithms. + template + inline void + swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b) + { __a.swap(__b); } + + // 2.2.3.9 shared_ptr casts + /** @warning The seemingly equivalent + * shared_ptr<_Tp, _Lp>(static_cast<_Tp*>(__r.get())) + * will eventually result in undefined behaviour, + * attempting to delete the same object twice. + */ + template + __shared_ptr<_Tp, _Lp> + static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) + { return __shared_ptr<_Tp, _Lp>(__r, __static_cast_tag()); } + + /** @warning The seemingly equivalent + * shared_ptr<_Tp, _Lp>(const_cast<_Tp*>(__r.get())) + * will eventually result in undefined behaviour, + * attempting to delete the same object twice. + */ + template + __shared_ptr<_Tp, _Lp> + const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) + { return __shared_ptr<_Tp, _Lp>(__r, __const_cast_tag()); } + + /** @warning The seemingly equivalent + * shared_ptr<_Tp, _Lp>(dynamic_cast<_Tp*>(__r.get())) + * will eventually result in undefined behaviour, + * attempting to delete the same object twice. + */ + template + __shared_ptr<_Tp, _Lp> + dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) + { return __shared_ptr<_Tp, _Lp>(__r, __dynamic_cast_tag()); } + + // 2.2.3.7 shared_ptr I/O + template + std::basic_ostream<_Ch, _Tr>& + operator<<(std::basic_ostream<_Ch, _Tr>& __os, + const __shared_ptr<_Tp, _Lp>& __p) + { + __os << __p.get(); + return __os; + } + + // 2.2.3.10 shared_ptr get_deleter (experimental) + template + inline _Del* + get_deleter(const __shared_ptr<_Tp, _Lp>& __p) + { return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); } + + + template + class __weak_ptr + { + public: + typedef _Tp element_type; + + __weak_ptr() + : _M_ptr(0), _M_refcount() // never throws + { } + + // Generated copy constructor, assignment, destructor are fine. + + // The "obvious" converting constructor implementation: + // + // template + // __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) + // : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws + // { } + // + // has a serious problem. + // + // __r._M_ptr may already have been invalidated. The _M_ptr(__r._M_ptr) + // conversion may require access to *__r._M_ptr (virtual inheritance). + // + // It is not possible to avoid spurious access violations since + // in multithreaded programs __r._M_ptr may be invalidated at any point. + template + __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) + : _M_refcount(__r._M_refcount) // never throws + { + __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) + _M_ptr = __r.lock().get(); + } + + template + __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r) + : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws + { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } + + template + __weak_ptr& + operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws + { + _M_ptr = __r.lock().get(); + _M_refcount = __r._M_refcount; + return *this; + } + + template + __weak_ptr& + operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws + { + _M_ptr = __r._M_ptr; + _M_refcount = __r._M_refcount; + return *this; + } + + __shared_ptr<_Tp, _Lp> + lock() const // never throws + { +#ifdef __GTHREADS + // Optimization: avoid throw overhead. + if (expired()) + return __shared_ptr(); + + try + { + return __shared_ptr(*this); + } + catch(const bad_weak_ptr&) + { + // Q: How can we get here? + // A: Another thread may have invalidated r after the + // use_count test above. + return __shared_ptr(); + } + +#else + // Optimization: avoid try/catch overhead when single threaded. + return expired() ? __shared_ptr() + : __shared_ptr(*this); + +#endif + } // XXX MT + + long + use_count() const // never throws + { return _M_refcount._M_get_use_count(); } + + bool + expired() const // never throws + { return _M_refcount._M_get_use_count() == 0; } + + void + reset() // never throws + { __weak_ptr().swap(*this); } + + void + swap(__weak_ptr& __s) // never throws + { + std::swap(_M_ptr, __s._M_ptr); + _M_refcount._M_swap(__s._M_refcount); + } + + private: + // Used by __enable_shared_from_this. + void + _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) + { + _M_ptr = __ptr; + _M_refcount = __refcount; + } + + template + bool + _M_less(const __weak_ptr<_Tp1, _Lp>& __rhs) const + { return _M_refcount < __rhs._M_refcount; } + + template friend class __shared_ptr; + template friend class __weak_ptr; + friend class __enable_shared_from_this<_Tp, _Lp>; + friend class enable_shared_from_this<_Tp>; + + // Friend injected into namespace and found by ADL. + template + friend inline bool + operator<(const __weak_ptr& __lhs, const __weak_ptr<_Tp1, _Lp>& __rhs) + { return __lhs._M_less(__rhs); } + + _Tp* _M_ptr; // Contained pointer. + __weak_count<_Lp> _M_refcount; // Reference counter. + }; + + // 2.2.4.7 weak_ptr specialized algorithms. + template + inline void + swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) + { __a.swap(__b); } + + + template + class __enable_shared_from_this + { + protected: + __enable_shared_from_this() { } + + __enable_shared_from_this(const __enable_shared_from_this&) { } + + __enable_shared_from_this& + operator=(const __enable_shared_from_this&) + { return *this; } + + ~__enable_shared_from_this() { } + + public: + __shared_ptr<_Tp, _Lp> + shared_from_this() + { return __shared_ptr<_Tp, _Lp>(this->_M_weak_this); } + + __shared_ptr + shared_from_this() const + { return __shared_ptr(this->_M_weak_this); } + + private: + template + void + _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const + { _M_weak_this._M_assign(__p, __n); } + + template + friend void + __enable_shared_from_this_helper(const __shared_count<_Lp>& __pn, + const __enable_shared_from_this* __pe, + const _Tp1* __px) + { + if (__pe != 0) + __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn); + } + + mutable __weak_ptr<_Tp, _Lp> _M_weak_this; + }; + + + // The actual TR1 shared_ptr, with forwarding constructors and + // assignment operators. + template + class shared_ptr + : public __shared_ptr<_Tp> + { + public: + shared_ptr() + : __shared_ptr<_Tp>() { } + + template + explicit + shared_ptr(_Tp1* __p) + : __shared_ptr<_Tp>(__p) { } + + template + shared_ptr(_Tp1* __p, _Deleter __d) + : __shared_ptr<_Tp>(__p, __d) { } + + template + shared_ptr(const shared_ptr<_Tp1>& __r) + : __shared_ptr<_Tp>(__r) { } + + template + explicit + shared_ptr(const weak_ptr<_Tp1>& __r) + : __shared_ptr<_Tp>(__r) { } + + template + explicit + shared_ptr(std::auto_ptr<_Tp1>& __r) + : __shared_ptr<_Tp>(__r) { } + + template + shared_ptr(const shared_ptr<_Tp1>& __r, __static_cast_tag) + : __shared_ptr<_Tp>(__r, __static_cast_tag()) { } + + template + shared_ptr(const shared_ptr<_Tp1>& __r, __const_cast_tag) + : __shared_ptr<_Tp>(__r, __const_cast_tag()) { } + + template + shared_ptr(const shared_ptr<_Tp1>& __r, __dynamic_cast_tag) + : __shared_ptr<_Tp>(__r, __dynamic_cast_tag()) { } + + template + shared_ptr& + operator=(const shared_ptr<_Tp1>& __r) // never throws + { + this->__shared_ptr<_Tp>::operator=(__r); + return *this; + } + + template + shared_ptr& + operator=(std::auto_ptr<_Tp1>& __r) + { + this->__shared_ptr<_Tp>::operator=(__r); + return *this; + } + }; + + template + shared_ptr<_Tp> + static_pointer_cast(const shared_ptr<_Tp1>& __r) + { return shared_ptr<_Tp>(__r, __static_cast_tag()); } + + template + shared_ptr<_Tp> + const_pointer_cast(const shared_ptr<_Tp1>& __r) + { return shared_ptr<_Tp>(__r, __const_cast_tag()); } + + template + shared_ptr<_Tp> + dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) + { return shared_ptr<_Tp>(__r, __dynamic_cast_tag()); } + + + // The actual TR1 weak_ptr, with forwarding constructors and + // assignment operators. + template + class weak_ptr + : public __weak_ptr<_Tp> + { + public: + weak_ptr() + : __weak_ptr<_Tp>() { } + + template + weak_ptr(const weak_ptr<_Tp1>& __r) + : __weak_ptr<_Tp>(__r) { } + + template + weak_ptr(const shared_ptr<_Tp1>& __r) + : __weak_ptr<_Tp>(__r) { } + + template + weak_ptr& + operator=(const weak_ptr<_Tp1>& __r) // never throws + { + this->__weak_ptr<_Tp>::operator=(__r); + return *this; + } + + template + weak_ptr& + operator=(const shared_ptr<_Tp1>& __r) // never throws + { + this->__weak_ptr<_Tp>::operator=(__r); + return *this; + } + + shared_ptr<_Tp> + lock() const // never throws + { +#ifdef __GTHREADS + if (this->expired()) + return shared_ptr<_Tp>(); + + try + { + return shared_ptr<_Tp>(*this); + } + catch(const bad_weak_ptr&) + { + return shared_ptr<_Tp>(); + } +#else + return this->expired() ? shared_ptr<_Tp>() + : shared_ptr<_Tp>(*this); +#endif + } + }; + + + template + class enable_shared_from_this + { + protected: + enable_shared_from_this() { } + + enable_shared_from_this(const enable_shared_from_this&) { } + + enable_shared_from_this& + operator=(const enable_shared_from_this&) + { return *this; } + + ~enable_shared_from_this() { } + + public: + shared_ptr<_Tp> + shared_from_this() + { return shared_ptr<_Tp>(this->_M_weak_this); } + + shared_ptr + shared_from_this() const + { return shared_ptr(this->_M_weak_this); } + + private: + template + void + _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const + { _M_weak_this._M_assign(__p, __n); } + + template + friend void + __enable_shared_from_this_helper(const __shared_count<>& __pn, + const enable_shared_from_this* __pe, + const _Tp1* __px) + { + if (__pe != 0) + __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn); + } + + mutable weak_ptr<_Tp> _M_weak_this; + }; + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/cctype b/libstdc++-v3/include/tr1_impl/cctype new file mode 100644 index 0000000..a227ec9 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cctype @@ -0,0 +1,48 @@ +// TR1 cctype -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cctype + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_USE_C99_CTYPE_TR1 + +#undef isblank + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + using ::isblank; + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#endif diff --git a/libstdc++-v3/include/tr1_impl/cfenv b/libstdc++-v3/include/tr1_impl/cfenv new file mode 100644 index 0000000..01535e0 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cfenv @@ -0,0 +1,77 @@ +// TR1 cfenv -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cfenv + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_USE_C99_FENV_TR1 + +#include_next + +#undef feclearexcept +#undef fegetexceptflag +#undef feraiseexcept +#undef fesetexceptflag +#undef fetestexcept +#undef fegetround +#undef fesetround +#undef fegetenv +#undef feholdexcept +#undef fesetenv +#undef feupdateenv + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // types + using ::fenv_t; + using ::fexcept_t; + + // functions + using ::feclearexcept; + using ::fegetexceptflag; + using ::feraiseexcept; + using ::fesetexceptflag; + using ::fetestexcept; + + using ::fegetround; + using ::fesetround; + + using ::fegetenv; + using ::feholdexcept; + using ::fesetenv; + using ::feupdateenv; + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#endif diff --git a/libstdc++-v3/include/tr1_impl/cinttypes b/libstdc++-v3/include/tr1_impl/cinttypes new file mode 100644 index 0000000..05b5251 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cinttypes @@ -0,0 +1,73 @@ +// TR1 cinttypes -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cinttypes + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_USE_C99_INTTYPES_TR1 + +// For 8.11.1/1 (see C99, Note 184) +#define __STDC_FORMAT_MACROS +#include_next + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // types + using ::imaxdiv_t; + + // functions + using ::imaxabs; + + // May collide with _Longlong abs(_Longlong), and is not described + // anywhere outside the synopsis. Likely, a defect. + // + // intmax_t abs(intmax_t) + + using ::imaxdiv; + + // Likewise, with lldiv_t div(_Longlong, _Longlong). + // + // imaxdiv_t div(intmax_t, intmax_t) + + using ::strtoimax; + using ::strtoumax; + +#ifdef _GLIBCXX_USE_WCHAR_T + using ::wcstoimax; + using ::wcstoumax; +#endif + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#endif diff --git a/libstdc++-v3/include/tr1_impl/cmath b/libstdc++-v3/include/tr1_impl/cmath new file mode 100644 index 0000000..3bbbda2 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cmath @@ -0,0 +1,907 @@ +// TR1 cmath -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cmath + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_USE_C99_MATH_TR1 + +#undef acosh +#undef acoshf +#undef acoshl +#undef asinh +#undef asinhf +#undef asinhl +#undef atanh +#undef atanhf +#undef atanhl +#undef cbrt +#undef cbrtf +#undef cbrtl +#undef copysign +#undef copysignf +#undef copysignl +#undef erf +#undef erff +#undef erfl +#undef erfc +#undef erfcf +#undef erfcl +#undef exp2 +#undef exp2f +#undef exp2l +#undef expm1 +#undef expm1f +#undef expm1l +#undef fdim +#undef fdimf +#undef fdiml +#undef fma +#undef fmaf +#undef fmal +#undef fmax +#undef fmaxf +#undef fmaxl +#undef fmin +#undef fminf +#undef fminl +#undef hypot +#undef hypotf +#undef hypotl +#undef ilogb +#undef ilogbf +#undef ilogbl +#undef lgamma +#undef lgammaf +#undef lgammal +#undef llrint +#undef llrintf +#undef llrintl +#undef llround +#undef llroundf +#undef llroundl +#undef log1p +#undef log1pf +#undef log1pl +#undef log2 +#undef log2f +#undef log2l +#undef logb +#undef logbf +#undef logbl +#undef lrint +#undef lrintf +#undef lrintl +#undef lround +#undef lroundf +#undef lroundl +#undef nan +#undef nanf +#undef nanl +#undef nearbyint +#undef nearbyintf +#undef nearbyintl +#undef nextafter +#undef nextafterf +#undef nextafterl +#undef nexttoward +#undef nexttowardf +#undef nexttowardl +#undef remainder +#undef remainderf +#undef remainderl +#undef remquo +#undef remquo +#undef remquo +#undef rint +#undef rintf +#undef rintl +#undef round +#undef roundf +#undef roundl +#undef scalbln +#undef scalblnf +#undef scalblnl +#undef scalbn +#undef scalbnf +#undef scalbnl +#undef tgamma +#undef tgammaf +#undef tgammal +#undef trunc +#undef truncf +#undef truncl + +#endif + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + +#if _GLIBCXX_USE_C99_MATH_TR1 + + // types + using ::double_t; + using ::float_t; + + // functions + using ::acosh; + using ::acoshf; + using ::acoshl; + + using ::asinh; + using ::asinhf; + using ::asinhl; + + using ::atanh; + using ::atanhf; + using ::atanhl; + + using ::cbrt; + using ::cbrtf; + using ::cbrtl; + + using ::copysign; + using ::copysignf; + using ::copysignl; + + using ::erf; + using ::erff; + using ::erfl; + + using ::erfc; + using ::erfcf; + using ::erfcl; + + using ::exp2; + using ::exp2f; + using ::exp2l; + + using ::expm1; + using ::expm1f; + using ::expm1l; + + using ::fdim; + using ::fdimf; + using ::fdiml; + + using ::fma; + using ::fmaf; + using ::fmal; + + using ::fmax; + using ::fmaxf; + using ::fmaxl; + + using ::fmin; + using ::fminf; + using ::fminl; + + using ::hypot; + using ::hypotf; + using ::hypotl; + + using ::ilogb; + using ::ilogbf; + using ::ilogbl; + + using ::lgamma; + using ::lgammaf; + using ::lgammal; + + using ::llrint; + using ::llrintf; + using ::llrintl; + + using ::llround; + using ::llroundf; + using ::llroundl; + + using ::log1p; + using ::log1pf; + using ::log1pl; + + using ::log2; + using ::log2f; + using ::log2l; + + using ::logb; + using ::logbf; + using ::logbl; + + using ::lrint; + using ::lrintf; + using ::lrintl; + + using ::lround; + using ::lroundf; + using ::lroundl; + + using ::nan; + using ::nanf; + using ::nanl; + + using ::nearbyint; + using ::nearbyintf; + using ::nearbyintl; + + using ::nextafter; + using ::nextafterf; + using ::nextafterl; + + using ::nexttoward; + using ::nexttowardf; + using ::nexttowardl; + + using ::remainder; + using ::remainderf; + using ::remainderl; + + using ::remquo; + using ::remquo; + using ::remquo; + + using ::rint; + using ::rintf; + using ::rintl; + + using ::round; + using ::roundf; + using ::roundl; + + using ::scalbln; + using ::scalblnf; + using ::scalblnl; + + using ::scalbn; + using ::scalbnf; + using ::scalbnl; + + using ::tgamma; + using ::tgammaf; + using ::tgammal; + + using ::trunc; + using ::truncf; + using ::truncl; + +#endif + +#if _GLIBCXX_USE_C99_MATH +#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC + + /// @brief Function template definitions [8.16.3]. + // + using std::signbit; + + using std::fpclassify; + + using std::isfinite; + using std::isinf; + using std::isnan; + using std::isnormal; + + using std::isgreater; + using std::isgreaterequal; + using std::isless; + using std::islessequal; + using std::islessgreater; + using std::isunordered; +#endif +#endif + +#if _GLIBCXX_USE_C99_MATH_TR1 + + /// @brief Additional overloads [8.16.4]. + // + using std::acos; + + inline float + acosh(float __x) + { return __builtin_acoshf(__x); } + + inline long double + acosh(long double __x) + { return __builtin_acoshl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + acosh(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return acosh(__type(__x)); + } + + using std::asin; + + inline float + asinh(float __x) + { return __builtin_asinhf(__x); } + + inline long double + asinh(long double __x) + { return __builtin_asinhl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + asinh(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return asinh(__type(__x)); + } + + using std::atan; + using std::atan2; + + inline float + atanh(float __x) + { return __builtin_atanhf(__x); } + + inline long double + atanh(long double __x) + { return __builtin_atanhl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + atanh(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return atanh(__type(__x)); + } + + inline float + cbrt(float __x) + { return __builtin_cbrtf(__x); } + + inline long double + cbrt(long double __x) + { return __builtin_cbrtl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + cbrt(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return cbrt(__type(__x)); + } + + using std::ceil; + + inline float + copysign(float __x, float __y) + { return __builtin_copysignf(__x, __y); } + + inline long double + copysign(long double __x, long double __y) + { return __builtin_copysignl(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + copysign(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return copysign(__type(__x), __type(__y)); + } + + using std::cos; + using std::cosh; + + inline float + erf(float __x) + { return __builtin_erff(__x); } + + inline long double + erf(long double __x) + { return __builtin_erfl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + erf(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return erf(__type(__x)); + } + + inline float + erfc(float __x) + { return __builtin_erfcf(__x); } + + inline long double + erfc(long double __x) + { return __builtin_erfcl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + erfc(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return erfc(__type(__x)); + } + + using std::exp; + + inline float + exp2(float __x) + { return __builtin_exp2f(__x); } + + inline long double + exp2(long double __x) + { return __builtin_exp2l(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + exp2(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return exp2(__type(__x)); + } + + inline float + expm1(float __x) + { return __builtin_expm1f(__x); } + + inline long double + expm1(long double __x) + { return __builtin_expm1l(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + expm1(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return expm1(__type(__x)); + } + + using std::fabs; + + inline float + fdim(float __x, float __y) + { return __builtin_fdimf(__x, __y); } + + inline long double + fdim(long double __x, long double __y) + { return __builtin_fdiml(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + fdim(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return fdim(__type(__x), __type(__y)); + } + + using std::floor; + + inline float + fma(float __x, float __y, float __z) + { return __builtin_fmaf(__x, __y, __z); } + + inline long double + fma(long double __x, long double __y, long double __z) + { return __builtin_fmal(__x, __y, __z); } + + template + inline typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type + fma(_Tp __x, _Up __y, _Vp __z) + { + typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type; + return fma(__type(__x), __type(__y), __type(__z)); + } + + inline float + fmax(float __x, float __y) + { return __builtin_fmaxf(__x, __y); } + + inline long double + fmax(long double __x, long double __y) + { return __builtin_fmaxl(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + fmax(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return fmax(__type(__x), __type(__y)); + } + + inline float + fmin(float __x, float __y) + { return __builtin_fminf(__x, __y); } + + inline long double + fmin(long double __x, long double __y) + { return __builtin_fminl(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + fmin(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return fmin(__type(__x), __type(__y)); + } + + using std::fmod; + using std::frexp; + + inline float + hypot(float __x, float __y) + { return __builtin_hypotf(__x, __y); } + + inline long double + hypot(long double __x, long double __y) + { return __builtin_hypotl(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + hypot(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return hypot(__type(__x), __type(__y)); + } + + inline int + ilogb(float __x) + { return __builtin_ilogbf(__x); } + + inline int + ilogb(long double __x) + { return __builtin_ilogbl(__x); } + + template + inline int + ilogb(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return ilogb(__type(__x)); + } + + using std::ldexp; + + inline float + lgamma(float __x) + { return __builtin_lgammaf(__x); } + + inline long double + lgamma(long double __x) + { return __builtin_lgammal(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + lgamma(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return lgamma(__type(__x)); + } + + inline long long + llrint(float __x) + { return __builtin_llrintf(__x); } + + inline long long + llrint(long double __x) + { return __builtin_llrintl(__x); } + + template + inline long long + llrint(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return llrint(__type(__x)); + } + + inline long long + llround(float __x) + { return __builtin_llroundf(__x); } + + inline long long + llround(long double __x) + { return __builtin_llroundl(__x); } + + template + inline long long + llround(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return llround(__type(__x)); + } + + using std::log; + using std::log10; + + inline float + log1p(float __x) + { return __builtin_log1pf(__x); } + + inline long double + log1p(long double __x) + { return __builtin_log1pl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + log1p(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return log1p(__type(__x)); + } + + // DR 568. + inline float + log2(float __x) + { return __builtin_log2f(__x); } + + inline long double + log2(long double __x) + { return __builtin_log2l(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + log2(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return log2(__type(__x)); + } + + inline float + logb(float __x) + { return __builtin_logbf(__x); } + + inline long double + logb(long double __x) + { return __builtin_logbl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + logb(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return logb(__type(__x)); + } + + inline long + lrint(float __x) + { return __builtin_lrintf(__x); } + + inline long + lrint(long double __x) + { return __builtin_lrintl(__x); } + + template + inline long + lrint(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return lrint(__type(__x)); + } + + inline long + lround(float __x) + { return __builtin_lroundf(__x); } + + inline long + lround(long double __x) + { return __builtin_lroundl(__x); } + + template + inline long + lround(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return lround(__type(__x)); + } + + inline float + nearbyint(float __x) + { return __builtin_nearbyintf(__x); } + + inline long double + nearbyint(long double __x) + { return __builtin_nearbyintl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + nearbyint(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return nearbyint(__type(__x)); + } + + inline float + nextafter(float __x, float __y) + { return __builtin_nextafterf(__x, __y); } + + inline long double + nextafter(long double __x, long double __y) + { return __builtin_nextafterl(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + nextafter(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return nextafter(__type(__x), __type(__y)); + } + + inline float + nexttoward(float __x, long double __y) + { return __builtin_nexttowardf(__x, __y); } + + inline long double + nexttoward(long double __x, long double __y) + { return __builtin_nexttowardl(__x, __y); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + nexttoward(_Tp __x, long double __y) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return nexttoward(__type(__x), __y); + } + + using std::pow; + + inline float + remainder(float __x, float __y) + { return __builtin_remainderf(__x, __y); } + + inline long double + remainder(long double __x, long double __y) + { return __builtin_remainderl(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + remainder(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return remainder(__type(__x), __type(__y)); + } + + inline float + remquo(float __x, float __y, int* __pquo) + { return __builtin_remquof(__x, __y, __pquo); } + + inline long double + remquo(long double __x, long double __y, int* __pquo) + { return __builtin_remquol(__x, __y, __pquo); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + remquo(_Tp __x, _Up __y, int* __pquo) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return remquo(__type(__x), __type(__y), __pquo); + } + + inline float + rint(float __x) + { return __builtin_rintf(__x); } + + inline long double + rint(long double __x) + { return __builtin_rintl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + rint(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return rint(__type(__x)); + } + + inline float + round(float __x) + { return __builtin_roundf(__x); } + + inline long double + round(long double __x) + { return __builtin_roundl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + round(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return round(__type(__x)); + } + + inline float + scalbln(float __x, long __ex) + { return __builtin_scalblnf(__x, __ex); } + + inline long double + scalbln(long double __x, long __ex) + { return __builtin_scalblnl(__x, __ex); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + scalbln(_Tp __x, long __ex) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return scalbln(__type(__x), __ex); + } + + inline float + scalbn(float __x, int __ex) + { return __builtin_scalbnf(__x, __ex); } + + inline long double + scalbn(long double __x, int __ex) + { return __builtin_scalbnl(__x, __ex); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + scalbn(_Tp __x, int __ex) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return scalbn(__type(__x), __ex); + } + + using std::sin; + using std::sinh; + using std::sqrt; + using std::tan; + using std::tanh; + + inline float + tgamma(float __x) + { return __builtin_tgammaf(__x); } + + inline long double + tgamma(long double __x) + { return __builtin_tgammal(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + tgamma(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return tgamma(__type(__x)); + } + + inline float + trunc(float __x) + { return __builtin_truncf(__x); } + + inline long double + trunc(long double __x) + { return __builtin_truncl(__x); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + trunc(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return trunc(__type(__x)); + } + +#endif + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/complex b/libstdc++-v3/include/tr1_impl/complex new file mode 100644 index 0000000..f763182 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/complex @@ -0,0 +1,369 @@ +// TR1 complex -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/complex + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // Forward declarations. + template std::complex<_Tp> acos(const std::complex<_Tp>&); + template std::complex<_Tp> asin(const std::complex<_Tp>&); + template std::complex<_Tp> atan(const std::complex<_Tp>&); + + template std::complex<_Tp> acosh(const std::complex<_Tp>&); + template std::complex<_Tp> asinh(const std::complex<_Tp>&); + template std::complex<_Tp> atanh(const std::complex<_Tp>&); + template std::complex<_Tp> fabs(const std::complex<_Tp>&); + + /// @brief acos(__z) [8.1.2]. + // Effects: Behaves the same as C99 function cacos, defined + // in subclause 7.3.5.1. + template + inline std::complex<_Tp> + __complex_acos(const std::complex<_Tp>& __z) + { + const std::complex<_Tp> __t = std::_GLIBCXX_TR1 asin(__z); + const _Tp __pi_2 = 1.5707963267948966192313216916397514L; + return std::complex<_Tp>(__pi_2 - __t.real(), -__t.imag()); + } + +#if _GLIBCXX_USE_C99_COMPLEX_TR1 + inline __complex__ float + __complex_acos(__complex__ float __z) + { return __builtin_cacosf(__z); } + + inline __complex__ double + __complex_acos(__complex__ double __z) + { return __builtin_cacos(__z); } + + inline __complex__ long double + __complex_acos(const __complex__ long double& __z) + { return __builtin_cacosl(__z); } + + template + inline std::complex<_Tp> + acos(const std::complex<_Tp>& __z) + { return __complex_acos(__z.__rep()); } +#else + template + inline std::complex<_Tp> + acos(const std::complex<_Tp>& __z) + { return __complex_acos(__z); } +#endif + + /// @brief asin(__z) [8.1.3]. + // Effects: Behaves the same as C99 function casin, defined + // in subclause 7.3.5.2. + template + inline std::complex<_Tp> + __complex_asin(const std::complex<_Tp>& __z) + { + std::complex<_Tp> __t(-__z.imag(), __z.real()); + __t = std::_GLIBCXX_TR1 asinh(__t); + return std::complex<_Tp>(__t.imag(), -__t.real()); + } + +#if _GLIBCXX_USE_C99_COMPLEX_TR1 + inline __complex__ float + __complex_asin(__complex__ float __z) + { return __builtin_casinf(__z); } + + inline __complex__ double + __complex_asin(__complex__ double __z) + { return __builtin_casin(__z); } + + inline __complex__ long double + __complex_asin(const __complex__ long double& __z) + { return __builtin_casinl(__z); } + + template + inline std::complex<_Tp> + asin(const std::complex<_Tp>& __z) + { return __complex_asin(__z.__rep()); } +#else + template + inline std::complex<_Tp> + asin(const std::complex<_Tp>& __z) + { return __complex_asin(__z); } +#endif + + /// @brief atan(__z) [8.1.4]. + // Effects: Behaves the same as C99 function catan, defined + // in subclause 7.3.5.3. + template + std::complex<_Tp> + __complex_atan(const std::complex<_Tp>& __z) + { + const _Tp __r2 = __z.real() * __z.real(); + const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag(); + + _Tp __num = __z.imag() + _Tp(1.0); + _Tp __den = __z.imag() - _Tp(1.0); + + __num = __r2 + __num * __num; + __den = __r2 + __den * __den; + + return std::complex<_Tp>(_Tp(0.5) * atan2(_Tp(2.0) * __z.real(), __x), + _Tp(0.25) * log(__num / __den)); + } + +#if _GLIBCXX_USE_C99_COMPLEX_TR1 + inline __complex__ float + __complex_atan(__complex__ float __z) + { return __builtin_catanf(__z); } + + inline __complex__ double + __complex_atan(__complex__ double __z) + { return __builtin_catan(__z); } + + inline __complex__ long double + __complex_atan(const __complex__ long double& __z) + { return __builtin_catanl(__z); } + + template + inline std::complex<_Tp> + atan(const std::complex<_Tp>& __z) + { return __complex_atan(__z.__rep()); } +#else + template + inline std::complex<_Tp> + atan(const std::complex<_Tp>& __z) + { return __complex_atan(__z); } +#endif + + /// @brief acosh(__z) [8.1.5]. + // Effects: Behaves the same as C99 function cacosh, defined + // in subclause 7.3.6.1. + template + std::complex<_Tp> + __complex_acosh(const std::complex<_Tp>& __z) + { + std::complex<_Tp> __t((__z.real() - __z.imag()) + * (__z.real() + __z.imag()) - _Tp(1.0), + _Tp(2.0) * __z.real() * __z.imag()); + __t = std::sqrt(__t); + + return std::log(__t + __z); + } + +#if _GLIBCXX_USE_C99_COMPLEX_TR1 + inline __complex__ float + __complex_acosh(__complex__ float __z) + { return __builtin_cacoshf(__z); } + + inline __complex__ double + __complex_acosh(__complex__ double __z) + { return __builtin_cacosh(__z); } + + inline __complex__ long double + __complex_acosh(const __complex__ long double& __z) + { return __builtin_cacoshl(__z); } + + template + inline std::complex<_Tp> + acosh(const std::complex<_Tp>& __z) + { return __complex_acosh(__z.__rep()); } +#else + template + inline std::complex<_Tp> + acosh(const std::complex<_Tp>& __z) + { return __complex_acosh(__z); } +#endif + + /// @brief asinh(__z) [8.1.6]. + // Effects: Behaves the same as C99 function casin, defined + // in subclause 7.3.6.2. + template + std::complex<_Tp> + __complex_asinh(const std::complex<_Tp>& __z) + { + std::complex<_Tp> __t((__z.real() - __z.imag()) + * (__z.real() + __z.imag()) + _Tp(1.0), + _Tp(2.0) * __z.real() * __z.imag()); + __t = std::sqrt(__t); + + return std::log(__t + __z); + } + +#if _GLIBCXX_USE_C99_COMPLEX_TR1 + inline __complex__ float + __complex_asinh(__complex__ float __z) + { return __builtin_casinhf(__z); } + + inline __complex__ double + __complex_asinh(__complex__ double __z) + { return __builtin_casinh(__z); } + + inline __complex__ long double + __complex_asinh(const __complex__ long double& __z) + { return __builtin_casinhl(__z); } + + template + inline std::complex<_Tp> + asinh(const std::complex<_Tp>& __z) + { return __complex_asinh(__z.__rep()); } +#else + template + inline std::complex<_Tp> + asinh(const std::complex<_Tp>& __z) + { return __complex_asinh(__z); } +#endif + + /// @brief atanh(__z) [8.1.7]. + // Effects: Behaves the same as C99 function catanh, defined + // in subclause 7.3.6.3. + template + std::complex<_Tp> + __complex_atanh(const std::complex<_Tp>& __z) + { + const _Tp __i2 = __z.imag() * __z.imag(); + const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real(); + + _Tp __num = _Tp(1.0) + __z.real(); + _Tp __den = _Tp(1.0) - __z.real(); + + __num = __i2 + __num * __num; + __den = __i2 + __den * __den; + + return std::complex<_Tp>(_Tp(0.25) * (log(__num) - log(__den)), + _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x)); + } + +#if _GLIBCXX_USE_C99_COMPLEX_TR1 + inline __complex__ float + __complex_atanh(__complex__ float __z) + { return __builtin_catanhf(__z); } + + inline __complex__ double + __complex_atanh(__complex__ double __z) + { return __builtin_catanh(__z); } + + inline __complex__ long double + __complex_atanh(const __complex__ long double& __z) + { return __builtin_catanhl(__z); } + + template + inline std::complex<_Tp> + atanh(const std::complex<_Tp>& __z) + { return __complex_atanh(__z.__rep()); } +#else + template + inline std::complex<_Tp> + atanh(const std::complex<_Tp>& __z) + { return __complex_atanh(__z); } +#endif + + /// @brief fabs(__z) [8.1.8]. + // Effects: Behaves the same as C99 function cabs, defined + // in subclause 7.3.8.1. + template + inline std::complex<_Tp> + fabs(const std::complex<_Tp>& __z) + { return std::abs(__z); } + + +#if (defined(_GLIBCXX_INCLUDE_AS_CXX0X) \ + || (defined(_GLIBCXX_INCLUDE_AS_TR1) \ + && !defined(__GXX_EXPERIMENTAL_CXX0X__))) + + /// @brief Additional overloads [8.1.9]. + // + template + inline typename __gnu_cxx::__promote<_Tp>::__type + arg(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return std::arg(std::complex<__type>(__x)); + } + + template + inline std::complex::__type> + conj(_Tp __x) + { return __x; } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + imag(_Tp) + { return _Tp(); } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + norm(_Tp __x) + { + typedef typename __gnu_cxx::__promote<_Tp>::__type __type; + return __type(__x) * __type(__x); + } + + template + inline std::complex::__type> + polar(const _Tp& __rho, const _Up& __theta) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return std::polar(__type(__rho), __type(__theta)); + } + + template + inline std::complex::__type> + pow(const std::complex<_Tp>& __x, const _Up& __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return std::pow(std::complex<__type>(__x), __type(__y)); + } + + template + inline std::complex::__type> + pow(const _Tp& __x, const std::complex<_Up>& __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return std::pow(__type(__x), std::complex<__type>(__y)); + } + + template + inline std::complex::__type> + pow(const std::complex<_Tp>& __x, const std::complex<_Up>& __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return std::pow(std::complex<__type>(__x), + std::complex<__type>(__y)); + } + + template + inline typename __gnu_cxx::__promote<_Tp>::__type + real(_Tp __x) + { return __x; } + +#endif + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/cstdint b/libstdc++-v3/include/tr1_impl/cstdint new file mode 100644 index 0000000..862ee97 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cstdint @@ -0,0 +1,85 @@ +// TR1 cstdint -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cstdint + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_USE_C99_STDINT_TR1 + +// For 8.22.1/1 (see C99, Notes 219, 220, 222) +#define __STDC_LIMIT_MACROS +#define __STDC_CONSTANT_MACROS +#include_next + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + using ::int8_t; + using ::int16_t; + using ::int32_t; + using ::int64_t; + + using ::int_fast8_t; + using ::int_fast16_t; + using ::int_fast32_t; + using ::int_fast64_t; + + using ::int_least8_t; + using ::int_least16_t; + using ::int_least32_t; + using ::int_least64_t; + + using ::intmax_t; + using ::intptr_t; + + using ::uint8_t; + using ::uint16_t; + using ::uint32_t; + using ::uint64_t; + + using ::uint_fast8_t; + using ::uint_fast16_t; + using ::uint_fast32_t; + using ::uint_fast64_t; + + using ::uint_least8_t; + using ::uint_least16_t; + using ::uint_least32_t; + using ::uint_least64_t; + + using ::uintmax_t; + using ::uintptr_t; + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#endif diff --git a/libstdc++-v3/include/tr1_impl/cstdio b/libstdc++-v3/include/tr1_impl/cstdio new file mode 100644 index 0000000..f45adea --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cstdio @@ -0,0 +1,49 @@ +// TR1 cstdio -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cstdio + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + +#if _GLIBCXX_USE_C99 + using std::snprintf; + using std::vsnprintf; + + using std::vfscanf; + using std::vscanf; + using std::vsscanf; +#endif + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/cstdlib b/libstdc++-v3/include/tr1_impl/cstdlib new file mode 100644 index 0000000..482f20c --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cstdlib @@ -0,0 +1,70 @@ +// TR1 cstdlib -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cstdlib + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_HOSTED + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + +#if _GLIBCXX_USE_C99 + +#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC + // types + using std::lldiv_t; + + // functions + using std::llabs; + using std::lldiv; +#endif + + using std::atoll; + using std::strtoll; + using std::strtoull; + + using std::strtof; + using std::strtold; + + // overloads + using std::abs; +#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC + using std::div; +#endif + +#endif + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#endif diff --git a/libstdc++-v3/include/tr1_impl/cwchar b/libstdc++-v3/include/tr1_impl/cwchar new file mode 100644 index 0000000..a0f8e2d --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cwchar @@ -0,0 +1,63 @@ +// TR1 cwchar -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cwchar + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_USE_WCHAR_T + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + +#if _GLIBCXX_HAVE_WCSTOF + using std::wcstof; +#endif +#if _GLIBCXX_HAVE_VFWSCANF + using std::vfwscanf; +#endif +#if _GLIBCXX_HAVE_VSWSCANF + using std::vswscanf; +#endif +#if _GLIBCXX_HAVE_VWSCANF + using std::vwscanf; +#endif + +#if _GLIBCXX_USE_C99 + using std::wcstold; + using std::wcstoll; + using std::wcstoull; +#endif + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#endif diff --git a/libstdc++-v3/include/tr1_impl/cwctype b/libstdc++-v3/include/tr1_impl/cwctype new file mode 100644 index 0000000..51a2e91 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/cwctype @@ -0,0 +1,48 @@ +// TR1 cwctype -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/cwctype + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#if _GLIBCXX_USE_WCHAR_T + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + +#if _GLIBCXX_HAVE_ISWBLANK + using std::iswblank; +#endif + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#endif diff --git a/libstdc++-v3/include/tr1_impl/functional b/libstdc++-v3/include/tr1_impl/functional new file mode 100644 index 0000000..0005dfc --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/functional @@ -0,0 +1,2294 @@ +// TR1 functional header -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/functional + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + template + class _Mem_fn; + + /** + * @if maint + * Actual implementation of _Has_result_type, which uses SFINAE to + * determine if the type _Tp has a publicly-accessible member type + * result_type. + * @endif + */ + template + class _Has_result_type_helper : __sfinae_types + { + template + struct _Wrap_type + { }; + + template + static __one __test(_Wrap_type*); + + template + static __two __test(...); + + public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; + }; + + template + struct _Has_result_type + : integral_constant::type>::value> + { }; + + /** + * @if maint + * If we have found a result_type, extract it. + * @endif + */ + template + struct _Maybe_get_result_type + { }; + + template + struct _Maybe_get_result_type + { + typedef typename _Functor::result_type result_type; + }; + + /** + * @if maint + * Base class for any function object that has a weak result type, as + * defined in 3.3/3 of TR1. + * @endif + */ + template + struct _Weak_result_type_impl + : _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor> + { + }; + + /** + * @if maint + * Retrieve the result type for a function type. + * @endif + */ + template + struct _Weak_result_type_impl<_Res(_ArgTypes...)> + { + typedef _Res result_type; + }; + + /** + * @if maint + * Retrieve the result type for a function reference. + * @endif + */ + template + struct _Weak_result_type_impl<_Res(&)(_ArgTypes...)> + { + typedef _Res result_type; + }; + + /** + * @if maint + * Retrieve the result type for a function pointer. + * @endif + */ + template + struct _Weak_result_type_impl<_Res(*)(_ArgTypes...)> + { + typedef _Res result_type; + }; + + /** + * @if maint + * Retrieve result type for a member function pointer. + * @endif maint + */ + template + struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)> + { + typedef _Res result_type; + }; + + /** + * @if maint + * Retrieve result type for a const member function pointer. + * @endif maint + */ + template + struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) const> + { + typedef _Res result_type; + }; + + /** + * @if maint + * Retrieve result type for a volatile member function pointer. + * @endif maint + */ + template + struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) volatile> + { + typedef _Res result_type; + }; + + /** + * @if maint + * Retrieve result type for a const volatile member function pointer. + * @endif maint + */ + template + struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)const volatile> + { + typedef _Res result_type; + }; + + /** + * @if maint + * Strip top-level cv-qualifiers from the function object and let + * _Weak_result_type_impl perform the real work. + * @endif + */ + template + struct _Weak_result_type + : _Weak_result_type_impl::type> + { + }; + + template + class result_of; + + /** + * @if maint + * Actual implementation of result_of. When _Has_result_type is + * true, gets its result from _Weak_result_type. Otherwise, uses + * the function object's member template result to extract the + * result type. + * @endif + */ + template + struct _Result_of_impl; + + // Handle member data pointers using _Mem_fn's logic + template + struct _Result_of_impl + { + typedef typename _Mem_fn<_Res _Class::*> + ::template _Result_type<_T1>::type type; + }; + + /** + * @if maint + * Determine whether we can determine a result type from @c Functor + * alone. + * @endif + */ + template + class result_of<_Functor(_ArgTypes...)> + : public _Result_of_impl< + _Has_result_type<_Weak_result_type<_Functor> >::value, + _Functor(_ArgTypes...)> + { + }; + + /** + * @if maint + * We already know the result type for @c Functor; use it. + * @endif + */ + template + struct _Result_of_impl + { + typedef typename _Weak_result_type<_Functor>::result_type type; + }; + + /** + * @if maint + * We need to compute the result type for this invocation the hard + * way. + * @endif + */ + template + struct _Result_of_impl + { + typedef typename _Functor + ::template result<_Functor(_ArgTypes...)>::type type; + }; + + /** + * @if maint + * It is unsafe to access ::result when there are zero arguments, so we + * return @c void instead. + * @endif + */ + template + struct _Result_of_impl + { + typedef void type; + }; + + /** + * @if maint + * Determines if the type _Tp derives from unary_function. + * @endif + */ + template + struct _Derives_from_unary_function : __sfinae_types + { + private: + template + static __one __test(const volatile unary_function<_T1, _Res>*); + + // It's tempting to change "..." to const volatile void*, but + // that fails when _Tp is a function type. + static __two __test(...); + + public: + static const bool value = sizeof(__test((_Tp*)0)) == 1; + }; + + /** + * @if maint + * Determines if the type _Tp derives from binary_function. + * @endif + */ + template + struct _Derives_from_binary_function : __sfinae_types + { + private: + template + static __one __test(const volatile binary_function<_T1, _T2, _Res>*); + + // It's tempting to change "..." to const volatile void*, but + // that fails when _Tp is a function type. + static __two __test(...); + + public: + static const bool value = sizeof(__test((_Tp*)0)) == 1; + }; + + /** + * @if maint + * Turns a function type into a function pointer type + * @endif + */ + template::value> + struct _Function_to_function_pointer + { + typedef _Tp type; + }; + + template + struct _Function_to_function_pointer<_Tp, true> + { + typedef _Tp* type; + }; + + /** + * @if maint + * Invoke a function object, which may be either a member pointer or a + * function object. The first parameter will tell which. + * @endif + */ + template + inline + typename __gnu_cxx::__enable_if< + (!is_member_pointer<_Functor>::value + && !is_function<_Functor>::value + && !is_function::type>::value), + typename result_of<_Functor(_Args...)>::type + >::__type + __invoke(_Functor& __f, _Args&... __args) + { + return __f(__args...); + } + + template + inline + typename __gnu_cxx::__enable_if< + (is_member_pointer<_Functor>::value + && !is_function<_Functor>::value + && !is_function::type>::value), + typename result_of<_Functor(_Args...)>::type + >::__type + __invoke(_Functor& __f, _Args&... __args) + { + return mem_fn(__f)(__args...); + } + + // To pick up function references (that will become function pointers) + template + inline + typename __gnu_cxx::__enable_if< + (is_pointer<_Functor>::value + && is_function::type>::value), + typename result_of<_Functor(_Args...)>::type + >::__type + __invoke(_Functor __f, _Args&... __args) + { + return __f(__args...); + } + + /** + * @if maint + * Knowing which of unary_function and binary_function _Tp derives + * from, derives from the same and ensures that reference_wrapper + * will have a weak result type. See cases below. + * @endif + */ + template + struct _Reference_wrapper_base_impl; + + // Not a unary_function or binary_function, so try a weak result type + template + struct _Reference_wrapper_base_impl + : _Weak_result_type<_Tp> + { }; + + // unary_function but not binary_function + template + struct _Reference_wrapper_base_impl + : unary_function + { }; + + // binary_function but not unary_function + template + struct _Reference_wrapper_base_impl + : binary_function + { }; + + // both unary_function and binary_function. import result_type to + // avoid conflicts. + template + struct _Reference_wrapper_base_impl + : unary_function, + binary_function + { + typedef typename _Tp::result_type result_type; + }; + + /** + * @if maint + * Derives from unary_function or binary_function when it + * can. Specializations handle all of the easy cases. The primary + * template determines what to do with a class type, which may + * derive from both unary_function and binary_function. + * @endif + */ + template + struct _Reference_wrapper_base + : _Reference_wrapper_base_impl< + _Derives_from_unary_function<_Tp>::value, + _Derives_from_binary_function<_Tp>::value, + _Tp> + { }; + + // - a function type (unary) + template + struct _Reference_wrapper_base<_Res(_T1)> + : unary_function<_T1, _Res> + { }; + + // - a function type (binary) + template + struct _Reference_wrapper_base<_Res(_T1, _T2)> + : binary_function<_T1, _T2, _Res> + { }; + + // - a function pointer type (unary) + template + struct _Reference_wrapper_base<_Res(*)(_T1)> + : unary_function<_T1, _Res> + { }; + + // - a function pointer type (binary) + template + struct _Reference_wrapper_base<_Res(*)(_T1, _T2)> + : binary_function<_T1, _T2, _Res> + { }; + + // - a pointer to member function type (unary, no qualifiers) + template + struct _Reference_wrapper_base<_Res (_T1::*)()> + : unary_function<_T1*, _Res> + { }; + + // - a pointer to member function type (binary, no qualifiers) + template + struct _Reference_wrapper_base<_Res (_T1::*)(_T2)> + : binary_function<_T1*, _T2, _Res> + { }; + + // - a pointer to member function type (unary, const) + template + struct _Reference_wrapper_base<_Res (_T1::*)() const> + : unary_function + { }; + + // - a pointer to member function type (binary, const) + template + struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const> + : binary_function + { }; + + // - a pointer to member function type (unary, volatile) + template + struct _Reference_wrapper_base<_Res (_T1::*)() volatile> + : unary_function + { }; + + // - a pointer to member function type (binary, volatile) + template + struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile> + : binary_function + { }; + + // - a pointer to member function type (unary, const volatile) + template + struct _Reference_wrapper_base<_Res (_T1::*)() const volatile> + : unary_function + { }; + + // - a pointer to member function type (binary, const volatile) + template + struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile> + : binary_function + { }; + + template + class reference_wrapper + : public _Reference_wrapper_base::type> + { + // If _Tp is a function type, we can't form result_of<_Tp(...)>, + // so turn it into a function pointer type. + typedef typename _Function_to_function_pointer<_Tp>::type + _M_func_type; + + _Tp* _M_data; + public: + typedef _Tp type; + + explicit + reference_wrapper(_Tp& __indata): _M_data(&__indata) + { } + + reference_wrapper(const reference_wrapper<_Tp>& __inref): + _M_data(__inref._M_data) + { } + + reference_wrapper& + operator=(const reference_wrapper<_Tp>& __inref) + { + _M_data = __inref._M_data; + return *this; + } + + operator _Tp&() const + { return this->get(); } + + _Tp& + get() const + { return *_M_data; } + + template + typename result_of<_M_func_type(_Args...)>::type + operator()(_Args&... __args) const + { + return __invoke(get(), __args...); + } + }; + + + // Denotes a reference should be taken to a variable. + template + inline reference_wrapper<_Tp> + ref(_Tp& __t) + { return reference_wrapper<_Tp>(__t); } + + // Denotes a const reference should be taken to a variable. + template + inline reference_wrapper + cref(const _Tp& __t) + { return reference_wrapper(__t); } + + template + inline reference_wrapper<_Tp> + ref(reference_wrapper<_Tp> __t) + { return ref(__t.get()); } + + template + inline reference_wrapper + cref(reference_wrapper<_Tp> __t) + { return cref(__t.get()); } + + template + struct _Mem_fn_const_or_non + { + typedef const _Tp& type; + }; + + template + struct _Mem_fn_const_or_non<_Tp, false> + { + typedef _Tp& type; + }; + + /** + * @if maint + * Derives from @c unary_function or @c binary_function, or perhaps + * nothing, depending on the number of arguments provided. The + * primary template is the basis case, which derives nothing. + * @endif maint + */ + template + struct _Maybe_unary_or_binary_function { }; + + /** + * @if maint + * Derives from @c unary_function, as appropriate. + * @endif + */ + template + struct _Maybe_unary_or_binary_function<_Res, _T1> + : std::unary_function<_T1, _Res> { }; + + /** + * @if maint + * Derives from @c binary_function, as appropriate. + * @endif + */ + template + struct _Maybe_unary_or_binary_function<_Res, _T1, _T2> + : std::binary_function<_T1, _T2, _Res> { }; + + /** + * @if maint + * Implementation of @c mem_fn for member function pointers. + * @endif + */ + template + class _Mem_fn<_Res (_Class::*)(_ArgTypes...)> + : public _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...> + { + typedef _Res (_Class::*_Functor)(_ArgTypes...); + + template + _Res + _M_call(_Tp& __object, const volatile _Class *, + _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const + { return ((*__ptr).*__pmf)(__args...); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(_Class& __object, _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + // Handle pointers + _Res + operator()(_Class* __object, _ArgTypes... __args) const + { return (__object->*__pmf)(__args...); } + + // Handle smart pointers, references and pointers to derived + template + _Res + operator()(_Tp& __object, _ArgTypes... __args) const + { return _M_call(__object, &__object, __args...); } + + private: + _Functor __pmf; + }; + + /** + * @if maint + * Implementation of @c mem_fn for const member function pointers. + * @endif + */ + template + class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const> + : public _Maybe_unary_or_binary_function<_Res, const _Class*, + _ArgTypes...> + { + typedef _Res (_Class::*_Functor)(_ArgTypes...) const; + + template + _Res + _M_call(_Tp& __object, const volatile _Class *, + _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const + { return ((*__ptr).*__pmf)(__args...); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(const _Class& __object, _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + // Handle pointers + _Res + operator()(const _Class* __object, _ArgTypes... __args) const + { return (__object->*__pmf)(__args...); } + + // Handle smart pointers, references and pointers to derived + template + _Res operator()(_Tp& __object, _ArgTypes... __args) const + { return _M_call(__object, &__object, __args...); } + + private: + _Functor __pmf; + }; + + /** + * @if maint + * Implementation of @c mem_fn for volatile member function pointers. + * @endif + */ + template + class _Mem_fn<_Res (_Class::*)(_ArgTypes...) volatile> + : public _Maybe_unary_or_binary_function<_Res, volatile _Class*, + _ArgTypes...> + { + typedef _Res (_Class::*_Functor)(_ArgTypes...) volatile; + + template + _Res + _M_call(_Tp& __object, const volatile _Class *, + _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const + { return ((*__ptr).*__pmf)(__args...); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(volatile _Class& __object, _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + // Handle pointers + _Res + operator()(volatile _Class* __object, _ArgTypes... __args) const + { return (__object->*__pmf)(__args...); } + + // Handle smart pointers, references and pointers to derived + template + _Res + operator()(_Tp& __object, _ArgTypes... __args) const + { return _M_call(__object, &__object, __args...); } + + private: + _Functor __pmf; + }; + + /** + * @if maint + * Implementation of @c mem_fn for const volatile member function pointers. + * @endif + */ + template + class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const volatile> + : public _Maybe_unary_or_binary_function<_Res, const volatile _Class*, + _ArgTypes...> + { + typedef _Res (_Class::*_Functor)(_ArgTypes...) const volatile; + + template + _Res + _M_call(_Tp& __object, const volatile _Class *, + _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + template + _Res + _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const + { return ((*__ptr).*__pmf)(__args...); } + + public: + typedef _Res result_type; + + explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { } + + // Handle objects + _Res + operator()(const volatile _Class& __object, _ArgTypes... __args) const + { return (__object.*__pmf)(__args...); } + + // Handle pointers + _Res + operator()(const volatile _Class* __object, _ArgTypes... __args) const + { return (__object->*__pmf)(__args...); } + + // Handle smart pointers, references and pointers to derived + template + _Res operator()(_Tp& __object, _ArgTypes... __args) const + { return _M_call(__object, &__object, __args...); } + + private: + _Functor __pmf; + }; + + + template + class _Mem_fn<_Res _Class::*> + { + // This bit of genius is due to Peter Dimov, improved slightly by + // Douglas Gregor. + template + _Res& + _M_call(_Tp& __object, _Class *) const + { return __object.*__pm; } + + template + _Res& + _M_call(_Tp& __object, _Up * const *) const + { return (*__object).*__pm; } + + template + const _Res& + _M_call(_Tp& __object, const _Up * const *) const + { return (*__object).*__pm; } + + template + const _Res& + _M_call(_Tp& __object, const _Class *) const + { return __object.*__pm; } + + template + const _Res& + _M_call(_Tp& __ptr, const volatile void*) const + { return (*__ptr).*__pm; } + + template static _Tp& __get_ref(); + + template + static __sfinae_types::__one __check_const(_Tp&, _Class*); + template + static __sfinae_types::__one __check_const(_Tp&, _Up * const *); + template + static __sfinae_types::__two __check_const(_Tp&, const _Up * const *); + template + static __sfinae_types::__two __check_const(_Tp&, const _Class*); + template + static __sfinae_types::__two __check_const(_Tp&, const volatile void*); + + public: + template + struct _Result_type + : _Mem_fn_const_or_non<_Res, + (sizeof(__sfinae_types::__two) + == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))> + { }; + + template + struct result; + + template + struct result<_CVMem(_Tp)> + : public _Result_type<_Tp> { }; + + template + struct result<_CVMem(_Tp&)> + : public _Result_type<_Tp> { }; + + explicit + _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { } + + // Handle objects + _Res& + operator()(_Class& __object) const + { return __object.*__pm; } + + const _Res& + operator()(const _Class& __object) const + { return __object.*__pm; } + + // Handle pointers + _Res& + operator()(_Class* __object) const + { return __object->*__pm; } + + const _Res& + operator()(const _Class* __object) const + { return __object->*__pm; } + + // Handle smart pointers and derived + template + typename _Result_type<_Tp>::type + operator()(_Tp& __unknown) const + { return _M_call(__unknown, &__unknown); } + + private: + _Res _Class::*__pm; + }; + + /** + * @brief Returns a function object that forwards to the member + * pointer @a pm. + */ + template + inline _Mem_fn<_Tp _Class::*> + mem_fn(_Tp _Class::* __pm) + { + return _Mem_fn<_Tp _Class::*>(__pm); + } + + /** + * @brief Determines if the given type _Tp is a function object + * should be treated as a subexpression when evaluating calls to + * function objects returned by bind(). [TR1 3.6.1] + */ + template + struct is_bind_expression + { static const bool value = false; }; + + template + const bool is_bind_expression<_Tp>::value; + + /** + * @brief Determines if the given type _Tp is a placeholder in a + * bind() expression and, if so, which placeholder it is. [TR1 3.6.2] + */ + template + struct is_placeholder + { static const int value = 0; }; + + template + const int is_placeholder<_Tp>::value; + + /** + * @if maint + * The type of placeholder objects defined by libstdc++. + * @endif + */ + template struct _Placeholder { }; + + // Define a large number of placeholders. There is no way to + // simplify this with variadic templates, because we're introducing + // unique names for each. + namespace placeholders { namespace { + _Placeholder<1> _1; + _Placeholder<2> _2; + _Placeholder<3> _3; + _Placeholder<4> _4; + _Placeholder<5> _5; + _Placeholder<6> _6; + _Placeholder<7> _7; + _Placeholder<8> _8; + _Placeholder<9> _9; + _Placeholder<10> _10; + _Placeholder<11> _11; + _Placeholder<12> _12; + _Placeholder<13> _13; + _Placeholder<14> _14; + _Placeholder<15> _15; + _Placeholder<16> _16; + _Placeholder<17> _17; + _Placeholder<18> _18; + _Placeholder<19> _19; + _Placeholder<20> _20; + _Placeholder<21> _21; + _Placeholder<22> _22; + _Placeholder<23> _23; + _Placeholder<24> _24; + _Placeholder<25> _25; + _Placeholder<26> _26; + _Placeholder<27> _27; + _Placeholder<28> _28; + _Placeholder<29> _29; + } } + + /** + * @if maint + * Partial specialization of is_placeholder that provides the placeholder + * number for the placeholder objects defined by libstdc++. + * @endif + */ + template + struct is_placeholder<_Placeholder<_Num> > + { static const int value = _Num; }; + + template + const int is_placeholder<_Placeholder<_Num> >::value; + + /** + * @if maint + * Stores a tuple of indices. Used by bind() to extract the elements + * in a tuple. + * @endif + */ + template + struct _Index_tuple { }; + + /** + * @if maint + * Builds an _Index_tuple<0, 1, 2, ..., _Num-1>. + * @endif + */ + template > + struct _Build_index_tuple; + + template + struct _Build_index_tuple<_Num, _Index_tuple<_Indexes...> > + : _Build_index_tuple<_Num - 1, + _Index_tuple<_Indexes..., sizeof...(_Indexes)> > + { + }; + + template + struct _Build_index_tuple<0, _Index_tuple<_Indexes...> > + { + typedef _Index_tuple<_Indexes...> __type; + }; + + /** + * @if maint + * Used by _Safe_tuple_element to indicate that there is no tuple + * element at this position. + * @endif + */ + struct _No_tuple_element; + + /** + * @if maint + * Implementation helper for _Safe_tuple_element. This primary + * template handles the case where it is safe to use @c + * tuple_element. + * @endif + */ + template + struct _Safe_tuple_element_impl + : tuple_element<__i, _Tuple> { }; + + /** + * @if maint + * Implementation helper for _Safe_tuple_element. This partial + * specialization handles the case where it is not safe to use @c + * tuple_element. We just return @c _No_tuple_element. + * @endif + */ + template + struct _Safe_tuple_element_impl<__i, _Tuple, false> + { + typedef _No_tuple_element type; + }; + + /** + * Like tuple_element, but returns @c _No_tuple_element when + * tuple_element would return an error. + */ + template + struct _Safe_tuple_element + : _Safe_tuple_element_impl<__i, _Tuple, + (__i >= 0 && __i < tuple_size<_Tuple>::value)> + { + }; + + /** + * @if maint + * Maps an argument to bind() into an actual argument to the bound + * function object [TR1 3.6.3/5]. Only the first parameter should + * be specified: the rest are used to determine among the various + * implementations. Note that, although this class is a function + * object, isn't not entirely normal because it takes only two + * parameters regardless of the number of parameters passed to the + * bind expression. The first parameter is the bound argument and + * the second parameter is a tuple containing references to the + * rest of the arguments. + * @endif + */ + template::value, + bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)> + class _Mu; + + /** + * @if maint + * If the argument is reference_wrapper<_Tp>, returns the + * underlying reference. [TR1 3.6.3/5 bullet 1] + * @endif + */ + template + class _Mu, false, false> + { + public: + typedef _Tp& result_type; + + /* Note: This won't actually work for const volatile + * reference_wrappers, because reference_wrapper::get() is const + * but not volatile-qualified. This might be a defect in the TR. + */ + template + result_type + operator()(_CVRef& __arg, const _Tuple&) const volatile + { return __arg.get(); } + }; + + /** + * @if maint + * If the argument is a bind expression, we invoke the underlying + * function object with the same cv-qualifiers as we are given and + * pass along all of our arguments (unwrapped). [TR1 3.6.3/5 bullet 2] + * @endif + */ + template + class _Mu<_Arg, true, false> + { + public: + template class result; + + // Determine the result type when we pass the arguments along. This + // involves passing along the cv-qualifiers placed on _Mu and + // unwrapping the argument bundle. + template + class result<_CVMu(_CVArg, tuple<_Args...>)> + : public result_of<_CVArg(_Args...)> { }; + + template + typename result_of<_CVArg(_Args...)>::type + operator()(_CVArg& __arg, + const tuple<_Args...>& __tuple) const volatile + { + // Construct an index tuple and forward to __call + typedef typename _Build_index_tuple::__type + _Indexes; + return this->__call(__arg, __tuple, _Indexes()); + } + + private: + // Invokes the underlying function object __arg by unpacking all + // of the arguments in the tuple. + template + typename result_of<_CVArg(_Args...)>::type + __call(_CVArg& __arg, const tuple<_Args...>& __tuple, + const _Index_tuple<_Indexes...>&) const volatile + { + return __arg(_GLIBCXX_TR1 get<_Indexes>(__tuple)...); + } + }; + + /** + * @if maint + * If the argument is a placeholder for the Nth argument, returns + * a reference to the Nth argument to the bind function object. + * [TR1 3.6.3/5 bullet 3] + * @endif + */ + template + class _Mu<_Arg, false, true> + { + public: + template class result; + + template + class result<_CVMu(_CVArg, _Tuple)> + { + // Add a reference, if it hasn't already been done for us. + // This allows us to be a little bit sloppy in constructing + // the tuple that we pass to result_of<...>. + typedef typename _Safe_tuple_element<(is_placeholder<_Arg>::value + - 1), _Tuple>::type + __base_type; + + public: + typedef typename add_reference<__base_type>::type type; + }; + + template + typename result<_Mu(_Arg, _Tuple)>::type + operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile + { + return ::std::_GLIBCXX_TR1 get<(is_placeholder<_Arg>::value + - 1)>(__tuple); + } + }; + + /** + * @if maint + * If the argument is just a value, returns a reference to that + * value. The cv-qualifiers on the reference are the same as the + * cv-qualifiers on the _Mu object. [TR1 3.6.3/5 bullet 4] + * @endif + */ + template + class _Mu<_Arg, false, false> + { + public: + template struct result; + + template + struct result<_CVMu(_CVArg, _Tuple)> + { + typedef typename add_reference<_CVArg>::type type; + }; + + // Pick up the cv-qualifiers of the argument + template + _CVArg& + operator()(_CVArg& __arg, const _Tuple&) const volatile + { return __arg; } + }; + + /** + * @if maint + * Maps member pointers into instances of _Mem_fn but leaves all + * other function objects untouched. Used by tr1::bind(). The + * primary template handles the non--member-pointer case. + * @endif + */ + template + struct _Maybe_wrap_member_pointer + { + typedef _Tp type; + + static const _Tp& + __do_wrap(const _Tp& __x) + { return __x; } + }; + + /** + * @if maint + * Maps member pointers into instances of _Mem_fn but leaves all + * other function objects untouched. Used by tr1::bind(). This + * partial specialization handles the member pointer case. + * @endif + */ + template + struct _Maybe_wrap_member_pointer<_Tp _Class::*> + { + typedef _Mem_fn<_Tp _Class::*> type; + + static type + __do_wrap(_Tp _Class::* __pm) + { return type(__pm); } + }; + + /** + * @if maint + * Type of the function object returned from bind(). + * @endif + */ + template + struct _Bind; + + template + class _Bind<_Functor(_Bound_args...)> + : public _Weak_result_type<_Functor> + { + typedef _Bind __self_type; + typedef typename _Build_index_tuple::__type + _Bound_indexes; + + _Functor _M_f; + tuple<_Bound_args...> _M_bound_args; + + // Call unqualified + template + typename result_of< + _Functor(typename result_of<_Mu<_Bound_args> + (_Bound_args, tuple<_Args...>)>::type...) + >::type + __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + // Call as const + template + typename result_of< + const _Functor(typename result_of<_Mu<_Bound_args> + (const _Bound_args, tuple<_Args...>) + >::type...)>::type + __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + // Call as volatile + template + typename result_of< + volatile _Functor(typename result_of<_Mu<_Bound_args> + (volatile _Bound_args, tuple<_Args...>) + >::type...)>::type + __call(const tuple<_Args...>& __args, + _Index_tuple<_Indexes...>) volatile + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + // Call as const volatile + template + typename result_of< + const volatile _Functor(typename result_of<_Mu<_Bound_args> + (const volatile _Bound_args, + tuple<_Args...>) + >::type...)>::type + __call(const tuple<_Args...>& __args, + _Index_tuple<_Indexes...>) const volatile + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + public: + explicit _Bind(_Functor __f, _Bound_args... __bound_args) + : _M_f(__f), _M_bound_args(__bound_args...) { } + + // Call unqualified + template + typename result_of< + _Functor(typename result_of<_Mu<_Bound_args> + (_Bound_args, tuple<_Args...>)>::type...) + >::type + operator()(_Args&... __args) + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + + // Call as const + template + typename result_of< + const _Functor(typename result_of<_Mu<_Bound_args> + (const _Bound_args, tuple<_Args...>)>::type...) + >::type + operator()(_Args&... __args) const + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + + + // Call as volatile + template + typename result_of< + volatile _Functor(typename result_of<_Mu<_Bound_args> + (volatile _Bound_args, tuple<_Args...>)>::type...) + >::type + operator()(_Args&... __args) volatile + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + + + // Call as const volatile + template + typename result_of< + const volatile _Functor(typename result_of<_Mu<_Bound_args> + (const volatile _Bound_args, + tuple<_Args...>)>::type...) + >::type + operator()(_Args&... __args) const volatile + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + }; + + /** + * @if maint + * Type of the function object returned from bind(). + * @endif + */ + template + struct _Bind_result; + + template + class _Bind_result<_Result, _Functor(_Bound_args...)> + { + typedef _Bind_result __self_type; + typedef typename _Build_index_tuple::__type + _Bound_indexes; + + _Functor _M_f; + tuple<_Bound_args...> _M_bound_args; + + // Call unqualified + template + _Result + __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + // Call as const + template + _Result + __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + // Call as volatile + template + _Result + __call(const tuple<_Args...>& __args, + _Index_tuple<_Indexes...>) volatile + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + // Call as const volatile + template + _Result + __call(const tuple<_Args...>& __args, + _Index_tuple<_Indexes...>) const volatile + { + return _M_f(_Mu<_Bound_args>() + (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...); + } + + public: + typedef _Result result_type; + + explicit + _Bind_result(_Functor __f, _Bound_args... __bound_args) + : _M_f(__f), _M_bound_args(__bound_args...) { } + + // Call unqualified + template + result_type + operator()(_Args&... __args) + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + + // Call as const + template + result_type + operator()(_Args&... __args) const + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + + // Call as volatile + template + result_type + operator()(_Args&... __args) volatile + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + + // Call as const volatile + template + result_type + operator()(_Args&... __args) const volatile + { + return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes()); + } + }; + + /** + * @if maint + * Class template _Bind is always a bind expression. + * @endif + */ + template + struct is_bind_expression<_Bind<_Signature> > + { static const bool value = true; }; + + template + const bool is_bind_expression<_Bind<_Signature> >::value; + + /** + * @if maint + * Class template _Bind_result is always a bind expression. + * @endif + */ + template + struct is_bind_expression<_Bind_result<_Result, _Signature> > + { static const bool value = true; }; + + template + const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value; + + template + inline + _Bind::type(_ArgTypes...)> + bind(_Functor __f, _ArgTypes... __args) + { + typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type; + typedef typename __maybe_type::type __functor_type; + typedef _Bind<__functor_type(_ArgTypes...)> __result_type; + return __result_type(__maybe_type::__do_wrap(__f), __args...); + } + + template + inline + _Bind_result<_Result, + typename _Maybe_wrap_member_pointer<_Functor>::type + (_ArgTypes...)> + bind(_Functor __f, _ArgTypes... __args) + { + typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type; + typedef typename __maybe_type::type __functor_type; + typedef _Bind_result<_Result, __functor_type(_ArgTypes...)> + __result_type; + return __result_type(__maybe_type::__do_wrap(__f), __args...); + } + + /** + * @brief Exception class thrown when class template function's + * operator() is called with an empty target. + * + */ + class bad_function_call : public std::exception { }; + + /** + * @if maint + * The integral constant expression 0 can be converted into a + * pointer to this type. It is used by the function template to + * accept NULL pointers. + * @endif + */ + struct _M_clear_type; + + /** + * @if maint + * Trait identifying "location-invariant" types, meaning that the + * address of the object (or any of its members) will not escape. + * Also implies a trivial copy constructor and assignment operator. + * @endif + */ + template + struct __is_location_invariant + : integral_constant::value + || is_member_pointer<_Tp>::value)> + { + }; + + class _Undefined_class; + + union _Nocopy_types + { + void* _M_object; + const void* _M_const_object; + void (*_M_function_pointer)(); + void (_Undefined_class::*_M_member_pointer)(); + }; + + union _Any_data + { + void* _M_access() { return &_M_pod_data[0]; } + const void* _M_access() const { return &_M_pod_data[0]; } + + template + _Tp& + _M_access() + { return *static_cast<_Tp*>(_M_access()); } + + template + const _Tp& + _M_access() const + { return *static_cast(_M_access()); } + + _Nocopy_types _M_unused; + char _M_pod_data[sizeof(_Nocopy_types)]; + }; + + enum _Manager_operation + { + __get_type_info, + __get_functor_ptr, + __clone_functor, + __destroy_functor + }; + + /* Simple type wrapper that helps avoid annoying const problems + when casting between void pointers and pointers-to-pointers. */ + template + struct _Simple_type_wrapper + { + _Simple_type_wrapper(_Tp __value) : __value(__value) { } + + _Tp __value; + }; + + template + struct __is_location_invariant<_Simple_type_wrapper<_Tp> > + : __is_location_invariant<_Tp> + { + }; + + // Converts a reference to a function object into a callable + // function object. + template + inline _Functor& + __callable_functor(_Functor& __f) + { return __f; } + + template + inline _Mem_fn<_Member _Class::*> + __callable_functor(_Member _Class::* &__p) + { return mem_fn(__p); } + + template + inline _Mem_fn<_Member _Class::*> + __callable_functor(_Member _Class::* const &__p) + { return mem_fn(__p); } + + template + class function; + + /** + * @if maint + * Base class of all polymorphic function object wrappers. + * @endif + */ + class _Function_base + { + public: + static const std::size_t _M_max_size = sizeof(_Nocopy_types); + static const std::size_t _M_max_align = __alignof__(_Nocopy_types); + + template + class _Base_manager + { + protected: + static const bool __stored_locally = + (__is_location_invariant<_Functor>::value + && sizeof(_Functor) <= _M_max_size + && __alignof__(_Functor) <= _M_max_align + && (_M_max_align % __alignof__(_Functor) == 0)); + + typedef integral_constant _Local_storage; + + // Retrieve a pointer to the function object + static _Functor* + _M_get_pointer(const _Any_data& __source) + { + const _Functor* __ptr = + __stored_locally? &__source._M_access<_Functor>() + /* have stored a pointer */ : __source._M_access<_Functor*>(); + return const_cast<_Functor*>(__ptr); + } + + // Clone a location-invariant function object that fits within + // an _Any_data structure. + static void + _M_clone(_Any_data& __dest, const _Any_data& __source, true_type) + { + new (__dest._M_access()) _Functor(__source._M_access<_Functor>()); + } + + // Clone a function object that is not location-invariant or + // that cannot fit into an _Any_data structure. + static void + _M_clone(_Any_data& __dest, const _Any_data& __source, false_type) + { + __dest._M_access<_Functor*>() = + new _Functor(*__source._M_access<_Functor*>()); + } + + // Destroying a location-invariant object may still require + // destruction. + static void + _M_destroy(_Any_data& __victim, true_type) + { + __victim._M_access<_Functor>().~_Functor(); + } + + // Destroying an object located on the heap. + static void + _M_destroy(_Any_data& __victim, false_type) + { + delete __victim._M_access<_Functor*>(); + } + + public: + static bool + _M_manager(_Any_data& __dest, const _Any_data& __source, + _Manager_operation __op) + { + switch (__op) + { + case __get_type_info: + __dest._M_access() = &typeid(_Functor); + break; + + case __get_functor_ptr: + __dest._M_access<_Functor*>() = _M_get_pointer(__source); + break; + + case __clone_functor: + _M_clone(__dest, __source, _Local_storage()); + break; + + case __destroy_functor: + _M_destroy(__dest, _Local_storage()); + break; + } + return false; + } + + static void + _M_init_functor(_Any_data& __functor, const _Functor& __f) + { + _M_init_functor(__functor, __f, _Local_storage()); + } + + template + static bool + _M_not_empty_function(const function<_Signature>& __f) + { + return __f; + } + + template + static bool + _M_not_empty_function(const _Tp*& __fp) + { + return __fp; + } + + template + static bool + _M_not_empty_function(_Tp _Class::* const& __mp) + { + return __mp; + } + + template + static bool + _M_not_empty_function(const _Tp&) + { + return true; + } + + private: + static void + _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type) + { + new (__functor._M_access()) _Functor(__f); + } + + static void + _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type) + { + __functor._M_access<_Functor*>() = new _Functor(__f); + } + }; + + template + class _Ref_manager : public _Base_manager<_Functor*> + { + typedef _Function_base::_Base_manager<_Functor*> _Base; + + public: + static bool + _M_manager(_Any_data& __dest, const _Any_data& __source, + _Manager_operation __op) + { + switch (__op) + { + case __get_type_info: + __dest._M_access() = &typeid(_Functor); + break; + + case __get_functor_ptr: + __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source); + return is_const<_Functor>::value; + break; + + default: + _Base::_M_manager(__dest, __source, __op); + } + return false; + } + + static void + _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f) + { + // TBD: Use address_of function instead + _Base::_M_init_functor(__functor, &__f.get()); + } + }; + + _Function_base() : _M_manager(0) { } + + ~_Function_base() + { + if (_M_manager) + _M_manager(_M_functor, _M_functor, __destroy_functor); + } + + + bool _M_empty() const { return !_M_manager; } + + typedef bool (*_Manager_type)(_Any_data&, const _Any_data&, + _Manager_operation); + + _Any_data _M_functor; + _Manager_type _M_manager; + }; + + template + class _Function_handler; + + template + class _Function_handler<_Res(_ArgTypes...), _Functor> + : public _Function_base::_Base_manager<_Functor> + { + typedef _Function_base::_Base_manager<_Functor> _Base; + + public: + static _Res + _M_invoke(const _Any_data& __functor, _ArgTypes... __args) + { + return (*_Base::_M_get_pointer(__functor))(__args...); + } + }; + + template + class _Function_handler + : public _Function_base::_Base_manager<_Functor> + { + typedef _Function_base::_Base_manager<_Functor> _Base; + + public: + static void + _M_invoke(const _Any_data& __functor, _ArgTypes... __args) + { + (*_Base::_M_get_pointer(__functor))(__args...); + } + }; + + template + class _Function_handler<_Res(_ArgTypes...), reference_wrapper<_Functor> > + : public _Function_base::_Ref_manager<_Functor> + { + typedef _Function_base::_Ref_manager<_Functor> _Base; + + public: + static _Res + _M_invoke(const _Any_data& __functor, _ArgTypes... __args) + { + return + __callable_functor(**_Base::_M_get_pointer(__functor))(__args...); + } + }; + + template + class _Function_handler > + : public _Function_base::_Ref_manager<_Functor> + { + typedef _Function_base::_Ref_manager<_Functor> _Base; + + public: + static void + _M_invoke(const _Any_data& __functor, _ArgTypes... __args) + { + __callable_functor(**_Base::_M_get_pointer(__functor))(__args...); + } + }; + + template + class _Function_handler<_Res(_ArgTypes...), _Member _Class::*> + : public _Function_handler + { + typedef _Function_handler + _Base; + + public: + static _Res + _M_invoke(const _Any_data& __functor, _ArgTypes... __args) + { + return _GLIBCXX_TR1 + mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...); + } + }; + + template + class _Function_handler + : public _Function_base::_Base_manager< + _Simple_type_wrapper< _Member _Class::* > > + { + typedef _Member _Class::* _Functor; + typedef _Simple_type_wrapper<_Functor> _Wrapper; + typedef _Function_base::_Base_manager<_Wrapper> _Base; + + public: + static bool + _M_manager(_Any_data& __dest, const _Any_data& __source, + _Manager_operation __op) + { + switch (__op) + { + case __get_type_info: + __dest._M_access() = &typeid(_Functor); + break; + + case __get_functor_ptr: + __dest._M_access<_Functor*>() = + &_Base::_M_get_pointer(__source)->__value; + break; + + default: + _Base::_M_manager(__dest, __source, __op); + } + return false; + } + + static void + _M_invoke(const _Any_data& __functor, _ArgTypes... __args) + { + _GLIBCXX_TR1 + mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...); + } + }; + + template + class function<_Res(_ArgTypes...)> + : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>, + private _Function_base + { + /** + * @if maint + * This class is used to implement the safe_bool idiom. + * @endif + */ + struct _Hidden_type + { + _Hidden_type* _M_bool; + }; + + /** + * @if maint + * This typedef is used to implement the safe_bool idiom. + * @endif + */ + typedef _Hidden_type* _Hidden_type::* _Safe_bool; + + typedef _Res _Signature_type(_ArgTypes...); + + struct _Useless {}; + + public: + typedef _Res result_type; + + // [3.7.2.1] construct/copy/destroy + + /** + * @brief Default construct creates an empty function call wrapper. + * @post @c !(bool)*this + */ + function() : _Function_base() { } + + /** + * @brief Default construct creates an empty function call wrapper. + * @post @c !(bool)*this + */ + function(_M_clear_type*) : _Function_base() { } + + /** + * @brief %Function copy constructor. + * @param x A %function object with identical call signature. + * @pre @c (bool)*this == (bool)x + * + * The newly-created %function contains a copy of the target of @a + * x (if it has one). + */ + function(const function& __x); + + /** + * @brief Builds a %function that targets a copy of the incoming + * function object. + * @param f A %function object that is callable with parameters of + * type @c T1, @c T2, ..., @c TN and returns a value convertible + * to @c Res. + * + * The newly-created %function object will target a copy of @a + * f. If @a f is @c reference_wrapper, then this function + * object will contain a reference to the function object @c + * f.get(). If @a f is a NULL function pointer or NULL + * pointer-to-member, the newly-created object will be empty. + * + * If @a f is a non-NULL function pointer or an object of type @c + * reference_wrapper, this function will not throw. + */ + template + function(_Functor __f, + typename __gnu_cxx::__enable_if< + !is_integral<_Functor>::value, _Useless>::__type + = _Useless()); + + /** + * @brief %Function assignment operator. + * @param x A %function with identical call signature. + * @post @c (bool)*this == (bool)x + * @returns @c *this + * + * The target of @a x is copied to @c *this. If @a x has no + * target, then @c *this will be empty. + * + * If @a x targets a function pointer or a reference to a function + * object, then this operation will not throw an exception. + */ + function& + operator=(const function& __x) + { + function(__x).swap(*this); + return *this; + } + + /** + * @brief %Function assignment to zero. + * @post @c !(bool)*this + * @returns @c *this + * + * The target of @a *this is deallocated, leaving it empty. + */ + function& + operator=(_M_clear_type*) + { + if (_M_manager) + { + _M_manager(_M_functor, _M_functor, __destroy_functor); + _M_manager = 0; + _M_invoker = 0; + } + return *this; + } + + /** + * @brief %Function assignment to a new target. + * @param f A %function object that is callable with parameters of + * type @c T1, @c T2, ..., @c TN and returns a value convertible + * to @c Res. + * @return @c *this + * + * This %function object wrapper will target a copy of @a + * f. If @a f is @c reference_wrapper, then this function + * object will contain a reference to the function object @c + * f.get(). If @a f is a NULL function pointer or NULL + * pointer-to-member, @c this object will be empty. + * + * If @a f is a non-NULL function pointer or an object of type @c + * reference_wrapper, this function will not throw. + */ + template + typename __gnu_cxx::__enable_if::value, + function&>::__type + operator=(_Functor __f) + { + function(__f).swap(*this); + return *this; + } + + // [3.7.2.2] function modifiers + + /** + * @brief Swap the targets of two %function objects. + * @param f A %function with identical call signature. + * + * Swap the targets of @c this function object and @a f. This + * function will not throw an exception. + */ + void swap(function& __x) + { + _Any_data __old_functor = _M_functor; + _M_functor = __x._M_functor; + __x._M_functor = __old_functor; + _Manager_type __old_manager = _M_manager; + _M_manager = __x._M_manager; + __x._M_manager = __old_manager; + _Invoker_type __old_invoker = _M_invoker; + _M_invoker = __x._M_invoker; + __x._M_invoker = __old_invoker; + } + + // [3.7.2.3] function capacity + + /** + * @brief Determine if the %function wrapper has a target. + * + * @return @c true when this %function object contains a target, + * or @c false when it is empty. + * + * This function will not throw an exception. + */ + operator _Safe_bool() const + { + if (_M_empty()) + return 0; + else + return &_Hidden_type::_M_bool; + } + + // [3.7.2.4] function invocation + + /** + * @brief Invokes the function targeted by @c *this. + * @returns the result of the target. + * @throws bad_function_call when @c !(bool)*this + * + * The function call operator invokes the target function object + * stored by @c this. + */ + _Res operator()(_ArgTypes... __args) const; + + // [3.7.2.5] function target access + /** + * @brief Determine the type of the target of this function object + * wrapper. + * + * @returns the type identifier of the target function object, or + * @c typeid(void) if @c !(bool)*this. + * + * This function will not throw an exception. + */ + const type_info& target_type() const; + + /** + * @brief Access the stored target function object. + * + * @return Returns a pointer to the stored target function object, + * if @c typeid(Functor).equals(target_type()); otherwise, a NULL + * pointer. + * + * This function will not throw an exception. + */ + template _Functor* target(); + + /** + * @overload + */ + template const _Functor* target() const; + + private: + // [3.7.2.6] undefined operators + template + void operator==(const function<_Function>&) const; + template + void operator!=(const function<_Function>&) const; + + typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...); + _Invoker_type _M_invoker; + }; + + template + function<_Res(_ArgTypes...)>:: + function(const function& __x) + : _Function_base() + { + if (__x) + { + _M_invoker = __x._M_invoker; + _M_manager = __x._M_manager; + __x._M_manager(_M_functor, __x._M_functor, __clone_functor); + } + } + + template + template + function<_Res(_ArgTypes...)>:: + function(_Functor __f, + typename __gnu_cxx::__enable_if< + !is_integral<_Functor>::value, _Useless>::__type) + : _Function_base() + { + typedef _Function_handler<_Signature_type, _Functor> _My_handler; + + if (_My_handler::_M_not_empty_function(__f)) + { + _M_invoker = &_My_handler::_M_invoke; + _M_manager = &_My_handler::_M_manager; + _My_handler::_M_init_functor(_M_functor, __f); + } + } + + template + _Res + function<_Res(_ArgTypes...)>:: + operator()(_ArgTypes... __args) const + { + if (_M_empty()) + { +#if __EXCEPTIONS + throw bad_function_call(); +#else + __builtin_abort(); +#endif + } + return _M_invoker(_M_functor, __args...); + } + + template + const type_info& + function<_Res(_ArgTypes...)>:: + target_type() const + { + if (_M_manager) + { + _Any_data __typeinfo_result; + _M_manager(__typeinfo_result, _M_functor, __get_type_info); + return *__typeinfo_result._M_access(); + } + else + return typeid(void); + } + + template + template + _Functor* + function<_Res(_ArgTypes...)>:: + target() + { + if (typeid(_Functor) == target_type() && _M_manager) + { + _Any_data __ptr; + if (_M_manager(__ptr, _M_functor, __get_functor_ptr) + && !is_const<_Functor>::value) + return 0; + else + return __ptr._M_access<_Functor*>(); + } + else + return 0; + } + + template + template + const _Functor* + function<_Res(_ArgTypes...)>:: + target() const + { + if (typeid(_Functor) == target_type() && _M_manager) + { + _Any_data __ptr; + _M_manager(__ptr, _M_functor, __get_functor_ptr); + return __ptr._M_access(); + } + else + return 0; + } + + // [3.7.2.7] null pointer comparisons + + /** + * @brief Compares a polymorphic function object wrapper against 0 + * (the NULL pointer). + * @returns @c true if the wrapper has no target, @c false otherwise + * + * This function will not throw an exception. + */ + template + inline bool + operator==(const function<_Signature>& __f, _M_clear_type*) + { + return !__f; + } + + /** + * @overload + */ + template + inline bool + operator==(_M_clear_type*, const function<_Signature>& __f) + { + return !__f; + } + + /** + * @brief Compares a polymorphic function object wrapper against 0 + * (the NULL pointer). + * @returns @c false if the wrapper has no target, @c true otherwise + * + * This function will not throw an exception. + */ + template + inline bool + operator!=(const function<_Signature>& __f, _M_clear_type*) + { + return __f; + } + + /** + * @overload + */ + template + inline bool + operator!=(_M_clear_type*, const function<_Signature>& __f) + { + return __f; + } + + // [3.7.2.8] specialized algorithms + + /** + * @brief Swap the targets of two polymorphic function object wrappers. + * + * This function will not throw an exception. + */ + template + inline void + swap(function<_Signature>& __x, function<_Signature>& __y) + { + __x.swap(__y); + } + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/functional_hash.h b/libstdc++-v3/include/tr1_impl/functional_hash.h new file mode 100644 index 0000000..3b1a758 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/functional_hash.h @@ -0,0 +1,223 @@ +// TR1 functional -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/functional_hash.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // Definition of default hash function std::tr1::hash<>. The types for + // which std::tr1::hash is defined is in clause 6.3.3. of the PDTR. + template + struct hash; + +#define _TR1_hashtable_define_trivial_hash(_Tp) \ + template<> \ + struct hash<_Tp> \ + : public std::unary_function<_Tp, std::size_t> \ + { \ + std::size_t \ + operator()(_Tp __val) const \ + { return static_cast(__val); } \ + } + + _TR1_hashtable_define_trivial_hash(bool); + _TR1_hashtable_define_trivial_hash(char); + _TR1_hashtable_define_trivial_hash(signed char); + _TR1_hashtable_define_trivial_hash(unsigned char); + _TR1_hashtable_define_trivial_hash(wchar_t); + _TR1_hashtable_define_trivial_hash(short); + _TR1_hashtable_define_trivial_hash(int); + _TR1_hashtable_define_trivial_hash(long); + _TR1_hashtable_define_trivial_hash(long long); + _TR1_hashtable_define_trivial_hash(unsigned short); + _TR1_hashtable_define_trivial_hash(unsigned int); + _TR1_hashtable_define_trivial_hash(unsigned long); + _TR1_hashtable_define_trivial_hash(unsigned long long); + +#undef _TR1_hashtable_define_trivial_hash + + template + struct hash<_Tp*> + : public std::unary_function<_Tp*, std::size_t> + { + std::size_t + operator()(_Tp* __p) const + { return reinterpret_cast(__p); } + }; + + // Fowler / Noll / Vo (FNV) Hash (type FNV-1a) + // (used by the next specializations of std::tr1::hash<>) + + // Dummy generic implementation (for sizeof(size_t) != 4, 8). + template + struct _Fnv_hash + { + static std::size_t + hash(const char* __first, std::size_t __length) + { + std::size_t __result = 0; + for (; __length > 0; --__length) + __result = (__result * 131) + *__first++; + return __result; + } + }; + + template<> + struct _Fnv_hash<4> + { + static std::size_t + hash(const char* __first, std::size_t __length) + { + std::size_t __result = static_cast(2166136261UL); + for (; __length > 0; --__length) + { + __result ^= static_cast(*__first++); + __result *= static_cast(16777619UL); + } + return __result; + } + }; + + template<> + struct _Fnv_hash<8> + { + static std::size_t + hash(const char* __first, std::size_t __length) + { + std::size_t __result = + static_cast(14695981039346656037ULL); + for (; __length > 0; --__length) + { + __result ^= static_cast(*__first++); + __result *= static_cast(1099511628211ULL); + } + return __result; + } + }; + + // XXX String and floating point hashes probably shouldn't be inline + // member functions, since are nontrivial. Once we have the framework + // for TR1 .cc files, these should go in one. + template<> + struct hash + : public std::unary_function + { + std::size_t + operator()(const std::string& __s) const + { return _Fnv_hash<>::hash(__s.data(), __s.length()); } + }; + +#ifdef _GLIBCXX_USE_WCHAR_T + template<> + struct hash + : public std::unary_function + { + std::size_t + operator()(const std::wstring& __s) const + { + return _Fnv_hash<>::hash(reinterpret_cast(__s.data()), + __s.length() * sizeof(wchar_t)); + } + }; +#endif + + template<> + struct hash + : public std::unary_function + { + std::size_t + operator()(float __fval) const + { + std::size_t __result = 0; + + // 0 and -0 both hash to zero. + if (__fval != 0.0f) + __result = _Fnv_hash<>::hash(reinterpret_cast(&__fval), + sizeof(__fval)); + return __result; + } + }; + + template<> + struct hash + : public std::unary_function + { + std::size_t + operator()(double __dval) const + { + std::size_t __result = 0; + + // 0 and -0 both hash to zero. + if (__dval != 0.0) + __result = _Fnv_hash<>::hash(reinterpret_cast(&__dval), + sizeof(__dval)); + return __result; + } + }; + + // For long double, careful with random padding bits (e.g., on x86, + // 10 bytes -> 12 bytes) and resort to frexp. + template<> + struct hash + : public std::unary_function + { + std::size_t + operator()(long double __ldval) const + { + std::size_t __result = 0; + + int __exponent; + __ldval = std::frexp(__ldval, &__exponent); + __ldval = __ldval < 0.0l ? -(__ldval + 0.5l) : __ldval; + + const long double __mult = + __gnu_cxx::__numeric_traits::__max + 1.0l; + __ldval *= __mult; + + // Try to use all the bits of the mantissa (really necessary only + // on 32-bit targets, at least for 80-bit floating point formats). + const std::size_t __hibits = (std::size_t)__ldval; + __ldval = (__ldval - (long double)__hibits) * __mult; + + const std::size_t __coeff = + __gnu_cxx::__numeric_traits::__max / __LDBL_MAX_EXP__; + + __result = __hibits + (std::size_t)__ldval + __coeff * __exponent; + + return __result; + } + }; + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/hashtable b/libstdc++-v3/include/tr1_impl/hashtable new file mode 100644 index 0000000..acdeb66 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/hashtable @@ -0,0 +1,1190 @@ +// Internal header for TR1 unordered_set and unordered_map -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/hashtable + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +// This header file defines std::tr1::hashtable, which is used to +// implement std::tr1::unordered_set, std::tr1::unordered_map, +// std::tr1::unordered_multiset, and std::tr1::unordered_multimap. +// hashtable has many template parameters, partly to accommodate +// the differences between those four classes and partly to +// accommodate policy choices that go beyond what TR1 calls for. + +// Class template hashtable attempts to encapsulate all reasonable +// variation among hash tables that use chaining. It does not handle +// open addressing. + +// References: +// M. Austern, "A Proposal to Add Hash Tables to the Standard +// Library (revision 4)," WG21 Document N1456=03-0039, 2003. +// D. E. Knuth, The Art of Computer Programming, v. 3, Sorting and Searching. +// A. Tavori and V. Dreizin, "Policy-Based Data Structures", 2004. +// http://gcc.gnu.org/onlinedocs/libstdc++/ext/pb_ds/index.html + +#include + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // Class template _Hashtable, class definition. + + // Meaning of class template _Hashtable's template parameters + + // _Key and _Value: arbitrary CopyConstructible types. + + // _Allocator: an allocator type ([lib.allocator.requirements]) whose + // value type is Value. As a conforming extension, we allow for + // value type != Value. + + // _ExtractKey: function object that takes a object of type Value + // and returns a value of type _Key. + + // _Equal: function object that takes two objects of type k and returns + // a bool-like value that is true if the two objects are considered equal. + + // _H1: the hash function. A unary function object with argument type + // Key and result type size_t. Return values should be distributed + // over the entire range [0, numeric_limits:::max()]. + + // _H2: the range-hashing function (in the terminology of Tavori and + // Dreizin). A binary function object whose argument types and result + // type are all size_t. Given arguments r and N, the return value is + // in the range [0, N). + + // _Hash: the ranged hash function (Tavori and Dreizin). A binary function + // whose argument types are _Key and size_t and whose result type is + // size_t. Given arguments k and N, the return value is in the range + // [0, N). Default: hash(k, N) = h2(h1(k), N). If _Hash is anything other + // than the default, _H1 and _H2 are ignored. + + // _RehashPolicy: Policy class with three members, all of which govern + // the bucket count. _M_next_bkt(n) returns a bucket count no smaller + // than n. _M_bkt_for_elements(n) returns a bucket count appropriate + // for an element count of n. _M_need_rehash(n_bkt, n_elt, n_ins) + // determines whether, if the current bucket count is n_bkt and the + // current element count is n_elt, we need to increase the bucket + // count. If so, returns make_pair(true, n), where n is the new + // bucket count. If not, returns make_pair(false, ). + + // ??? Right now it is hard-wired that the number of buckets never + // shrinks. Should we allow _RehashPolicy to change that? + + // __cache_hash_code: bool. true if we store the value of the hash + // function along with the value. This is a time-space tradeoff. + // Storing it may improve lookup speed by reducing the number of times + // we need to call the Equal function. + + // __constant_iterators: bool. true if iterator and const_iterator are + // both constant iterator types. This is true for unordered_set and + // unordered_multiset, false for unordered_map and unordered_multimap. + + // __unique_keys: bool. true if the return value of _Hashtable::count(k) + // is always at most one, false if it may be an arbitrary number. This + // true for unordered_set and unordered_map, false for unordered_multiset + // and unordered_multimap. + + template + class _Hashtable + : public __detail::_Rehash_base<_RehashPolicy, + _Hashtable<_Key, _Value, _Allocator, + _ExtractKey, + _Equal, _H1, _H2, _Hash, + _RehashPolicy, + __cache_hash_code, + __constant_iterators, + __unique_keys> >, + public __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, + _H1, _H2, _Hash, __cache_hash_code>, + public __detail::_Map_base<_Key, _Value, _ExtractKey, __unique_keys, + _Hashtable<_Key, _Value, _Allocator, + _ExtractKey, + _Equal, _H1, _H2, _Hash, + _RehashPolicy, + __cache_hash_code, + __constant_iterators, + __unique_keys> > + { + public: + typedef _Allocator allocator_type; + typedef _Value value_type; + typedef _Key key_type; + typedef _Equal key_equal; + // mapped_type, if present, comes from _Map_base. + // hasher, if present, comes from _Hash_code_base. + typedef typename _Allocator::difference_type difference_type; + typedef typename _Allocator::size_type size_type; + typedef typename _Allocator::reference reference; + typedef typename _Allocator::const_reference const_reference; + + typedef __detail::_Node_iterator + local_iterator; + typedef __detail::_Node_const_iterator + const_local_iterator; + + typedef __detail::_Hashtable_iterator + iterator; + typedef __detail::_Hashtable_const_iterator + const_iterator; + + template + friend struct __detail::_Map_base; + + private: + typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node; + typedef typename _Allocator::template rebind<_Node>::other + _Node_allocator_type; + typedef typename _Allocator::template rebind<_Node*>::other + _Bucket_allocator_type; + + typedef typename _Allocator::template rebind<_Value>::other + _Value_allocator_type; + + _Node_allocator_type _M_node_allocator; + _Node** _M_buckets; + size_type _M_bucket_count; + size_type _M_element_count; + _RehashPolicy _M_rehash_policy; + + _Node* + _M_allocate_node(const value_type& __v); + + void + _M_deallocate_node(_Node* __n); + + void + _M_deallocate_nodes(_Node**, size_type); + + _Node** + _M_allocate_buckets(size_type __n); + + void + _M_deallocate_buckets(_Node**, size_type __n); + + public: + // Constructor, destructor, assignment, swap + _Hashtable(size_type __bucket_hint, + const _H1&, const _H2&, const _Hash&, + const _Equal&, const _ExtractKey&, + const allocator_type&); + + template + _Hashtable(_InputIterator __first, _InputIterator __last, + size_type __bucket_hint, + const _H1&, const _H2&, const _Hash&, + const _Equal&, const _ExtractKey&, + const allocator_type&); + + _Hashtable(const _Hashtable&); + + _Hashtable& + operator=(const _Hashtable&); + + ~_Hashtable(); + + void swap(_Hashtable&); + + // Basic container operations + iterator + begin() + { + iterator __i(_M_buckets); + if (!__i._M_cur_node) + __i._M_incr_bucket(); + return __i; + } + + const_iterator + begin() const + { + const_iterator __i(_M_buckets); + if (!__i._M_cur_node) + __i._M_incr_bucket(); + return __i; + } + + iterator + end() + { return iterator(_M_buckets + _M_bucket_count); } + + const_iterator + end() const + { return const_iterator(_M_buckets + _M_bucket_count); } + + size_type + size() const + { return _M_element_count; } + + bool + empty() const + { return size() == 0; } + + allocator_type + get_allocator() const + { return allocator_type(_M_node_allocator); } + + _Value_allocator_type + _M_get_Value_allocator() const + { return _Value_allocator_type(_M_node_allocator); } + + size_type + max_size() const + { return _M_get_Value_allocator().max_size(); } + + // Observers + key_equal + key_eq() const + { return this->_M_eq; } + + // hash_function, if present, comes from _Hash_code_base. + + // Bucket operations + size_type + bucket_count() const + { return _M_bucket_count; } + + size_type + max_bucket_count() const + { return max_size(); } + + size_type + bucket_size(size_type __n) const + { return std::distance(begin(__n), end(__n)); } + + size_type + bucket(const key_type& __k) const + { + return this->_M_bucket_index(__k, this->_M_hash_code(__k), + bucket_count()); + } + + local_iterator + begin(size_type __n) + { return local_iterator(_M_buckets[__n]); } + + local_iterator + end(size_type) + { return local_iterator(0); } + + const_local_iterator + begin(size_type __n) const + { return const_local_iterator(_M_buckets[__n]); } + + const_local_iterator + end(size_type) const + { return const_local_iterator(0); } + + float + load_factor() const + { + return static_cast(size()) / static_cast(bucket_count()); + } + + // max_load_factor, if present, comes from _Rehash_base. + + // Generalization of max_load_factor. Extension, not found in TR1. Only + // useful if _RehashPolicy is something other than the default. + const _RehashPolicy& + __rehash_policy() const + { return _M_rehash_policy; } + + void + __rehash_policy(const _RehashPolicy&); + + // Lookup. + iterator + find(const key_type& __k); + + const_iterator + find(const key_type& __k) const; + + size_type + count(const key_type& __k) const; + + std::pair + equal_range(const key_type& __k); + + std::pair + equal_range(const key_type& __k) const; + + private: // Find, insert and erase helper functions + // ??? This dispatching is a workaround for the fact that we don't + // have partial specialization of member templates; it would be + // better to just specialize insert on __unique_keys. There may be a + // cleaner workaround. + typedef typename __gnu_cxx::__conditional_type<__unique_keys, + std::pair, iterator>::__type + _Insert_Return_Type; + + typedef typename __gnu_cxx::__conditional_type<__unique_keys, + std::_Select1st<_Insert_Return_Type>, + std::_Identity<_Insert_Return_Type> + >::__type + _Insert_Conv_Type; + + _Node* + _M_find_node(_Node*, const key_type&, + typename _Hashtable::_Hash_code_type) const; + + iterator + _M_insert_bucket(const value_type&, size_type, + typename _Hashtable::_Hash_code_type); + + std::pair + _M_insert(const value_type&, std::_GLIBCXX_TR1 true_type); + + iterator + _M_insert(const value_type&, std::_GLIBCXX_TR1 false_type); + + void + _M_erase_node(_Node*, _Node**); + + public: + // Insert and erase + _Insert_Return_Type + insert(const value_type& __v) + { return _M_insert(__v, std::_GLIBCXX_TR1 integral_constant()); } + + iterator + insert(iterator, const value_type& __v) + { return iterator(_Insert_Conv_Type()(this->insert(__v))); } + + const_iterator + insert(const_iterator, const value_type& __v) + { return const_iterator(_Insert_Conv_Type()(this->insert(__v))); } + + template + void + insert(_InputIterator __first, _InputIterator __last); + + iterator + erase(iterator); + + const_iterator + erase(const_iterator); + + size_type + erase(const key_type&); + + iterator + erase(iterator, iterator); + + const_iterator + erase(const_iterator, const_iterator); + + void + clear(); + + // Set number of buckets to be appropriate for container of n element. + void rehash(size_type __n); + + private: + // Unconditionally change size of bucket array to n. + void _M_rehash(size_type __n); + }; + + + // Definitions of class template _Hashtable's out-of-line member functions. + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::_Node* + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_allocate_node(const value_type& __v) + { + _Node* __n = _M_node_allocator.allocate(1); + try + { + _M_get_Value_allocator().construct(&__n->_M_v, __v); + __n->_M_next = 0; + return __n; + } + catch(...) + { + _M_node_allocator.deallocate(__n, 1); + __throw_exception_again; + } + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_deallocate_node(_Node* __n) + { + _M_get_Value_allocator().destroy(&__n->_M_v); + _M_node_allocator.deallocate(__n, 1); + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_deallocate_nodes(_Node** __array, size_type __n) + { + for (size_type __i = 0; __i < __n; ++__i) + { + _Node* __p = __array[__i]; + while (__p) + { + _Node* __tmp = __p; + __p = __p->_M_next; + _M_deallocate_node(__tmp); + } + __array[__i] = 0; + } + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::_Node** + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_allocate_buckets(size_type __n) + { + _Bucket_allocator_type __alloc(_M_node_allocator); + + // We allocate one extra bucket to hold a sentinel, an arbitrary + // non-null pointer. Iterator increment relies on this. + _Node** __p = __alloc.allocate(__n + 1); + std::fill(__p, __p + __n, (_Node*) 0); + __p[__n] = reinterpret_cast<_Node*>(0x1000); + return __p; + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_deallocate_buckets(_Node** __p, size_type __n) + { + _Bucket_allocator_type __alloc(_M_node_allocator); + __alloc.deallocate(__p, __n + 1); + } + + template + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _Hashtable(size_type __bucket_hint, + const _H1& __h1, const _H2& __h2, const _Hash& __h, + const _Equal& __eq, const _ExtractKey& __exk, + const allocator_type& __a) + : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(), + __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, + _H1, _H2, _Hash, __chc>(__exk, __eq, + __h1, __h2, __h), + __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(), + _M_node_allocator(__a), + _M_bucket_count(0), + _M_element_count(0), + _M_rehash_policy() + { + _M_bucket_count = _M_rehash_policy._M_next_bkt(__bucket_hint); + _M_buckets = _M_allocate_buckets(_M_bucket_count); + } + + template + template + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _Hashtable(_InputIterator __f, _InputIterator __l, + size_type __bucket_hint, + const _H1& __h1, const _H2& __h2, const _Hash& __h, + const _Equal& __eq, const _ExtractKey& __exk, + const allocator_type& __a) + : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(), + __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, + _H1, _H2, _Hash, __chc>(__exk, __eq, + __h1, __h2, __h), + __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(), + _M_node_allocator(__a), + _M_bucket_count(0), + _M_element_count(0), + _M_rehash_policy() + { + _M_bucket_count = std::max(_M_rehash_policy._M_next_bkt(__bucket_hint), + _M_rehash_policy. + _M_bkt_for_elements(__detail:: + __distance_fw(__f, + __l))); + _M_buckets = _M_allocate_buckets(_M_bucket_count); + try + { + for (; __f != __l; ++__f) + this->insert(*__f); + } + catch(...) + { + clear(); + _M_deallocate_buckets(_M_buckets, _M_bucket_count); + __throw_exception_again; + } + } + + template + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _Hashtable(const _Hashtable& __ht) + : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(__ht), + __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, + _H1, _H2, _Hash, __chc>(__ht), + __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(__ht), + _M_node_allocator(__ht._M_node_allocator), + _M_bucket_count(__ht._M_bucket_count), + _M_element_count(__ht._M_element_count), + _M_rehash_policy(__ht._M_rehash_policy) + { + _M_buckets = _M_allocate_buckets(_M_bucket_count); + try + { + for (size_type __i = 0; __i < __ht._M_bucket_count; ++__i) + { + _Node* __n = __ht._M_buckets[__i]; + _Node** __tail = _M_buckets + __i; + while (__n) + { + *__tail = _M_allocate_node(__n->_M_v); + this->_M_copy_code(*__tail, __n); + __tail = &((*__tail)->_M_next); + __n = __n->_M_next; + } + } + } + catch(...) + { + clear(); + _M_deallocate_buckets(_M_buckets, _M_bucket_count); + __throw_exception_again; + } + } + + template + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>& + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + operator=(const _Hashtable& __ht) + { + _Hashtable __tmp(__ht); + this->swap(__tmp); + return *this; + } + + template + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + ~_Hashtable() + { + clear(); + _M_deallocate_buckets(_M_buckets, _M_bucket_count); + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + swap(_Hashtable& __x) + { + // The only base class with member variables is hash_code_base. We + // define _Hash_code_base::_M_swap because different specializations + // have different members. + __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, + _H1, _H2, _Hash, __chc>::_M_swap(__x); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Node_allocator_type>::_S_do_it(_M_node_allocator, + __x._M_node_allocator); + + std::swap(_M_rehash_policy, __x._M_rehash_policy); + std::swap(_M_buckets, __x._M_buckets); + std::swap(_M_bucket_count, __x._M_bucket_count); + std::swap(_M_element_count, __x._M_element_count); + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + __rehash_policy(const _RehashPolicy& __pol) + { + _M_rehash_policy = __pol; + size_type __n_bkt = __pol._M_bkt_for_elements(_M_element_count); + if (__n_bkt > _M_bucket_count) + _M_rehash(__n_bkt); + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + find(const key_type& __k) + { + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + _Node* __p = _M_find_node(_M_buckets[__n], __k, __code); + return __p ? iterator(__p, _M_buckets + __n) : this->end(); + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::const_iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + find(const key_type& __k) const + { + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + _Node* __p = _M_find_node(_M_buckets[__n], __k, __code); + return __p ? const_iterator(__p, _M_buckets + __n) : this->end(); + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::size_type + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + count(const key_type& __k) const + { + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + std::size_t __result = 0; + for (_Node* __p = _M_buckets[__n]; __p; __p = __p->_M_next) + if (this->_M_compare(__k, __code, __p)) + ++__result; + return __result; + } + + template + std::pair::iterator, + typename _Hashtable<_Key, _Value, _Allocator, + _ExtractKey, _Equal, _H1, + _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::iterator> + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + equal_range(const key_type& __k) + { + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + _Node** __head = _M_buckets + __n; + _Node* __p = _M_find_node(*__head, __k, __code); + + if (__p) + { + _Node* __p1 = __p->_M_next; + for (; __p1; __p1 = __p1->_M_next) + if (!this->_M_compare(__k, __code, __p1)) + break; + + iterator __first(__p, __head); + iterator __last(__p1, __head); + if (!__p1) + __last._M_incr_bucket(); + return std::make_pair(__first, __last); + } + else + return std::make_pair(this->end(), this->end()); + } + + template + std::pair::const_iterator, + typename _Hashtable<_Key, _Value, _Allocator, + _ExtractKey, _Equal, _H1, + _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::const_iterator> + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + equal_range(const key_type& __k) const + { + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + _Node** __head = _M_buckets + __n; + _Node* __p = _M_find_node(*__head, __k, __code); + + if (__p) + { + _Node* __p1 = __p->_M_next; + for (; __p1; __p1 = __p1->_M_next) + if (!this->_M_compare(__k, __code, __p1)) + break; + + const_iterator __first(__p, __head); + const_iterator __last(__p1, __head); + if (!__p1) + __last._M_incr_bucket(); + return std::make_pair(__first, __last); + } + else + return std::make_pair(this->end(), this->end()); + } + + // Find the node whose key compares equal to k, beginning the search + // at p (usually the head of a bucket). Return nil if no node is found. + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, + _Equal, _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::_Node* + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_find_node(_Node* __p, const key_type& __k, + typename _Hashtable::_Hash_code_type __code) const + { + for (; __p; __p = __p->_M_next) + if (this->_M_compare(__k, __code, __p)) + return __p; + return false; + } + + // Insert v in bucket n (assumes no element with its key already present). + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_insert_bucket(const value_type& __v, size_type __n, + typename _Hashtable::_Hash_code_type __code) + { + std::pair __do_rehash + = _M_rehash_policy._M_need_rehash(_M_bucket_count, + _M_element_count, 1); + + // Allocate the new node before doing the rehash so that we don't + // do a rehash if the allocation throws. + _Node* __new_node = _M_allocate_node(__v); + + try + { + if (__do_rehash.first) + { + const key_type& __k = this->_M_extract(__v); + __n = this->_M_bucket_index(__k, __code, __do_rehash.second); + _M_rehash(__do_rehash.second); + } + + __new_node->_M_next = _M_buckets[__n]; + this->_M_store_code(__new_node, __code); + _M_buckets[__n] = __new_node; + ++_M_element_count; + return iterator(__new_node, _M_buckets + __n); + } + catch(...) + { + _M_deallocate_node(__new_node); + __throw_exception_again; + } + } + + // Insert v if no element with its key is already present. + template + std::pair::iterator, bool> + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_insert(const value_type& __v, std::_GLIBCXX_TR1 true_type) + { + const key_type& __k = this->_M_extract(__v); + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + size_type __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + + if (_Node* __p = _M_find_node(_M_buckets[__n], __k, __code)) + return std::make_pair(iterator(__p, _M_buckets + __n), false); + return std::make_pair(_M_insert_bucket(__v, __n, __code), true); + } + + // Insert v unconditionally. + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_insert(const value_type& __v, std::_GLIBCXX_TR1 false_type) + { + std::pair __do_rehash + = _M_rehash_policy._M_need_rehash(_M_bucket_count, + _M_element_count, 1); + if (__do_rehash.first) + _M_rehash(__do_rehash.second); + + const key_type& __k = this->_M_extract(__v); + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + size_type __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + + // First find the node, avoid leaking new_node if compare throws. + _Node* __prev = _M_find_node(_M_buckets[__n], __k, __code); + _Node* __new_node = _M_allocate_node(__v); + + if (__prev) + { + __new_node->_M_next = __prev->_M_next; + __prev->_M_next = __new_node; + } + else + { + __new_node->_M_next = _M_buckets[__n]; + _M_buckets[__n] = __new_node; + } + this->_M_store_code(__new_node, __code); + + ++_M_element_count; + return iterator(__new_node, _M_buckets + __n); + } + + // For erase(iterator) and erase(const_iterator). + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_erase_node(_Node* __p, _Node** __b) + { + _Node* __cur = *__b; + if (__cur == __p) + *__b = __cur->_M_next; + else + { + _Node* __next = __cur->_M_next; + while (__next != __p) + { + __cur = __next; + __next = __cur->_M_next; + } + __cur->_M_next = __next->_M_next; + } + + _M_deallocate_node(__p); + --_M_element_count; + } + + template + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + insert(_InputIterator __first, _InputIterator __last) + { + size_type __n_elt = __detail::__distance_fw(__first, __last); + std::pair __do_rehash + = _M_rehash_policy._M_need_rehash(_M_bucket_count, + _M_element_count, __n_elt); + if (__do_rehash.first) + _M_rehash(__do_rehash.second); + + for (; __first != __last; ++__first) + this->insert(*__first); + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + erase(iterator __it) + { + iterator __result = __it; + ++__result; + _M_erase_node(__it._M_cur_node, __it._M_cur_bucket); + return __result; + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::const_iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + erase(const_iterator __it) + { + const_iterator __result = __it; + ++__result; + _M_erase_node(__it._M_cur_node, __it._M_cur_bucket); + return __result; + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::size_type + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + erase(const key_type& __k) + { + typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); + std::size_t __n = this->_M_bucket_index(__k, __code, _M_bucket_count); + size_type __result = 0; + + _Node** __slot = _M_buckets + __n; + while (*__slot && !this->_M_compare(__k, __code, *__slot)) + __slot = &((*__slot)->_M_next); + + _Node** __saved_slot = 0; + while (*__slot && this->_M_compare(__k, __code, *__slot)) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 526. Is it undefined if a function in the standard changes + // in parameters? + if (&this->_M_extract((*__slot)->_M_v) != &__k) + { + _Node* __p = *__slot; + *__slot = __p->_M_next; + _M_deallocate_node(__p); + --_M_element_count; + ++__result; + } + else + { + __saved_slot = __slot; + __slot = &((*__slot)->_M_next); + } + } + + if (__saved_slot) + { + _Node* __p = *__saved_slot; + *__saved_slot = __p->_M_next; + _M_deallocate_node(__p); + --_M_element_count; + ++__result; + } + + return __result; + } + + // ??? This could be optimized by taking advantage of the bucket + // structure, but it's not clear that it's worth doing. It probably + // wouldn't even be an optimization unless the load factor is large. + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + erase(iterator __first, iterator __last) + { + while (__first != __last) + __first = this->erase(__first); + return __last; + } + + template + typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, + __chc, __cit, __uk>::const_iterator + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + erase(const_iterator __first, const_iterator __last) + { + while (__first != __last) + __first = this->erase(__first); + return __last; + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + clear() + { + _M_deallocate_nodes(_M_buckets, _M_bucket_count); + _M_element_count = 0; + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + rehash(size_type __n) + { + _M_rehash(std::max(_M_rehash_policy._M_next_bkt(__n), + _M_rehash_policy._M_bkt_for_elements(_M_element_count + + 1))); + } + + template + void + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _M_rehash(size_type __n) + { + _Node** __new_array = _M_allocate_buckets(__n); + try + { + for (size_type __i = 0; __i < _M_bucket_count; ++__i) + while (_Node* __p = _M_buckets[__i]) + { + std::size_t __new_index = this->_M_bucket_index(__p, __n); + _M_buckets[__i] = __p->_M_next; + __p->_M_next = __new_array[__new_index]; + __new_array[__new_index] = __p; + } + _M_deallocate_buckets(_M_buckets, _M_bucket_count); + _M_bucket_count = __n; + _M_buckets = __new_array; + } + catch(...) + { + // A failure here means that a hash function threw an exception. + // We can't restore the previous state without calling the hash + // function again, so the only sensible recovery is to delete + // everything. + _M_deallocate_nodes(__new_array, __n); + _M_deallocate_buckets(__new_array, __n); + _M_deallocate_nodes(_M_buckets, _M_bucket_count); + _M_element_count = 0; + __throw_exception_again; + } + } + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/hashtable_policy.h b/libstdc++-v3/include/tr1_impl/hashtable_policy.h new file mode 100644 index 0000000..79740fa --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/hashtable_policy.h @@ -0,0 +1,896 @@ +// Internal policy header for TR1 unordered_set and unordered_map -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/hashtable_policy.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + +namespace __detail +{ + // Helper function: return distance(first, last) for forward + // iterators, or 0 for input iterators. + template + inline typename std::iterator_traits<_Iterator>::difference_type + __distance_fw(_Iterator __first, _Iterator __last, + std::input_iterator_tag) + { return 0; } + + template + inline typename std::iterator_traits<_Iterator>::difference_type + __distance_fw(_Iterator __first, _Iterator __last, + std::forward_iterator_tag) + { return std::distance(__first, __last); } + + template + inline typename std::iterator_traits<_Iterator>::difference_type + __distance_fw(_Iterator __first, _Iterator __last) + { + typedef typename std::iterator_traits<_Iterator>::iterator_category _Tag; + return __distance_fw(__first, __last, _Tag()); + } + + // XXX This is a hack. _Prime_rehash_policy's member functions, and + // certainly the list of primes, should be defined in a .cc file. + // We're temporarily putting them in a header because we don't have a + // place to put TR1 .cc files yet. There's no good reason for any of + // _Prime_rehash_policy's member functions to be inline, and there's + // certainly no good reason for _Primes<> to exist at all. + struct _LessThan + { + template + bool + operator()(_Tp __x, _Up __y) + { return __x < __y; } + }; + + template + struct _Primes + { + static const int __n_primes = __ulongsize != 8 ? 256 : 256 + 48; + static const unsigned long __primes[256 + 48 + 1]; + }; + + template + const int _Primes<__ulongsize>::__n_primes; + + template + const unsigned long _Primes<__ulongsize>::__primes[256 + 48 + 1] = + { + 2ul, 3ul, 5ul, 7ul, 11ul, 13ul, 17ul, 19ul, 23ul, 29ul, 31ul, + 37ul, 41ul, 43ul, 47ul, 53ul, 59ul, 61ul, 67ul, 71ul, 73ul, 79ul, + 83ul, 89ul, 97ul, 103ul, 109ul, 113ul, 127ul, 137ul, 139ul, 149ul, + 157ul, 167ul, 179ul, 193ul, 199ul, 211ul, 227ul, 241ul, 257ul, + 277ul, 293ul, 313ul, 337ul, 359ul, 383ul, 409ul, 439ul, 467ul, + 503ul, 541ul, 577ul, 619ul, 661ul, 709ul, 761ul, 823ul, 887ul, + 953ul, 1031ul, 1109ul, 1193ul, 1289ul, 1381ul, 1493ul, 1613ul, + 1741ul, 1879ul, 2029ul, 2179ul, 2357ul, 2549ul, 2753ul, 2971ul, + 3209ul, 3469ul, 3739ul, 4027ul, 4349ul, 4703ul, 5087ul, 5503ul, + 5953ul, 6427ul, 6949ul, 7517ul, 8123ul, 8783ul, 9497ul, 10273ul, + 11113ul, 12011ul, 12983ul, 14033ul, 15173ul, 16411ul, 17749ul, + 19183ul, 20753ul, 22447ul, 24281ul, 26267ul, 28411ul, 30727ul, + 33223ul, 35933ul, 38873ul, 42043ul, 45481ul, 49201ul, 53201ul, + 57557ul, 62233ul, 67307ul, 72817ul, 78779ul, 85229ul, 92203ul, + 99733ul, 107897ul, 116731ul, 126271ul, 136607ul, 147793ul, + 159871ul, 172933ul, 187091ul, 202409ul, 218971ul, 236897ul, + 256279ul, 277261ul, 299951ul, 324503ul, 351061ul, 379787ul, + 410857ul, 444487ul, 480881ul, 520241ul, 562841ul, 608903ul, + 658753ul, 712697ul, 771049ul, 834181ul, 902483ul, 976369ul, + 1056323ul, 1142821ul, 1236397ul, 1337629ul, 1447153ul, 1565659ul, + 1693859ul, 1832561ul, 1982627ul, 2144977ul, 2320627ul, 2510653ul, + 2716249ul, 2938679ul, 3179303ul, 3439651ul, 3721303ul, 4026031ul, + 4355707ul, 4712381ul, 5098259ul, 5515729ul, 5967347ul, 6456007ul, + 6984629ul, 7556579ul, 8175383ul, 8844859ul, 9569143ul, 10352717ul, + 11200489ul, 12117689ul, 13109983ul, 14183539ul, 15345007ul, + 16601593ul, 17961079ul, 19431899ul, 21023161ul, 22744717ul, + 24607243ul, 26622317ul, 28802401ul, 31160981ul, 33712729ul, + 36473443ul, 39460231ul, 42691603ul, 46187573ul, 49969847ul, + 54061849ul, 58488943ul, 63278561ul, 68460391ul, 74066549ul, + 80131819ul, 86693767ul, 93793069ul, 101473717ul, 109783337ul, + 118773397ul, 128499677ul, 139022417ul, 150406843ul, 162723577ul, + 176048909ul, 190465427ul, 206062531ul, 222936881ul, 241193053ul, + 260944219ul, 282312799ul, 305431229ul, 330442829ul, 357502601ul, + 386778277ul, 418451333ul, 452718089ul, 489790921ul, 529899637ul, + 573292817ul, 620239453ul, 671030513ul, 725980837ul, 785430967ul, + 849749479ul, 919334987ul, 994618837ul, 1076067617ul, 1164186217ul, + 1259520799ul, 1362662261ul, 1474249943ul, 1594975441ul, + 1725587117ul, 1866894511ul, 2019773507ul, 2185171673ul, + 2364114217ul, 2557710269ul, 2767159799ul, 2993761039ul, + 3238918481ul, 3504151727ul, 3791104843ul, 4101556399ul, + 4294967291ul, + // Sentinel, so we don't have to test the result of lower_bound, + // or, on 64-bit machines, rest of the table. + __ulongsize != 8 ? 4294967291ul : (unsigned long)6442450933ull, + (unsigned long)8589934583ull, + (unsigned long)12884901857ull, (unsigned long)17179869143ull, + (unsigned long)25769803693ull, (unsigned long)34359738337ull, + (unsigned long)51539607367ull, (unsigned long)68719476731ull, + (unsigned long)103079215087ull, (unsigned long)137438953447ull, + (unsigned long)206158430123ull, (unsigned long)274877906899ull, + (unsigned long)412316860387ull, (unsigned long)549755813881ull, + (unsigned long)824633720731ull, (unsigned long)1099511627689ull, + (unsigned long)1649267441579ull, (unsigned long)2199023255531ull, + (unsigned long)3298534883309ull, (unsigned long)4398046511093ull, + (unsigned long)6597069766607ull, (unsigned long)8796093022151ull, + (unsigned long)13194139533241ull, (unsigned long)17592186044399ull, + (unsigned long)26388279066581ull, (unsigned long)35184372088777ull, + (unsigned long)52776558133177ull, (unsigned long)70368744177643ull, + (unsigned long)105553116266399ull, (unsigned long)140737488355213ull, + (unsigned long)211106232532861ull, (unsigned long)281474976710597ull, + (unsigned long)562949953421231ull, (unsigned long)1125899906842597ull, + (unsigned long)2251799813685119ull, (unsigned long)4503599627370449ull, + (unsigned long)9007199254740881ull, (unsigned long)18014398509481951ull, + (unsigned long)36028797018963913ull, (unsigned long)72057594037927931ull, + (unsigned long)144115188075855859ull, + (unsigned long)288230376151711717ull, + (unsigned long)576460752303423433ull, + (unsigned long)1152921504606846883ull, + (unsigned long)2305843009213693951ull, + (unsigned long)4611686018427387847ull, + (unsigned long)9223372036854775783ull, + (unsigned long)18446744073709551557ull, + (unsigned long)18446744073709551557ull + }; + + // Auxiliary types used for all instantiations of _Hashtable: nodes + // and iterators. + + // Nodes, used to wrap elements stored in the hash table. A policy + // template parameter of class template _Hashtable controls whether + // nodes also store a hash code. In some cases (e.g. strings) this + // may be a performance win. + template + struct _Hash_node; + + template + struct _Hash_node<_Value, true> + { + _Value _M_v; + std::size_t _M_hash_code; + _Hash_node* _M_next; + }; + + template + struct _Hash_node<_Value, false> + { + _Value _M_v; + _Hash_node* _M_next; + }; + + // Local iterators, used to iterate within a bucket but not between + // buckets. + template + struct _Node_iterator_base + { + _Node_iterator_base(_Hash_node<_Value, __cache>* __p) + : _M_cur(__p) { } + + void + _M_incr() + { _M_cur = _M_cur->_M_next; } + + _Hash_node<_Value, __cache>* _M_cur; + }; + + template + inline bool + operator==(const _Node_iterator_base<_Value, __cache>& __x, + const _Node_iterator_base<_Value, __cache>& __y) + { return __x._M_cur == __y._M_cur; } + + template + inline bool + operator!=(const _Node_iterator_base<_Value, __cache>& __x, + const _Node_iterator_base<_Value, __cache>& __y) + { return __x._M_cur != __y._M_cur; } + + template + struct _Node_iterator + : public _Node_iterator_base<_Value, __cache> + { + typedef _Value value_type; + typedef typename + __gnu_cxx::__conditional_type<__constant_iterators, + const _Value*, _Value*>::__type + pointer; + typedef typename + __gnu_cxx::__conditional_type<__constant_iterators, + const _Value&, _Value&>::__type + reference; + typedef std::ptrdiff_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + _Node_iterator() + : _Node_iterator_base<_Value, __cache>(0) { } + + explicit + _Node_iterator(_Hash_node<_Value, __cache>* __p) + : _Node_iterator_base<_Value, __cache>(__p) { } + + reference + operator*() const + { return this->_M_cur->_M_v; } + + pointer + operator->() const + { return &this->_M_cur->_M_v; } + + _Node_iterator& + operator++() + { + this->_M_incr(); + return *this; + } + + _Node_iterator + operator++(int) + { + _Node_iterator __tmp(*this); + this->_M_incr(); + return __tmp; + } + }; + + template + struct _Node_const_iterator + : public _Node_iterator_base<_Value, __cache> + { + typedef _Value value_type; + typedef const _Value* pointer; + typedef const _Value& reference; + typedef std::ptrdiff_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + _Node_const_iterator() + : _Node_iterator_base<_Value, __cache>(0) { } + + explicit + _Node_const_iterator(_Hash_node<_Value, __cache>* __p) + : _Node_iterator_base<_Value, __cache>(__p) { } + + _Node_const_iterator(const _Node_iterator<_Value, __constant_iterators, + __cache>& __x) + : _Node_iterator_base<_Value, __cache>(__x._M_cur) { } + + reference + operator*() const + { return this->_M_cur->_M_v; } + + pointer + operator->() const + { return &this->_M_cur->_M_v; } + + _Node_const_iterator& + operator++() + { + this->_M_incr(); + return *this; + } + + _Node_const_iterator + operator++(int) + { + _Node_const_iterator __tmp(*this); + this->_M_incr(); + return __tmp; + } + }; + + template + struct _Hashtable_iterator_base + { + _Hashtable_iterator_base(_Hash_node<_Value, __cache>* __node, + _Hash_node<_Value, __cache>** __bucket) + : _M_cur_node(__node), _M_cur_bucket(__bucket) { } + + void + _M_incr() + { + _M_cur_node = _M_cur_node->_M_next; + if (!_M_cur_node) + _M_incr_bucket(); + } + + void + _M_incr_bucket(); + + _Hash_node<_Value, __cache>* _M_cur_node; + _Hash_node<_Value, __cache>** _M_cur_bucket; + }; + + // Global iterators, used for arbitrary iteration within a hash + // table. Larger and more expensive than local iterators. + template + void + _Hashtable_iterator_base<_Value, __cache>:: + _M_incr_bucket() + { + ++_M_cur_bucket; + + // This loop requires the bucket array to have a non-null sentinel. + while (!*_M_cur_bucket) + ++_M_cur_bucket; + _M_cur_node = *_M_cur_bucket; + } + + template + inline bool + operator==(const _Hashtable_iterator_base<_Value, __cache>& __x, + const _Hashtable_iterator_base<_Value, __cache>& __y) + { return __x._M_cur_node == __y._M_cur_node; } + + template + inline bool + operator!=(const _Hashtable_iterator_base<_Value, __cache>& __x, + const _Hashtable_iterator_base<_Value, __cache>& __y) + { return __x._M_cur_node != __y._M_cur_node; } + + template + struct _Hashtable_iterator + : public _Hashtable_iterator_base<_Value, __cache> + { + typedef _Value value_type; + typedef typename + __gnu_cxx::__conditional_type<__constant_iterators, + const _Value*, _Value*>::__type + pointer; + typedef typename + __gnu_cxx::__conditional_type<__constant_iterators, + const _Value&, _Value&>::__type + reference; + typedef std::ptrdiff_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + _Hashtable_iterator() + : _Hashtable_iterator_base<_Value, __cache>(0, 0) { } + + _Hashtable_iterator(_Hash_node<_Value, __cache>* __p, + _Hash_node<_Value, __cache>** __b) + : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { } + + explicit + _Hashtable_iterator(_Hash_node<_Value, __cache>** __b) + : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { } + + reference + operator*() const + { return this->_M_cur_node->_M_v; } + + pointer + operator->() const + { return &this->_M_cur_node->_M_v; } + + _Hashtable_iterator& + operator++() + { + this->_M_incr(); + return *this; + } + + _Hashtable_iterator + operator++(int) + { + _Hashtable_iterator __tmp(*this); + this->_M_incr(); + return __tmp; + } + }; + + template + struct _Hashtable_const_iterator + : public _Hashtable_iterator_base<_Value, __cache> + { + typedef _Value value_type; + typedef const _Value* pointer; + typedef const _Value& reference; + typedef std::ptrdiff_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + _Hashtable_const_iterator() + : _Hashtable_iterator_base<_Value, __cache>(0, 0) { } + + _Hashtable_const_iterator(_Hash_node<_Value, __cache>* __p, + _Hash_node<_Value, __cache>** __b) + : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { } + + explicit + _Hashtable_const_iterator(_Hash_node<_Value, __cache>** __b) + : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { } + + _Hashtable_const_iterator(const _Hashtable_iterator<_Value, + __constant_iterators, __cache>& __x) + : _Hashtable_iterator_base<_Value, __cache>(__x._M_cur_node, + __x._M_cur_bucket) { } + + reference + operator*() const + { return this->_M_cur_node->_M_v; } + + pointer + operator->() const + { return &this->_M_cur_node->_M_v; } + + _Hashtable_const_iterator& + operator++() + { + this->_M_incr(); + return *this; + } + + _Hashtable_const_iterator + operator++(int) + { + _Hashtable_const_iterator __tmp(*this); + this->_M_incr(); + return __tmp; + } + }; + + + // Many of class template _Hashtable's template parameters are policy + // classes. These are defaults for the policies. + + // Default range hashing function: use division to fold a large number + // into the range [0, N). + struct _Mod_range_hashing + { + typedef std::size_t first_argument_type; + typedef std::size_t second_argument_type; + typedef std::size_t result_type; + + result_type + operator()(first_argument_type __num, second_argument_type __den) const + { return __num % __den; } + }; + + // Default ranged hash function H. In principle it should be a + // function object composed from objects of type H1 and H2 such that + // h(k, N) = h2(h1(k), N), but that would mean making extra copies of + // h1 and h2. So instead we'll just use a tag to tell class template + // hashtable to do that composition. + struct _Default_ranged_hash { }; + + // Default value for rehash policy. Bucket size is (usually) the + // smallest prime that keeps the load factor small enough. + struct _Prime_rehash_policy + { + _Prime_rehash_policy(float __z = 1.0); + + float + max_load_factor() const; + + // Return a bucket size no smaller than n. + std::size_t + _M_next_bkt(std::size_t __n) const; + + // Return a bucket count appropriate for n elements + std::size_t + _M_bkt_for_elements(std::size_t __n) const; + + // __n_bkt is current bucket count, __n_elt is current element count, + // and __n_ins is number of elements to be inserted. Do we need to + // increase bucket count? If so, return make_pair(true, n), where n + // is the new bucket count. If not, return make_pair(false, 0). + std::pair + _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt, + std::size_t __n_ins) const; + + float _M_max_load_factor; + float _M_growth_factor; + mutable std::size_t _M_next_resize; + }; + + inline + _Prime_rehash_policy:: + _Prime_rehash_policy(float __z) + : _M_max_load_factor(__z), _M_growth_factor(2.f), _M_next_resize(0) + { } + + inline float + _Prime_rehash_policy:: + max_load_factor() const + { return _M_max_load_factor; } + + // Return a prime no smaller than n. + inline std::size_t + _Prime_rehash_policy:: + _M_next_bkt(std::size_t __n) const + { + const unsigned long* const __last = (_Primes<>::__primes + + _Primes<>::__n_primes); + const unsigned long* __p = std::lower_bound(_Primes<>::__primes, __last, + __n); + _M_next_resize = static_cast(std::ceil(*__p + * _M_max_load_factor)); + return *__p; + } + + // Return the smallest prime p such that alpha p >= n, where alpha + // is the load factor. + inline std::size_t + _Prime_rehash_policy:: + _M_bkt_for_elements(std::size_t __n) const + { + const unsigned long* const __last = (_Primes<>::__primes + + _Primes<>::__n_primes); + const float __min_bkts = __n / _M_max_load_factor; + const unsigned long* __p = std::lower_bound(_Primes<>::__primes, __last, + __min_bkts, _LessThan()); + _M_next_resize = static_cast(std::ceil(*__p + * _M_max_load_factor)); + return *__p; + } + + // Finds the smallest prime p such that alpha p > __n_elt + __n_ins. + // If p > __n_bkt, return make_pair(true, p); otherwise return + // make_pair(false, 0). In principle this isn't very different from + // _M_bkt_for_elements. + + // The only tricky part is that we're caching the element count at + // which we need to rehash, so we don't have to do a floating-point + // multiply for every insertion. + + inline std::pair + _Prime_rehash_policy:: + _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt, + std::size_t __n_ins) const + { + if (__n_elt + __n_ins > _M_next_resize) + { + float __min_bkts = ((float(__n_ins) + float(__n_elt)) + / _M_max_load_factor); + if (__min_bkts > __n_bkt) + { + __min_bkts = std::max(__min_bkts, _M_growth_factor * __n_bkt); + const unsigned long* const __last = (_Primes<>::__primes + + _Primes<>::__n_primes); + const unsigned long* __p = std::lower_bound(_Primes<>::__primes, + __last, __min_bkts, + _LessThan()); + _M_next_resize = + static_cast(std::ceil(*__p * _M_max_load_factor)); + return std::make_pair(true, *__p); + } + else + { + _M_next_resize = + static_cast(std::ceil(__n_bkt + * _M_max_load_factor)); + return std::make_pair(false, 0); + } + } + else + return std::make_pair(false, 0); + } + + // Base classes for std::tr1::_Hashtable. We define these base + // classes because in some cases we want to do different things + // depending on the value of a policy class. In some cases the + // policy class affects which member functions and nested typedefs + // are defined; we handle that by specializing base class templates. + // Several of the base class templates need to access other members + // of class template _Hashtable, so we use the "curiously recurring + // template pattern" for them. + + // class template _Map_base. If the hashtable has a value type of the + // form pair and a key extraction policy that returns the + // first part of the pair, the hashtable gets a mapped_type typedef. + // If it satisfies those criteria and also has unique keys, then it + // also gets an operator[]. + template + struct _Map_base { }; + + template + struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, false, _Hashtable> + { + typedef typename _Pair::second_type mapped_type; + }; + + template + struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable> + { + typedef typename _Pair::second_type mapped_type; + + mapped_type& + operator[](const _Key& __k); + }; + + template + typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, + true, _Hashtable>::mapped_type& + _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: + operator[](const _Key& __k) + { + _Hashtable* __h = static_cast<_Hashtable*>(this); + typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k); + std::size_t __n = __h->_M_bucket_index(__k, __code, + __h->_M_bucket_count); + + typename _Hashtable::_Node* __p = + __h->_M_find_node(__h->_M_buckets[__n], __k, __code); + if (!__p) + return __h->_M_insert_bucket(std::make_pair(__k, mapped_type()), + __n, __code)->second; + return (__p->_M_v).second; + } + + // class template _Rehash_base. Give hashtable the max_load_factor + // functions iff the rehash policy is _Prime_rehash_policy. + template + struct _Rehash_base { }; + + template + struct _Rehash_base<_Prime_rehash_policy, _Hashtable> + { + float + max_load_factor() const + { + const _Hashtable* __this = static_cast(this); + return __this->__rehash_policy().max_load_factor(); + } + + void + max_load_factor(float __z) + { + _Hashtable* __this = static_cast<_Hashtable*>(this); + __this->__rehash_policy(_Prime_rehash_policy(__z)); + } + }; + + // Class template _Hash_code_base. Encapsulates two policy issues that + // aren't quite orthogonal. + // (1) the difference between using a ranged hash function and using + // the combination of a hash function and a range-hashing function. + // In the former case we don't have such things as hash codes, so + // we have a dummy type as placeholder. + // (2) Whether or not we cache hash codes. Caching hash codes is + // meaningless if we have a ranged hash function. + // We also put the key extraction and equality comparison function + // objects here, for convenience. + + // Primary template: unused except as a hook for specializations. + template + struct _Hash_code_base; + + // Specialization: ranged hash function, no caching hash codes. H1 + // and H2 are provided but ignored. We define a dummy hash code type. + template + struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, + _Hash, false> + { + protected: + _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq, + const _H1&, const _H2&, const _Hash& __h) + : _M_extract(__ex), _M_eq(__eq), _M_ranged_hash(__h) { } + + typedef void* _Hash_code_type; + + _Hash_code_type + _M_hash_code(const _Key& __key) const + { return 0; } + + std::size_t + _M_bucket_index(const _Key& __k, _Hash_code_type, + std::size_t __n) const + { return _M_ranged_hash(__k, __n); } + + std::size_t + _M_bucket_index(const _Hash_node<_Value, false>* __p, + std::size_t __n) const + { return _M_ranged_hash(_M_extract(__p->_M_v), __n); } + + bool + _M_compare(const _Key& __k, _Hash_code_type, + _Hash_node<_Value, false>* __n) const + { return _M_eq(__k, _M_extract(__n->_M_v)); } + + void + _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type) const + { } + + void + _M_copy_code(_Hash_node<_Value, false>*, + const _Hash_node<_Value, false>*) const + { } + + void + _M_swap(_Hash_code_base& __x) + { + std::swap(_M_extract, __x._M_extract); + std::swap(_M_eq, __x._M_eq); + std::swap(_M_ranged_hash, __x._M_ranged_hash); + } + + protected: + _ExtractKey _M_extract; + _Equal _M_eq; + _Hash _M_ranged_hash; + }; + + + // No specialization for ranged hash function while caching hash codes. + // That combination is meaningless, and trying to do it is an error. + + + // Specialization: ranged hash function, cache hash codes. This + // combination is meaningless, so we provide only a declaration + // and no definition. + template + struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, + _Hash, true>; + + // Specialization: hash function and range-hashing function, no + // caching of hash codes. H is provided but ignored. Provides + // typedef and accessor required by TR1. + template + struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, + _Default_ranged_hash, false> + { + typedef _H1 hasher; + + hasher + hash_function() const + { return _M_h1; } + + protected: + _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq, + const _H1& __h1, const _H2& __h2, + const _Default_ranged_hash&) + : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { } + + typedef std::size_t _Hash_code_type; + + _Hash_code_type + _M_hash_code(const _Key& __k) const + { return _M_h1(__k); } + + std::size_t + _M_bucket_index(const _Key&, _Hash_code_type __c, + std::size_t __n) const + { return _M_h2(__c, __n); } + + std::size_t + _M_bucket_index(const _Hash_node<_Value, false>* __p, + std::size_t __n) const + { return _M_h2(_M_h1(_M_extract(__p->_M_v)), __n); } + + bool + _M_compare(const _Key& __k, _Hash_code_type, + _Hash_node<_Value, false>* __n) const + { return _M_eq(__k, _M_extract(__n->_M_v)); } + + void + _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type) const + { } + + void + _M_copy_code(_Hash_node<_Value, false>*, + const _Hash_node<_Value, false>*) const + { } + + void + _M_swap(_Hash_code_base& __x) + { + std::swap(_M_extract, __x._M_extract); + std::swap(_M_eq, __x._M_eq); + std::swap(_M_h1, __x._M_h1); + std::swap(_M_h2, __x._M_h2); + } + + protected: + _ExtractKey _M_extract; + _Equal _M_eq; + _H1 _M_h1; + _H2 _M_h2; + }; + + // Specialization: hash function and range-hashing function, + // caching hash codes. H is provided but ignored. Provides + // typedef and accessor required by TR1. + template + struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, + _Default_ranged_hash, true> + { + typedef _H1 hasher; + + hasher + hash_function() const + { return _M_h1; } + + protected: + _Hash_code_base(const _ExtractKey& __ex, const _Equal& __eq, + const _H1& __h1, const _H2& __h2, + const _Default_ranged_hash&) + : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { } + + typedef std::size_t _Hash_code_type; + + _Hash_code_type + _M_hash_code(const _Key& __k) const + { return _M_h1(__k); } + + std::size_t + _M_bucket_index(const _Key&, _Hash_code_type __c, + std::size_t __n) const + { return _M_h2(__c, __n); } + + std::size_t + _M_bucket_index(const _Hash_node<_Value, true>* __p, + std::size_t __n) const + { return _M_h2(__p->_M_hash_code, __n); } + + bool + _M_compare(const _Key& __k, _Hash_code_type __c, + _Hash_node<_Value, true>* __n) const + { return __c == __n->_M_hash_code && _M_eq(__k, _M_extract(__n->_M_v)); } + + void + _M_store_code(_Hash_node<_Value, true>* __n, _Hash_code_type __c) const + { __n->_M_hash_code = __c; } + + void + _M_copy_code(_Hash_node<_Value, true>* __to, + const _Hash_node<_Value, true>* __from) const + { __to->_M_hash_code = __from->_M_hash_code; } + + void + _M_swap(_Hash_code_base& __x) + { + std::swap(_M_extract, __x._M_extract); + std::swap(_M_eq, __x._M_eq); + std::swap(_M_h1, __x._M_h1); + std::swap(_M_h2, __x._M_h2); + } + + protected: + _ExtractKey _M_extract; + _Equal _M_eq; + _H1 _M_h1; + _H2 _M_h2; + }; +} // namespace __detail + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/random b/libstdc++-v3/include/tr1_impl/random new file mode 100644 index 0000000..8d2b9ee --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/random @@ -0,0 +1,2349 @@ +// random number generation -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** + * @file tr1_impl/random + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // [5.1] Random number generation + + /** + * @addtogroup tr1_random Random Number Generation + * A facility for generating random numbers on selected distributions. + * @{ + */ + + /* + * Implementation-space details. + */ + namespace __detail + { + template::digits> + struct _Shift + { static const _UIntType __value = 0; }; + + template + struct _Shift<_UIntType, __w, true> + { static const _UIntType __value = _UIntType(1) << __w; }; + + template + struct _Mod; + + // Dispatch based on modulus value to prevent divide-by-zero compile-time + // errors when m == 0. + template + inline _Tp + __mod(_Tp __x) + { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); } + + typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4), + unsigned, unsigned long>::__type _UInt32Type; + + /* + * An adaptor class for converting the output of any Generator into + * the input for a specific Distribution. + */ + template + struct _Adaptor + { + typedef typename _Engine::result_type _Engine_result_type; + typedef typename _Distribution::input_type result_type; + + public: + _Adaptor(const _Engine& __g) + : _M_g(__g) { } + + result_type + min() const + { + result_type __return_value = 0; + if (is_integral<_Engine_result_type>::value + && is_integral::value) + __return_value = _M_g.min(); + else if (!is_integral::value) + __return_value = result_type(0); + return __return_value; + } + + result_type + max() const + { + result_type __return_value = 0; + if (is_integral<_Engine_result_type>::value + && is_integral::value) + __return_value = _M_g.max(); + else if (!is_integral::value) + __return_value = result_type(1); + return __return_value; + } + + result_type + operator()(); + + private: + _Engine _M_g; + }; + + /* + * Converts a value generated by the adapted random number generator into a + * value in the input domain for the dependent random number distribution. + * + * Because the type traits are compile time constants only the appropriate + * clause of the if statements will actually be emitted by the compiler. + */ + template + typename _Adaptor<_Engine, _Distribution>::result_type + _Adaptor<_Engine, _Distribution>:: + operator()() + { + result_type __return_value = 0; + if (is_integral<_Engine_result_type>::value + && is_integral::value) + __return_value = _M_g(); + else if (is_integral<_Engine_result_type>::value + && !is_integral::value) + __return_value = result_type(_M_g() - _M_g.min()) + / result_type(_M_g.max() - _M_g.min() + result_type(1)); + else if (!is_integral<_Engine_result_type>::value + && !is_integral::value) + __return_value = result_type(_M_g() - _M_g.min()) + / result_type(_M_g.max() - _M_g.min()); + return __return_value; + } + } // namespace __detail + + /** + * Produces random numbers on a given disribution function using a un uniform + * random number generation engine. + * + * @todo the engine_value_type needs to be studied more carefully. + */ + template + class variate_generator + { + // Concept requirements. + __glibcxx_class_requires(_Engine, _CopyConstructibleConcept) + // __glibcxx_class_requires(_Engine, _EngineConcept) + // __glibcxx_class_requires(_Dist, _EngineConcept) + + public: + typedef _Engine engine_type; + typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type; + typedef _Dist distribution_type; + typedef typename _Dist::result_type result_type; + + // tr1:5.1.1 table 5.1 requirement + typedef typename __gnu_cxx::__enable_if< + is_arithmetic::value, result_type>::__type _IsValidType; + + /** + * Constructs a variate generator with the uniform random number + * generator @p __eng for the random distribution @p __dist. + * + * @throws Any exceptions which may thrown by the copy constructors of + * the @p _Engine or @p _Dist objects. + */ + variate_generator(engine_type __eng, distribution_type __dist) + : _M_engine(__eng), _M_dist(__dist) { } + + /** + * Gets the next generated value on the distribution. + */ + result_type + operator()() + { return _M_dist(_M_engine); } + + /** + * WTF? + */ + template + result_type + operator()(_Tp __value) + { return _M_dist(_M_engine, __value); } + + /** + * Gets a reference to the underlying uniform random number generator + * object. + */ + engine_value_type& + engine() + { return _M_engine; } + + /** + * Gets a const reference to the underlying uniform random number + * generator object. + */ + const engine_value_type& + engine() const + { return _M_engine; } + + /** + * Gets a reference to the underlying random distribution. + */ + distribution_type& + distribution() + { return _M_dist; } + + /** + * Gets a const reference to the underlying random distribution. + */ + const distribution_type& + distribution() const + { return _M_dist; } + + /** + * Gets the closed lower bound of the distribution interval. + */ + result_type + min() const + { return this->distribution().min(); } + + /** + * Gets the closed upper bound of the distribution interval. + */ + result_type + max() const + { return this->distribution().max(); } + + private: + engine_value_type _M_engine; + distribution_type _M_dist; + }; + + + /** + * @addtogroup tr1_random_generators Random Number Generators + * @ingroup tr1_random + * + * These classes define objects which provide random or pseudorandom + * numbers, either from a discrete or a continuous interval. The + * random number generator supplied as a part of this library are + * all uniform random number generators which provide a sequence of + * random number uniformly distributed over their range. + * + * A number generator is a function object with an operator() that + * takes zero arguments and returns a number. + * + * A compliant random number generator must satisy the following + * requirements. + * + *
Random Number Generator Requirements
To be documented.
+ * + * @{ + */ + + /** + * @brief A model of a linear congruential random number generator. + * + * A random number generator that produces pseudorandom numbers using the + * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$. + * + * The template parameter @p _UIntType must be an unsigned integral type + * large enough to store values up to (__m-1). If the template parameter + * @p __m is 0, the modulus @p __m used is + * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template + * parameters @p __a and @p __c must be less than @p __m. + * + * The size of the state is @f$ 1 @f$. + */ + template + class linear_congruential + { + __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) + // __glibcpp_class_requires(__a < __m && __c < __m) + + public: + /** The type of the generated random value. */ + typedef _UIntType result_type; + + /** The multiplier. */ + static const _UIntType multiplier = __a; + /** An increment. */ + static const _UIntType increment = __c; + /** The modulus. */ + static const _UIntType modulus = __m; + + /** + * Constructs a %linear_congruential random number generator engine with + * seed @p __s. The default seed value is 1. + * + * @param __s The initial seed value. + */ + explicit + linear_congruential(unsigned long __x0 = 1) + { this->seed(__x0); } + + /** + * Constructs a %linear_congruential random number generator engine + * seeded from the generator function @p __g. + * + * @param __g The seed generator function. + */ + template + linear_congruential(_Gen& __g) + { this->seed(__g); } + + /** + * Reseeds the %linear_congruential random number generator engine + * sequence to the seed @g __s. + * + * @param __s The new seed. + */ + void + seed(unsigned long __s = 1); + + /** + * Reseeds the %linear_congruential random number generator engine + * sequence using values from the generator function @p __g. + * + * @param __g the seed generator function. + */ + template + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + /** + * Gets the smallest possible value in the output range. + * + * The minumum depends on the @p __c parameter: if it is zero, the + * minimum generated must be > 0, otherwise 0 is allowed. + */ + result_type + min() const + { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; } + + /** + * Gets the largest possible value in the output range. + */ + result_type + max() const + { return __m - 1; } + + /** + * Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * Compares two linear congruential random number generator + * objects of the same type for equality. + * + * @param __lhs A linear congruential random number generator object. + * @param __rhs Another linear congruential random number generator obj. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const linear_congruential& __lhs, + const linear_congruential& __rhs) + { return __lhs._M_x == __rhs._M_x; } + + /** + * Compares two linear congruential random number generator + * objects of the same type for inequality. + * + * @param __lhs A linear congruential random number generator object. + * @param __rhs Another linear congruential random number generator obj. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const linear_congruential& __lhs, + const linear_congruential& __rhs) + { return !(__lhs == __rhs); } + + /** + * Writes the textual representation of the state x(i) of x to @p __os. + * + * @param __os The output stream. + * @param __lcr A % linear_congruential random number generator. + * @returns __os. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const linear_congruential<_UIntType1, __a1, __c1, + __m1>& __lcr); + + /** + * Sets the state of the engine by reading its textual + * representation from @p __is. + * + * The textual representation must have been previously written using an + * output stream whose imbued locale and whose type's template + * specialization arguments _CharT and _Traits were the same as those of + * @p __is. + * + * @param __is The input stream. + * @param __lcr A % linear_congruential random number generator. + * @returns __is. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr); + + private: + template + void + seed(_Gen& __g, true_type) + { return seed(static_cast(__g)); } + + template + void + seed(_Gen& __g, false_type); + + _UIntType _M_x; + }; + + /** + * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller. + */ + typedef linear_congruential minstd_rand0; + + /** + * An alternative LCR (Lehmer Generator function) . + */ + typedef linear_congruential minstd_rand; + + + /** + * A generalized feedback shift register discrete random number generator. + * + * This algorithm avoind multiplication and division and is designed to be + * friendly to a pipelined architecture. If the parameters are chosen + * correctly, this generator will produce numbers with a very long period and + * fairly good apparent entropy, although still not cryptographically strong. + * + * The best way to use this generator is with the predefined mt19937 class. + * + * This algorithm was originally invented by Makoto Matsumoto and + * Takuji Nishimura. + * + * @var word_size The number of bits in each element of the state vector. + * @var state_size The degree of recursion. + * @var shift_size The period parameter. + * @var mask_bits The separation point bit index. + * @var parameter_a The last row of the twist matrix. + * @var output_u The first right-shift tempering matrix parameter. + * @var output_s The first left-shift tempering matrix parameter. + * @var output_b The first left-shift tempering matrix mask. + * @var output_t The second left-shift tempering matrix parameter. + * @var output_c The second left-shift tempering matrix mask. + * @var output_l The second right-shift tempering matrix parameter. + */ + template + class mersenne_twister + { + __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) + + public: + // types + typedef _UIntType result_type; + + // parameter values + static const int word_size = __w; + static const int state_size = __n; + static const int shift_size = __m; + static const int mask_bits = __r; + static const _UIntType parameter_a = __a; + static const int output_u = __u; + static const int output_s = __s; + static const _UIntType output_b = __b; + static const int output_t = __t; + static const _UIntType output_c = __c; + static const int output_l = __l; + + // constructors and member function + mersenne_twister() + { seed(); } + + explicit + mersenne_twister(unsigned long __value) + { seed(__value); } + + template + mersenne_twister(_Gen& __g) + { seed(__g); } + + void + seed() + { seed(5489UL); } + + void + seed(unsigned long __value); + + template + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + result_type + min() const + { return 0; }; + + result_type + max() const + { return __detail::_Shift<_UIntType, __w>::__value - 1; } + + result_type + operator()(); + + /** + * Compares two % mersenne_twister random number generator objects of + * the same type for equality. + * + * @param __lhs A % mersenne_twister random number generator object. + * @param __rhs Another % mersenne_twister random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const mersenne_twister& __lhs, + const mersenne_twister& __rhs) + { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); } + + /** + * Compares two % mersenne_twister random number generator objects of + * the same type for inequality. + * + * @param __lhs A % mersenne_twister random number generator object. + * @param __rhs Another % mersenne_twister random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const mersenne_twister& __lhs, + const mersenne_twister& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a % mersenne_twister random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A % mersenne_twister random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); + + /** + * Extracts the current state of a % mersenne_twister random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A % mersenne_twister random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); + + private: + template + void + seed(_Gen& __g, true_type) + { return seed(static_cast(__g)); } + + template + void + seed(_Gen& __g, false_type); + + _UIntType _M_x[state_size]; + int _M_p; + }; + + /** + * The classic Mersenne Twister. + * + * Reference: + * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally + * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions + * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. + */ + typedef mersenne_twister< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18 + > mt19937; + + + /** + * @brief The Marsaglia-Zaman generator. + * + * This is a model of a Generalized Fibonacci discrete random number + * generator, sometimes referred to as the SWC generator. + * + * A discrete random number generator that produces pseudorandom + * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} - + * carry_{i-1}) \bmod m @f$. + * + * The size of the state is @f$ r @f$ + * and the maximum period of the generator is @f$ m^r - m^s -1 @f$. + * + * N1688[4.13] says "the template parameter _IntType shall denote an integral + * type large enough to store values up to m." + * + * @if maint + * @var _M_x The state of the generator. This is a ring buffer. + * @var _M_carry The carry. + * @var _M_p Current index of x(i - r). + * @endif + */ + template + class subtract_with_carry + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the generated random value. */ + typedef _IntType result_type; + + // parameter values + static const _IntType modulus = __m; + static const int long_lag = __r; + static const int short_lag = __s; + + /** + * Constructs a default-initialized % subtract_with_carry random number + * generator. + */ + subtract_with_carry() + { this->seed(); } + + /** + * Constructs an explicitly seeded % subtract_with_carry random number + * generator. + */ + explicit + subtract_with_carry(unsigned long __value) + { this->seed(__value); } + + /** + * Constructs a %subtract_with_carry random number generator engine + * seeded from the generator function @p __g. + * + * @param __g The seed generator function. + */ + template + subtract_with_carry(_Gen& __g) + { this->seed(__g); } + + /** + * Seeds the initial state @f$ x_0 @f$ of the random number generator. + * + * N1688[4.19] modifies this as follows. If @p __value == 0, + * sets value to 19780503. In any case, with a linear + * congruential generator lcg(i) having parameters @f$ m_{lcg} = + * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value + * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m + * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$ + * set carry to 1, otherwise sets carry to 0. + */ + void + seed(unsigned long __value = 19780503); + + /** + * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry + * random number generator. + */ + template + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + /** + * Gets the inclusive minimum value of the range of random integers + * returned by this generator. + */ + result_type + min() const + { return 0; } + + /** + * Gets the inclusive maximum value of the range of random integers + * returned by this generator. + */ + result_type + max() const + { return this->modulus - 1; } + + /** + * Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * Compares two % subtract_with_carry random number generator objects of + * the same type for equality. + * + * @param __lhs A % subtract_with_carry random number generator object. + * @param __rhs Another % subtract_with_carry random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const subtract_with_carry& __lhs, + const subtract_with_carry& __rhs) + { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); } + + /** + * Compares two % subtract_with_carry random number generator objects of + * the same type for inequality. + * + * @param __lhs A % subtract_with_carry random number generator object. + * @param __rhs Another % subtract_with_carry random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const subtract_with_carry& __lhs, + const subtract_with_carry& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a % subtract_with_carry random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A % subtract_with_carry random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry<_IntType1, __m1, __s1, + __r1>& __x); + + /** + * Extracts the current state of a % subtract_with_carry random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A % subtract_with_carry random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x); + + private: + template + void + seed(_Gen& __g, true_type) + { return seed(static_cast(__g)); } + + template + void + seed(_Gen& __g, false_type); + + typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType; + + _UIntType _M_x[long_lag]; + _UIntType _M_carry; + int _M_p; + }; + + + /** + * @brief The Marsaglia-Zaman generator (floats version). + * + * @if maint + * @var _M_x The state of the generator. This is a ring buffer. + * @var _M_carry The carry. + * @var _M_p Current index of x(i - r). + * @var _M_npows Precomputed negative powers of 2. + * @endif + */ + template + class subtract_with_carry_01 + { + public: + /** The type of the generated random value. */ + typedef _RealType result_type; + + // parameter values + static const int word_size = __w; + static const int long_lag = __r; + static const int short_lag = __s; + + /** + * Constructs a default-initialized % subtract_with_carry_01 random + * number generator. + */ + subtract_with_carry_01() + { + this->seed(); + _M_initialize_npows(); + } + + /** + * Constructs an explicitly seeded % subtract_with_carry_01 random number + * generator. + */ + explicit + subtract_with_carry_01(unsigned long __value) + { + this->seed(__value); + _M_initialize_npows(); + } + + /** + * Constructs a % subtract_with_carry_01 random number generator engine + * seeded from the generator function @p __g. + * + * @param __g The seed generator function. + */ + template + subtract_with_carry_01(_Gen& __g) + { + this->seed(__g); + _M_initialize_npows(); + } + + /** + * Seeds the initial state @f$ x_0 @f$ of the random number generator. + */ + void + seed(unsigned long __value = 19780503); + + /** + * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry_01 + * random number generator. + */ + template + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + /** + * Gets the minimum value of the range of random floats + * returned by this generator. + */ + result_type + min() const + { return 0.0; } + + /** + * Gets the maximum value of the range of random floats + * returned by this generator. + */ + result_type + max() const + { return 1.0; } + + /** + * Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * Compares two % subtract_with_carry_01 random number generator objects + * of the same type for equality. + * + * @param __lhs A % subtract_with_carry_01 random number + * generator object. + * @param __rhs Another % subtract_with_carry_01 random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const subtract_with_carry_01& __lhs, + const subtract_with_carry_01& __rhs) + { + for (int __i = 0; __i < long_lag; ++__i) + if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n, + __rhs._M_x[__i])) + return false; + return true; + } + + /** + * Compares two % subtract_with_carry_01 random number generator objects + * of the same type for inequality. + * + * @param __lhs A % subtract_with_carry_01 random number + * generator object. + * + * @param __rhs Another % subtract_with_carry_01 random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const subtract_with_carry_01& __lhs, + const subtract_with_carry_01& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a % subtract_with_carry_01 random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A % subtract_with_carry_01 random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_01<_RealType1, __w1, __s1, + __r1>& __x); + + /** + * Extracts the current state of a % subtract_with_carry_01 random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A % subtract_with_carry_01 random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x); + + private: + template + void + seed(_Gen& __g, true_type) + { return seed(static_cast(__g)); } + + template + void + seed(_Gen& __g, false_type); + + void + _M_initialize_npows(); + + static const int __n = (__w + 31) / 32; + + typedef __detail::_UInt32Type _UInt32Type; + _UInt32Type _M_x[long_lag][__n]; + _RealType _M_npows[__n]; + _UInt32Type _M_carry; + int _M_p; + }; + + typedef subtract_with_carry_01 ranlux_base_01; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 508. Bad parameters for ranlux64_base_01. + typedef subtract_with_carry_01 ranlux64_base_01; + + + /** + * Produces random numbers from some base engine by discarding blocks of + * data. + * + * 0 <= @p __r <= @p __p + */ + template + class discard_block + { + // __glibcxx_class_requires(typename base_type::result_type, + // ArithmeticTypeConcept) + + public: + /** The type of the underlying generator engine. */ + typedef _UniformRandomNumberGenerator base_type; + /** The type of the generated random value. */ + typedef typename base_type::result_type result_type; + + // parameter values + static const int block_size = __p; + static const int used_block = __r; + + /** + * Constructs a default %discard_block engine. + * + * The underlying engine is default constructed as well. + */ + discard_block() + : _M_n(0) { } + + /** + * Copy constructs a %discard_block engine. + * + * Copies an existing base class random number geenerator. + * @param rng An existing (base class) engine object. + */ + explicit + discard_block(const base_type& __rng) + : _M_b(__rng), _M_n(0) { } + + /** + * Seed constructs a %discard_block engine. + * + * Constructs the underlying generator engine seeded with @p __s. + * @param __s A seed value for the base class engine. + */ + explicit + discard_block(unsigned long __s) + : _M_b(__s), _M_n(0) { } + + /** + * Generator construct a %discard_block engine. + * + * @param __g A seed generator function. + */ + template + discard_block(_Gen& __g) + : _M_b(__g), _M_n(0) { } + + /** + * Reseeds the %discard_block object with the default seed for the + * underlying base class generator engine. + */ + void seed() + { + _M_b.seed(); + _M_n = 0; + } + + /** + * Reseeds the %discard_block object with the given seed generator + * function. + * @param __g A seed generator function. + */ + template + void seed(_Gen& __g) + { + _M_b.seed(__g); + _M_n = 0; + } + + /** + * Gets a const reference to the underlying generator engine object. + */ + const base_type& + base() const + { return _M_b; } + + /** + * Gets the minimum value in the generated random number range. + */ + result_type + min() const + { return _M_b.min(); } + + /** + * Gets the maximum value in the generated random number range. + */ + result_type + max() const + { return _M_b.max(); } + + /** + * Gets the next value in the generated random number sequence. + */ + result_type + operator()(); + + /** + * Compares two %discard_block random number generator objects of + * the same type for equality. + * + * @param __lhs A %discard_block random number generator object. + * @param __rhs Another %discard_block random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const discard_block& __lhs, const discard_block& __rhs) + { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); } + + /** + * Compares two %discard_block random number generator objects of + * the same type for inequality. + * + * @param __lhs A %discard_block random number generator object. + * @param __rhs Another %discard_block random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const discard_block& __lhs, const discard_block& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a %discard_block random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %discard_block random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); + + /** + * Extracts the current state of a % subtract_with_carry random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %discard_block random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); + + private: + base_type _M_b; + int _M_n; + }; + + + /** + * James's luxury-level-3 integer adaptation of Luescher's generator. + */ + typedef discard_block< + subtract_with_carry, + 223, + 24 + > ranlux3; + + /** + * James's luxury-level-4 integer adaptation of Luescher's generator. + */ + typedef discard_block< + subtract_with_carry, + 389, + 24 + > ranlux4; + + typedef discard_block< + subtract_with_carry_01, + 223, + 24 + > ranlux3_01; + + typedef discard_block< + subtract_with_carry_01, + 389, + 24 + > ranlux4_01; + + + /** + * A random number generator adaptor class that combines two random number + * generator engines into a single output sequence. + */ + template + class xor_combine + { + // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1:: + // result_type, ArithmeticTypeConcept) + // __glibcxx_class_requires(typename _UniformRandomNumberGenerator2:: + // result_type, ArithmeticTypeConcept) + + public: + /** The type of the the first underlying generator engine. */ + typedef _UniformRandomNumberGenerator1 base1_type; + /** The type of the the second underlying generator engine. */ + typedef _UniformRandomNumberGenerator2 base2_type; + + private: + typedef typename base1_type::result_type _Result_type1; + typedef typename base2_type::result_type _Result_type2; + + public: + /** The type of the generated random value. */ + typedef typename __gnu_cxx::__conditional_type<(sizeof(_Result_type1) + > sizeof(_Result_type2)), + _Result_type1, _Result_type2>::__type result_type; + + // parameter values + static const int shift1 = __s1; + static const int shift2 = __s2; + + // constructors and member function + xor_combine() + : _M_b1(), _M_b2() + { _M_initialize_max(); } + + xor_combine(const base1_type& __rng1, const base2_type& __rng2) + : _M_b1(__rng1), _M_b2(__rng2) + { _M_initialize_max(); } + + xor_combine(unsigned long __s) + : _M_b1(__s), _M_b2(__s + 1) + { _M_initialize_max(); } + + template + xor_combine(_Gen& __g) + : _M_b1(__g), _M_b2(__g) + { _M_initialize_max(); } + + void + seed() + { + _M_b1.seed(); + _M_b2.seed(); + } + + template + void + seed(_Gen& __g) + { + _M_b1.seed(__g); + _M_b2.seed(__g); + } + + const base1_type& + base1() const + { return _M_b1; } + + const base2_type& + base2() const + { return _M_b2; } + + result_type + min() const + { return 0; } + + result_type + max() const + { return _M_max; } + + /** + * Gets the next random number in the sequence. + */ + // NB: Not exactly the TR1 formula, per N2079 instead. + result_type + operator()() + { + return ((result_type(_M_b1() - _M_b1.min()) << shift1) + ^ (result_type(_M_b2() - _M_b2.min()) << shift2)); + } + + /** + * Compares two %xor_combine random number generator objects of + * the same type for equality. + * + * @param __lhs A %xor_combine random number generator object. + * @param __rhs Another %xor_combine random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const xor_combine& __lhs, const xor_combine& __rhs) + { + return (__lhs.base1() == __rhs.base1()) + && (__lhs.base2() == __rhs.base2()); + } + + /** + * Compares two %xor_combine random number generator objects of + * the same type for inequality. + * + * @param __lhs A %xor_combine random number generator object. + * @param __rhs Another %xor_combine random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const xor_combine& __lhs, const xor_combine& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a %xor_combine random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %xor_combine random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const xor_combine<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); + + /** + * Extracts the current state of a %xor_combine random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %xor_combine random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + xor_combine<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); + + private: + void + _M_initialize_max(); + + result_type + _M_initialize_max_aux(result_type, result_type, int); + + base1_type _M_b1; + base2_type _M_b2; + result_type _M_max; + }; + + + /** + * A standard interface to a platform-specific non-deterministic + * random number generator (if any are available). + */ + class random_device + { + public: + // types + typedef unsigned int result_type; + + // constructors, destructors and member functions + +#ifdef _GLIBCXX_USE_RANDOM_TR1 + + explicit + random_device(const std::string& __token = "/dev/urandom") + { + if ((__token != "/dev/urandom" && __token != "/dev/random") + || !(_M_file = std::fopen(__token.c_str(), "rb"))) + std::__throw_runtime_error(__N("random_device::" + "random_device(const std::string&)")); + } + + ~random_device() + { std::fclose(_M_file); } + +#else + + explicit + random_device(const std::string& __token = "mt19937") + : _M_mt(_M_strtoul(__token)) { } + + private: + static unsigned long + _M_strtoul(const std::string& __str) + { + unsigned long __ret = 5489UL; + if (__str != "mt19937") + { + const char* __nptr = __str.c_str(); + char* __endptr; + __ret = std::strtoul(__nptr, &__endptr, 0); + if (*__nptr == '\0' || *__endptr != '\0') + std::__throw_runtime_error(__N("random_device::_M_strtoul" + "(const std::string&)")); + } + return __ret; + } + + public: + +#endif + + result_type + min() const + { return std::numeric_limits::min(); } + + result_type + max() const + { return std::numeric_limits::max(); } + + double + entropy() const + { return 0.0; } + + result_type + operator()() + { +#ifdef _GLIBCXX_USE_RANDOM_TR1 + result_type __ret; + std::fread(reinterpret_cast(&__ret), sizeof(result_type), + 1, _M_file); + return __ret; +#else + return _M_mt(); +#endif + } + + private: + random_device(const random_device&); + void operator=(const random_device&); + +#ifdef _GLIBCXX_USE_RANDOM_TR1 + FILE* _M_file; +#else + mt19937 _M_mt; +#endif + }; + + /* @} */ // group tr1_random_generators + + /** + * @addtogroup tr1_random_distributions Random Number Distributions + * @ingroup tr1_random + * @{ + */ + + /** + * @addtogroup tr1_random_distributions_discrete Discrete Distributions + * @ingroup tr1_random_distributions + * @{ + */ + + /** + * @brief Uniform discrete distribution for random numbers. + * A discrete random distribution on the range @f$[min, max]@f$ with equal + * probability throughout the range. + */ + template + class uniform_int + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the parameters of the distribution. */ + typedef _IntType input_type; + /** The type of the range of the distribution. */ + typedef _IntType result_type; + + public: + /** + * Constructs a uniform distribution object. + */ + explicit + uniform_int(_IntType __min = 0, _IntType __max = 9) + : _M_min(__min), _M_max(__max) + { + _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); + } + + /** + * Gets the inclusive lower bound of the distribution range. + */ + result_type + min() const + { return _M_min; } + + /** + * Gets the inclusive upper bound of the distribution range. + */ + result_type + max() const + { return _M_max; } + + /** + * Resets the distribution state. + * + * Does nothing for the uniform integer distribution. + */ + void + reset() { } + + /** + * Gets a uniformly distributed random number in the range + * @f$(min, max)@f$. + */ + template + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + typedef typename _UniformRandomNumberGenerator::result_type + _UResult_type; + return _M_call(__urng, _M_min, _M_max, + typename is_integral<_UResult_type>::type()); + } + + /** + * Gets a uniform random number in the range @f$[0, n)@f$. + * + * This function is aimed at use with std::random_shuffle. + */ + template + result_type + operator()(_UniformRandomNumberGenerator& __urng, result_type __n) + { + typedef typename _UniformRandomNumberGenerator::result_type + _UResult_type; + return _M_call(__urng, 0, __n - 1, + typename is_integral<_UResult_type>::type()); + } + + /** + * Inserts a %uniform_int random number distribution @p __x into the + * output stream @p os. + * + * @param __os An output stream. + * @param __x A %uniform_int random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType1>& __x); + + /** + * Extracts a %unform_int random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %uniform_int random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType1>& __x); + + private: + template + result_type + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, true_type) + { return result_type(__urng() % (__max - __min + 1)) + __min; } + + template + result_type + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, false_type) + { + return result_type((__urng() - __urng.min()) + / (__urng.max() - __urng.min()) + * (__max - __min + 1)) + __min; + } + + _IntType _M_min; + _IntType _M_max; + }; + + + /** + * @brief A Bernoulli random number distribution. + * + * Generates a sequence of true and false values with likelihood @f$ p @f$ + * that true will come up and @f$ (1 - p) @f$ that false will appear. + */ + class bernoulli_distribution + { + public: + typedef int input_type; + typedef bool result_type; + + public: + /** + * Constructs a Bernoulli distribution with likelihood @p p. + * + * @param __p [IN] The likelihood of a true result being returned. Must + * be in the interval @f$ [0, 1] @f$. + */ + explicit + bernoulli_distribution(double __p = 0.5) + : _M_p(__p) + { + _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0)); + } + + /** + * Gets the @p p parameter of the distribution. + */ + double + p() const + { return _M_p; } + + /** + * Resets the distribution state. + * + * Does nothing for a bernoulli distribution. + */ + void + reset() { } + + /** + * Gets the next value in the Bernoullian sequence. + */ + template + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min())) + return true; + return false; + } + + /** + * Inserts a %bernoulli_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %bernoulli_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x); + + /** + * Extracts a %bernoulli_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %bernoulli_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + bernoulli_distribution& __x) + { return __is >> __x._M_p; } + + private: + double _M_p; + }; + + + /** + * @brief A discrete geometric random number distribution. + * + * The formula for the geometric probability mass function is + * @f$ p(i) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the + * distribution. + */ + template + class geometric_distribution + { + public: + // types + typedef _RealType input_type; + typedef _IntType result_type; + + // constructors and member function + explicit + geometric_distribution(const _RealType& __p = _RealType(0.5)) + : _M_p(__p) + { + _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0)); + _M_initialize(); + } + + /** + * Gets the distribution parameter @p p. + */ + _RealType + p() const + { return _M_p; } + + void + reset() { } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %geometric_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %geometric_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType1, _RealType1>& __x); + + /** + * Extracts a %geometric_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %geometric_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + geometric_distribution& __x) + { + __is >> __x._M_p; + __x._M_initialize(); + return __is; + } + + private: + void + _M_initialize() + { _M_log_p = std::log(_M_p); } + + _RealType _M_p; + _RealType _M_log_p; + }; + + + template + class normal_distribution; + + /** + * @brief A discrete Poisson random number distribution. + * + * The formula for the poisson probability mass function is + * @f$ p(i) = \frac{mean^i}{i!} e^{-mean} @f$ where @f$ mean @f$ is the + * parameter of the distribution. + */ + template + class poisson_distribution + { + public: + // types + typedef _RealType input_type; + typedef _IntType result_type; + + // constructors and member function + explicit + poisson_distribution(const _RealType& __mean = _RealType(1)) + : _M_mean(__mean), _M_nd() + { + _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0); + _M_initialize(); + } + + /** + * Gets the distribution parameter @p mean. + */ + _RealType + mean() const + { return _M_mean; } + + void + reset() + { _M_nd.reset(); } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %poisson_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %poisson_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType1, _RealType1>& __x); + + /** + * Extracts a %poisson_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %poisson_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType1, _RealType1>& __x); + + private: + void + _M_initialize(); + + // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. + normal_distribution<_RealType> _M_nd; + + _RealType _M_mean; + + // Hosts either log(mean) or the threshold of the simple method. + _RealType _M_lm_thr; +#if _GLIBCXX_USE_C99_MATH_TR1 + _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb; +#endif + }; + + + /** + * @brief A discrete binomial random number distribution. + * + * The formula for the binomial probability mass function is + * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$ + * and @f$ p @f$ are the parameters of the distribution. + */ + template + class binomial_distribution + { + public: + // types + typedef _RealType input_type; + typedef _IntType result_type; + + // constructors and member function + explicit + binomial_distribution(_IntType __t = 1, + const _RealType& __p = _RealType(0.5)) + : _M_t(__t), _M_p(__p), _M_nd() + { + _GLIBCXX_DEBUG_ASSERT((_M_t >= 0) && (_M_p >= 0.0) && (_M_p <= 1.0)); + _M_initialize(); + } + + /** + * Gets the distribution @p t parameter. + */ + _IntType + t() const + { return _M_t; } + + /** + * Gets the distribution @p p parameter. + */ + _RealType + p() const + { return _M_p; } + + void + reset() + { _M_nd.reset(); } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %binomial_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %binomial_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType1, _RealType1>& __x); + + /** + * Extracts a %binomial_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %binomial_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType1, _RealType1>& __x); + + private: + void + _M_initialize(); + + template + result_type + _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t); + + // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. + normal_distribution<_RealType> _M_nd; + + _RealType _M_q; +#if _GLIBCXX_USE_C99_MATH_TR1 + _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c, + _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p; +#endif + _RealType _M_p; + _IntType _M_t; + + bool _M_easy; + }; + + /* @} */ // group tr1_random_distributions_discrete + + /** + * @addtogroup tr1_random_distributions_continuous Continuous Distributions + * @ingroup tr1_random_distributions + * @{ + */ + + /** + * @brief Uniform continuous distribution for random numbers. + * + * A continuous random distribution on the range [min, max) with equal + * probability throughout the range. The URNG should be real-valued and + * deliver number in the range [0, 1). + */ + template + class uniform_real + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs a uniform_real object. + * + * @param __min [IN] The lower bound of the distribution. + * @param __max [IN] The upper bound of the distribution. + */ + explicit + uniform_real(_RealType __min = _RealType(0), + _RealType __max = _RealType(1)) + : _M_min(__min), _M_max(__max) + { + _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); + } + + result_type + min() const + { return _M_min; } + + result_type + max() const + { return _M_max; } + + void + reset() { } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return (__urng() * (_M_max - _M_min)) + _M_min; } + + /** + * Inserts a %uniform_real random number distribution @p __x into the + * output stream @p __os. + * + * @param __os An output stream. + * @param __x A %uniform_real random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real<_RealType1>& __x); + + /** + * Extracts a %unform_real random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %uniform_real random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real<_RealType1>& __x); + + private: + _RealType _M_min; + _RealType _M_max; + }; + + + /** + * @brief An exponential continuous distribution for random numbers. + * + * The formula for the exponential probability mass function is + * @f$ p(x) = \lambda e^{-\lambda x} @f$. + * + * + * + * + * + * + * + * + *
Distribution Statistics
Mean@f$ \frac{1}{\lambda} @f$
Median@f$ \frac{\ln 2}{\lambda} @f$
Mode@f$ zero @f$
Range@f$[0, \infty]@f$
Standard Deviation@f$ \frac{1}{\lambda} @f$
+ */ + template + class exponential_distribution + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs an exponential distribution with inverse scale parameter + * @f$ \lambda @f$. + */ + explicit + exponential_distribution(const result_type& __lambda = result_type(1)) + : _M_lambda(__lambda) + { + _GLIBCXX_DEBUG_ASSERT(_M_lambda > 0); + } + + /** + * Gets the inverse scale parameter of the distribution. + */ + _RealType + lambda() const + { return _M_lambda; } + + /** + * Resets the distribution. + * + * Has no effect on exponential distributions. + */ + void + reset() { } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return -std::log(__urng()) / _M_lambda; } + + /** + * Inserts a %exponential_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %exponential_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType1>& __x); + + /** + * Extracts a %exponential_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %exponential_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + exponential_distribution& __x) + { return __is >> __x._M_lambda; } + + private: + result_type _M_lambda; + }; + + + /** + * @brief A normal continuous distribution for random numbers. + * + * The formula for the normal probability mass function is + * @f$ p(x) = \frac{1}{\sigma \sqrt{2 \pi}} + * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$. + */ + template + class normal_distribution + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs a normal distribution with parameters @f$ mean @f$ and + * @f$ \sigma @f$. + */ + explicit + normal_distribution(const result_type& __mean = result_type(0), + const result_type& __sigma = result_type(1)) + : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(false) + { + _GLIBCXX_DEBUG_ASSERT(_M_sigma > 0); + } + + /** + * Gets the mean of the distribution. + */ + _RealType + mean() const + { return _M_mean; } + + /** + * Gets the @f$ \sigma @f$ of the distribution. + */ + _RealType + sigma() const + { return _M_sigma; } + + /** + * Resets the distribution. + */ + void + reset() + { _M_saved_available = false; } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %normal_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %normal_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType1>& __x); + + /** + * Extracts a %normal_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %normal_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType1>& __x); + + private: + result_type _M_mean; + result_type _M_sigma; + result_type _M_saved; + bool _M_saved_available; + }; + + + /** + * @brief A gamma continuous distribution for random numbers. + * + * The formula for the gamma probability mass function is + * @f$ p(x) = \frac{1}{\Gamma(\alpha)} x^{\alpha - 1} e^{-x} @f$. + */ + template + class gamma_distribution + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs a gamma distribution with parameters @f$ \alpha @f$. + */ + explicit + gamma_distribution(const result_type& __alpha_val = result_type(1)) + : _M_alpha(__alpha_val) + { + _GLIBCXX_DEBUG_ASSERT(_M_alpha > 0); + _M_initialize(); + } + + /** + * Gets the @f$ \alpha @f$ of the distribution. + */ + _RealType + alpha() const + { return _M_alpha; } + + /** + * Resets the distribution. + */ + void + reset() { } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %gamma_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %gamma_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RealType1>& __x); + + /** + * Extracts a %gamma_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %gamma_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + gamma_distribution& __x) + { + __is >> __x._M_alpha; + __x._M_initialize(); + return __is; + } + + private: + void + _M_initialize(); + + result_type _M_alpha; + + // Hosts either lambda of GB or d of modified Vaduva's. + result_type _M_l_d; + }; + + /* @} */ // group tr1_random_distributions_continuous + /* @} */ // group tr1_random_distributions + /* @} */ // group tr1_random + +_GLIBCXX_END_NAMESPACE_TR1 +} + +#include diff --git a/libstdc++-v3/include/tr1_impl/random.tcc b/libstdc++-v3/include/tr1_impl/random.tcc new file mode 100644 index 0000000..e57d609 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/random.tcc @@ -0,0 +1,1548 @@ +// random number generation (out of line) -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/random.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + /* + * (Further) implementation-space details. + */ + namespace __detail + { + // General case for x = (ax + c) mod m -- use Schrage's algorithm to avoid + // integer overflow. + // + // Because a and c are compile-time integral constants the compiler kindly + // elides any unreachable paths. + // + // Preconditions: a > 0, m > 0. + // + template + struct _Mod + { + static _Tp + __calc(_Tp __x) + { + if (__a == 1) + __x %= __m; + else + { + static const _Tp __q = __m / __a; + static const _Tp __r = __m % __a; + + _Tp __t1 = __a * (__x % __q); + _Tp __t2 = __r * (__x / __q); + if (__t1 >= __t2) + __x = __t1 - __t2; + else + __x = __m - __t2 + __t1; + } + + if (__c != 0) + { + const _Tp __d = __m - __x; + if (__d > __c) + __x += __c; + else + __x = __c - __d; + } + return __x; + } + }; + + // Special case for m == 0 -- use unsigned integer overflow as modulo + // operator. + template + struct _Mod<_Tp, __a, __c, __m, true> + { + static _Tp + __calc(_Tp __x) + { return __a * __x + __c; } + }; + } // namespace __detail + + /** + * Seeds the LCR with integral value @p __x0, adjusted so that the + * ring identity is never a member of the convergence set. + */ + template + void + linear_congruential<_UIntType, __a, __c, __m>:: + seed(unsigned long __x0) + { + if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) + && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); + else + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); + } + + /** + * Seeds the LCR engine with a value generated by @p __g. + */ + template + template + void + linear_congruential<_UIntType, __a, __c, __m>:: + seed(_Gen& __g, false_type) + { + _UIntType __x0 = __g(); + if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) + && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); + else + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); + } + + /** + * Gets the next generated value in sequence. + */ + template + typename linear_congruential<_UIntType, __a, __c, __m>::result_type + linear_congruential<_UIntType, __a, __c, __m>:: + operator()() + { + _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x); + return _M_x; + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const linear_congruential<_UIntType, __a, __c, __m>& __lcr) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__os.widen(' ')); + + __os << __lcr._M_x; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + linear_congruential<_UIntType, __a, __c, __m>& __lcr) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec); + + __is >> __lcr._M_x; + + __is.flags(__flags); + return __is; + } + + + template + void + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>:: + seed(unsigned long __value) + { + _M_x[0] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__value); + + for (int __i = 1; __i < state_size; ++__i) + { + _UIntType __x = _M_x[__i - 1]; + __x ^= __x >> (__w - 2); + __x *= 1812433253ul; + __x += __i; + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__x); + } + _M_p = state_size; + } + + template + template + void + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>:: + seed(_Gen& __gen, false_type) + { + for (int __i = 0; __i < state_size; ++__i) + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__gen()); + _M_p = state_size; + } + + template + typename + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>::result_type + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>:: + operator()() + { + // Reload the vector - cost is O(n) amortized over n calls. + if (_M_p >= state_size) + { + const _UIntType __upper_mask = (~_UIntType()) << __r; + const _UIntType __lower_mask = ~__upper_mask; + + for (int __k = 0; __k < (__n - __m); ++__k) + { + _UIntType __y = ((_M_x[__k] & __upper_mask) + | (_M_x[__k + 1] & __lower_mask)); + _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + } + + for (int __k = (__n - __m); __k < (__n - 1); ++__k) + { + _UIntType __y = ((_M_x[__k] & __upper_mask) + | (_M_x[__k + 1] & __lower_mask)); + _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + } + + _UIntType __y = ((_M_x[__n - 1] & __upper_mask) + | (_M_x[0] & __lower_mask)); + _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + _M_p = 0; + } + + // Calculate o(x(i)). + result_type __z = _M_x[_M_p++]; + __z ^= (__z >> __u); + __z ^= (__z << __s) & __b; + __z ^= (__z << __t) & __c; + __z ^= (__z >> __l); + + return __z; + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __n - 1; ++__i) + __os << __x._M_x[__i] << __space; + __os << __x._M_x[__n - 1]; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (int __i = 0; __i < __n; ++__i) + __is >> __x._M_x[__i]; + + __is.flags(__flags); + return __is; + } + + + template + void + subtract_with_carry<_IntType, __m, __s, __r>:: + seed(unsigned long __value) + { + if (__value == 0) + __value = 19780503; + + std::_GLIBCXX_TR1 linear_congruential + __lcg(__value); + + for (int __i = 0; __i < long_lag; ++__i) + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__lcg()); + + _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; + _M_p = 0; + } + + template + template + void + subtract_with_carry<_IntType, __m, __s, __r>:: + seed(_Gen& __gen, false_type) + { + const int __n = (std::numeric_limits<_UIntType>::digits + 31) / 32; + + for (int __i = 0; __i < long_lag; ++__i) + { + _UIntType __tmp = 0; + _UIntType __factor = 1; + for (int __j = 0; __j < __n; ++__j) + { + __tmp += __detail::__mod<__detail::_UInt32Type, 1, 0, 0> + (__gen()) * __factor; + __factor *= __detail::_Shift<_UIntType, 32>::__value; + } + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__tmp); + } + _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; + _M_p = 0; + } + + template + typename subtract_with_carry<_IntType, __m, __s, __r>::result_type + subtract_with_carry<_IntType, __m, __s, __r>:: + operator()() + { + // Derive short lag index from current index. + int __ps = _M_p - short_lag; + if (__ps < 0) + __ps += long_lag; + + // Calculate new x(i) without overflow or division. + // NB: Thanks to the requirements for _IntType, _M_x[_M_p] + _M_carry + // cannot overflow. + _UIntType __xi; + if (_M_x[__ps] >= _M_x[_M_p] + _M_carry) + { + __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry; + _M_carry = 0; + } + else + { + __xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps]; + _M_carry = 1; + } + _M_x[_M_p] = __xi; + + // Adjust current index to loop around in ring buffer. + if (++_M_p >= long_lag) + _M_p = 0; + + return __xi; + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry<_IntType, __m, __s, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __r; ++__i) + __os << __x._M_x[__i] << __space; + __os << __x._M_carry; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry<_IntType, __m, __s, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (int __i = 0; __i < __r; ++__i) + __is >> __x._M_x[__i]; + __is >> __x._M_carry; + + __is.flags(__flags); + return __is; + } + + + template + void + subtract_with_carry_01<_RealType, __w, __s, __r>:: + _M_initialize_npows() + { + for (int __j = 0; __j < __n; ++__j) +#if _GLIBCXX_USE_C99_MATH_TR1 + _M_npows[__j] = std::_GLIBCXX_TR1 ldexp(_RealType(1), -__w + __j * 32); +#else + _M_npows[__j] = std::pow(_RealType(2), -__w + __j * 32); +#endif + } + + template + void + subtract_with_carry_01<_RealType, __w, __s, __r>:: + seed(unsigned long __value) + { + if (__value == 0) + __value = 19780503; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 512. Seeding subtract_with_carry_01 from a single unsigned long. + std::_GLIBCXX_TR1 linear_congruential + __lcg(__value); + + this->seed(__lcg); + } + + template + template + void + subtract_with_carry_01<_RealType, __w, __s, __r>:: + seed(_Gen& __gen, false_type) + { + for (int __i = 0; __i < long_lag; ++__i) + { + for (int __j = 0; __j < __n - 1; ++__j) + _M_x[__i][__j] = __detail::__mod<_UInt32Type, 1, 0, 0>(__gen()); + _M_x[__i][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, + __detail::_Shift<_UInt32Type, __w % 32>::__value>(__gen()); + } + + _M_carry = 1; + for (int __j = 0; __j < __n; ++__j) + if (_M_x[long_lag - 1][__j] != 0) + { + _M_carry = 0; + break; + } + + _M_p = 0; + } + + template + typename subtract_with_carry_01<_RealType, __w, __s, __r>::result_type + subtract_with_carry_01<_RealType, __w, __s, __r>:: + operator()() + { + // Derive short lag index from current index. + int __ps = _M_p - short_lag; + if (__ps < 0) + __ps += long_lag; + + _UInt32Type __new_carry; + for (int __j = 0; __j < __n - 1; ++__j) + { + if (_M_x[__ps][__j] > _M_x[_M_p][__j] + || (_M_x[__ps][__j] == _M_x[_M_p][__j] && _M_carry == 0)) + __new_carry = 0; + else + __new_carry = 1; + + _M_x[_M_p][__j] = _M_x[__ps][__j] - _M_x[_M_p][__j] - _M_carry; + _M_carry = __new_carry; + } + + if (_M_x[__ps][__n - 1] > _M_x[_M_p][__n - 1] + || (_M_x[__ps][__n - 1] == _M_x[_M_p][__n - 1] && _M_carry == 0)) + __new_carry = 0; + else + __new_carry = 1; + + _M_x[_M_p][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, + __detail::_Shift<_UInt32Type, __w % 32>::__value> + (_M_x[__ps][__n - 1] - _M_x[_M_p][__n - 1] - _M_carry); + _M_carry = __new_carry; + + result_type __ret = 0.0; + for (int __j = 0; __j < __n; ++__j) + __ret += _M_x[_M_p][__j] * _M_npows[__j]; + + // Adjust current index to loop around in ring buffer. + if (++_M_p >= long_lag) + _M_p = 0; + + return __ret; + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_01<_RealType, __w, __s, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __r; ++__i) + for (int __j = 0; __j < __x.__n; ++__j) + __os << __x._M_x[__i][__j] << __space; + __os << __x._M_carry; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_01<_RealType, __w, __s, __r>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (int __i = 0; __i < __r; ++__i) + for (int __j = 0; __j < __x.__n; ++__j) + __is >> __x._M_x[__i][__j]; + __is >> __x._M_carry; + + __is.flags(__flags); + return __is; + } + + + template + typename discard_block<_UniformRandomNumberGenerator, + __p, __r>::result_type + discard_block<_UniformRandomNumberGenerator, __p, __r>:: + operator()() + { + if (_M_n >= used_block) + { + while (_M_n < block_size) + { + _M_b(); + ++_M_n; + } + _M_n = 0; + } + ++_M_n; + return _M_b(); + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block<_UniformRandomNumberGenerator, + __p, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed + | __ios_base::left); + __os.fill(__space); + + __os << __x._M_b << __space << __x._M_n; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block<_UniformRandomNumberGenerator, __p, __r>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_b >> __x._M_n; + + __is.flags(__flags); + return __is; + } + + + template + void + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>:: + _M_initialize_max() + { + const int __w = std::numeric_limits::digits; + + const result_type __m1 = + std::min(result_type(_M_b1.max() - _M_b1.min()), + __detail::_Shift::__value - 1); + + const result_type __m2 = + std::min(result_type(_M_b2.max() - _M_b2.min()), + __detail::_Shift::__value - 1); + + // NB: In TR1 s1 is not required to be >= s2. + if (__s1 < __s2) + _M_max = _M_initialize_max_aux(__m2, __m1, __s2 - __s1) << __s1; + else + _M_max = _M_initialize_max_aux(__m1, __m2, __s1 - __s2) << __s2; + } + + template + typename xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>::result_type + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>:: + _M_initialize_max_aux(result_type __a, result_type __b, int __d) + { + const result_type __two2d = result_type(1) << __d; + const result_type __c = __a * __two2d; + + if (__a == 0 || __b < __two2d) + return __c + __b; + + const result_type __t = std::max(__c, __b); + const result_type __u = std::min(__c, __b); + + result_type __ub = __u; + result_type __p; + for (__p = 0; __ub != 1; __ub >>= 1) + ++__p; + + const result_type __two2p = result_type(1) << __p; + const result_type __k = __t / __two2p; + + if (__k & 1) + return (__k + 1) * __two2p - 1; + + if (__c >= __b) + return (__k + 1) * __two2p + _M_initialize_max_aux((__t % __two2p) + / __two2d, + __u % __two2p, __d); + else + return (__k + 1) * __two2p + _M_initialize_max_aux((__u % __two2p) + / __two2d, + __t % __two2p, __d); + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__space); + + __os << __x.base1() << __space << __x.base2(); + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + __is >> __x._M_b1 >> __x._M_b2; + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + + __os << __x.min() << __space << __x.max(); + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_min >> __x._M_max; + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits::__max_digits10); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template + template + typename geometric_distribution<_IntType, _RealType>::result_type + geometric_distribution<_IntType, _RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + // About the epsilon thing see this thread: + // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html + const _RealType __naf = + (1 - std::numeric_limits<_RealType>::epsilon()) / 2; + // The largest _RealType convertible to _IntType. + const _RealType __thr = + std::numeric_limits<_IntType>::max() + __naf; + + _RealType __cand; + do + __cand = std::ceil(std::log(__urng()) / _M_log_p); + while (__cand >= __thr); + + return result_type(__cand + __naf); + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template + void + poisson_distribution<_IntType, _RealType>:: + _M_initialize() + { +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_mean >= 12) + { + const _RealType __m = std::floor(_M_mean); + _M_lm_thr = std::log(_M_mean); + _M_lfm = std::_GLIBCXX_TR1 lgamma(__m + 1); + _M_sm = std::sqrt(__m); + + const _RealType __pi_4 = 0.7853981633974483096156608458198757L; + const _RealType __dx = std::sqrt(2 * __m * std::log(32 * __m + / __pi_4)); + _M_d = std::_GLIBCXX_TR1 round(std::max(_RealType(6), + std::min(__m, __dx))); + const _RealType __cx = 2 * __m + _M_d; + _M_scx = std::sqrt(__cx / 2); + _M_1cx = 1 / __cx; + + _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx); + _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2)) / _M_d; + } + else +#endif + _M_lm_thr = std::exp(-_M_mean); + } + + /** + * A rejection algorithm when mean >= 12 and a simple method based + * upon the multiplication of uniform random variates otherwise. + * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 + * is defined. + * + * Reference: + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!). + */ + template + template + typename poisson_distribution<_IntType, _RealType>::result_type + poisson_distribution<_IntType, _RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_mean >= 12) + { + _RealType __x; + + // See comments above... + const _RealType __naf = + (1 - std::numeric_limits<_RealType>::epsilon()) / 2; + const _RealType __thr = + std::numeric_limits<_IntType>::max() + __naf; + + const _RealType __m = std::floor(_M_mean); + // sqrt(pi / 2) + const _RealType __spi_2 = 1.2533141373155002512078826424055226L; + const _RealType __c1 = _M_sm * __spi_2; + const _RealType __c2 = _M_c2b + __c1; + const _RealType __c3 = __c2 + 1; + const _RealType __c4 = __c3 + 1; + // e^(1 / 78) + const _RealType __e178 = 1.0129030479320018583185514777512983L; + const _RealType __c5 = __c4 + __e178; + const _RealType __c = _M_cb + __c5; + const _RealType __2cx = 2 * (2 * __m + _M_d); + + bool __reject = true; + do + { + const _RealType __u = __c * __urng(); + const _RealType __e = -std::log(__urng()); + + _RealType __w = 0.0; + + if (__u <= __c1) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = -std::abs(__n) * _M_sm - 1; + __x = std::floor(__y); + __w = -__n * __n / 2; + if (__x < -__m) + continue; + } + else if (__u <= __c2) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = 1 + std::abs(__n) * _M_scx; + __x = std::ceil(__y); + __w = __y * (2 - __y) * _M_1cx; + if (__x > _M_d) + continue; + } + else if (__u <= __c3) + // NB: This case not in the book, nor in the Errata, + // but should be ok... + __x = -1; + else if (__u <= __c4) + __x = 0; + else if (__u <= __c5) + __x = 1; + else + { + const _RealType __v = -std::log(__urng()); + const _RealType __y = _M_d + __v * __2cx / _M_d; + __x = std::ceil(__y); + __w = -_M_d * _M_1cx * (1 + __y / 2); + } + + __reject = (__w - __e - __x * _M_lm_thr + > _M_lfm - std::_GLIBCXX_TR1 lgamma(__x + __m + 1)); + + __reject |= __x + __m >= __thr; + + } while (__reject); + + return result_type(__x + __m + __naf); + } + else +#endif + { + _IntType __x = 0; + _RealType __prod = 1.0; + + do + { + __prod *= __urng(); + __x += 1; + } + while (__prod > _M_lm_thr); + + return __x - 1; + } + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.mean() << __space << __x._M_nd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + __is >> __x._M_mean >> __x._M_nd; + __x._M_initialize(); + + __is.flags(__flags); + return __is; + } + + + template + void + binomial_distribution<_IntType, _RealType>:: + _M_initialize() + { + const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; + + _M_easy = true; + +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_t * __p12 >= 8) + { + _M_easy = false; + const _RealType __np = std::floor(_M_t * __p12); + const _RealType __pa = __np / _M_t; + const _RealType __1p = 1 - __pa; + + const _RealType __pi_4 = 0.7853981633974483096156608458198757L; + const _RealType __d1x = + std::sqrt(__np * __1p * std::log(32 * __np + / (81 * __pi_4 * __1p))); + _M_d1 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d1x)); + const _RealType __d2x = + std::sqrt(__np * __1p * std::log(32 * _M_t * __1p + / (__pi_4 * __pa))); + _M_d2 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d2x)); + + // sqrt(pi / 2) + const _RealType __spi_2 = 1.2533141373155002512078826424055226L; + _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np)); + _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p)); + _M_c = 2 * _M_d1 / __np; + _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2; + const _RealType __a12 = _M_a1 + _M_s2 * __spi_2; + const _RealType __s1s = _M_s1 * _M_s1; + _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p)) + * 2 * __s1s / _M_d1 + * std::exp(-_M_d1 * _M_d1 / (2 * __s1s))); + const _RealType __s2s = _M_s2 * _M_s2; + _M_s = (_M_a123 + 2 * __s2s / _M_d2 + * std::exp(-_M_d2 * _M_d2 / (2 * __s2s))); + _M_lf = (std::_GLIBCXX_TR1 lgamma(__np + 1) + + std::_GLIBCXX_TR1 lgamma(_M_t - __np + 1)); + _M_lp1p = std::log(__pa / __1p); + + _M_q = -std::log(1 - (__p12 - __pa) / __1p); + } + else +#endif + _M_q = -std::log(1 - __p12); + } + + template + template + typename binomial_distribution<_IntType, _RealType>::result_type + binomial_distribution<_IntType, _RealType>:: + _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t) + { + _IntType __x = 0; + _RealType __sum = 0; + + do + { + const _RealType __e = -std::log(__urng()); + __sum += __e / (__t - __x); + __x += 1; + } + while (__sum <= _M_q); + + return __x - 1; + } + + /** + * A rejection algorithm when t * p >= 8 and a simple waiting time + * method - the second in the referenced book - otherwise. + * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 + * is defined. + * + * Reference: + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. X, Sect. 4 (+ Errata!). + */ + template + template + typename binomial_distribution<_IntType, _RealType>::result_type + binomial_distribution<_IntType, _RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __ret; + const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; + +#if _GLIBCXX_USE_C99_MATH_TR1 + if (!_M_easy) + { + _RealType __x; + + // See comments above... + const _RealType __naf = + (1 - std::numeric_limits<_RealType>::epsilon()) / 2; + const _RealType __thr = + std::numeric_limits<_IntType>::max() + __naf; + + const _RealType __np = std::floor(_M_t * __p12); + const _RealType __pa = __np / _M_t; + + // sqrt(pi / 2) + const _RealType __spi_2 = 1.2533141373155002512078826424055226L; + const _RealType __a1 = _M_a1; + const _RealType __a12 = __a1 + _M_s2 * __spi_2; + const _RealType __a123 = _M_a123; + const _RealType __s1s = _M_s1 * _M_s1; + const _RealType __s2s = _M_s2 * _M_s2; + + bool __reject; + do + { + const _RealType __u = _M_s * __urng(); + + _RealType __v; + + if (__u <= __a1) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = _M_s1 * std::abs(__n); + __reject = __y >= _M_d1; + if (!__reject) + { + const _RealType __e = -std::log(__urng()); + __x = std::floor(__y); + __v = -__e - __n * __n / 2 + _M_c; + } + } + else if (__u <= __a12) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = _M_s2 * std::abs(__n); + __reject = __y >= _M_d2; + if (!__reject) + { + const _RealType __e = -std::log(__urng()); + __x = std::floor(-__y); + __v = -__e - __n * __n / 2; + } + } + else if (__u <= __a123) + { + const _RealType __e1 = -std::log(__urng()); + const _RealType __e2 = -std::log(__urng()); + + const _RealType __y = _M_d1 + 2 * __s1s * __e1 / _M_d1; + __x = std::floor(__y); + __v = (-__e2 + _M_d1 * (1 / (_M_t - __np) + -__y / (2 * __s1s))); + __reject = false; + } + else + { + const _RealType __e1 = -std::log(__urng()); + const _RealType __e2 = -std::log(__urng()); + + const _RealType __y = _M_d2 + 2 * __s2s * __e1 / _M_d2; + __x = std::floor(-__y); + __v = -__e2 - _M_d2 * __y / (2 * __s2s); + __reject = false; + } + + __reject = __reject || __x < -__np || __x > _M_t - __np; + if (!__reject) + { + const _RealType __lfx = + std::_GLIBCXX_TR1 lgamma(__np + __x + 1) + + std::_GLIBCXX_TR1 lgamma(_M_t - (__np + __x) + 1); + __reject = __v > _M_lf - __lfx + __x * _M_lp1p; + } + + __reject |= __x + __np >= __thr; + } + while (__reject); + + __x += __np + __naf; + + const _IntType __z = _M_waiting(__urng, _M_t - _IntType(__x)); + __ret = _IntType(__x) + __z; + } + else +#endif + __ret = _M_waiting(__urng, _M_t); + + if (__p12 != _M_p) + __ret = _M_t - __ret; + return __ret; + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.t() << __space << __x.p() + << __space << __x._M_nd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_t >> __x._M_p >> __x._M_nd; + __x._M_initialize(); + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.min() << __space << __x.max(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + __is >> __x._M_min >> __x._M_max; + + __is.flags(__flags); + return __is; + } + + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.lambda(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + /** + * Polar method due to Marsaglia. + * + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. V, Sect. 4.4. + */ + template + template + typename normal_distribution<_RealType>::result_type + normal_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __ret; + + if (_M_saved_available) + { + _M_saved_available = false; + __ret = _M_saved; + } + else + { + result_type __x, __y, __r2; + do + { + __x = result_type(2.0) * __urng() - 1.0; + __y = result_type(2.0) * __urng() - 1.0; + __r2 = __x * __x + __y * __y; + } + while (__r2 > 1.0 || __r2 == 0.0); + + const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2); + _M_saved = __x * __mult; + _M_saved_available = true; + __ret = __y * __mult; + } + + __ret = __ret * _M_sigma + _M_mean; + return __ret; + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x._M_saved_available << __space + << __x.mean() << __space + << __x.sigma(); + if (__x._M_saved_available) + __os << __space << __x._M_saved; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_saved_available >> __x._M_mean + >> __x._M_sigma; + if (__x._M_saved_available) + __is >> __x._M_saved; + + __is.flags(__flags); + return __is; + } + + + template + void + gamma_distribution<_RealType>:: + _M_initialize() + { + if (_M_alpha >= 1) + _M_l_d = std::sqrt(2 * _M_alpha - 1); + else + _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha)) + * (1 - _M_alpha)); + } + + /** + * Cheng's rejection algorithm GB for alpha >= 1 and a modification + * of Vaduva's rejection from Weibull algorithm due to Devroye for + * alpha < 1. + * + * References: + * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral + * Shape Parameter." Applied Statistics, 26, 71-75, 1977. + * + * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection + * and Composition Procedures." Math. Operationsforschung and Statistik, + * Series in Statistics, 8, 545-576, 1977. + * + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!). + */ + template + template + typename gamma_distribution<_RealType>::result_type + gamma_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x; + + bool __reject; + if (_M_alpha >= 1) + { + // alpha - log(4) + const result_type __b = _M_alpha + - result_type(1.3862943611198906188344642429163531L); + const result_type __c = _M_alpha + _M_l_d; + const result_type __1l = 1 / _M_l_d; + + // 1 + log(9 / 2) + const result_type __k = 2.5040773967762740733732583523868748L; + + do + { + const result_type __u = __urng(); + const result_type __v = __urng(); + + const result_type __y = __1l * std::log(__v / (1 - __v)); + __x = _M_alpha * std::exp(__y); + + const result_type __z = __u * __v * __v; + const result_type __r = __b + __c * __y - __x; + + __reject = __r < result_type(4.5) * __z - __k; + if (__reject) + __reject = __r < std::log(__z); + } + while (__reject); + } + else + { + const result_type __c = 1 / _M_alpha; + + do + { + const result_type __z = -std::log(__urng()); + const result_type __e = -std::log(__urng()); + + __x = std::pow(__z, __c); + + __reject = __z + __e < _M_l_d + __x; + } + while (__reject); + } + + return __x; + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.alpha(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/regex b/libstdc++-v3/include/tr1_impl/regex new file mode 100644 index 0000000..de695dd --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/regex @@ -0,0 +1,2414 @@ +// class template regex -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** + * @file tr1_impl/regex + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + +/** + * @addtogroup tr1_regex Regular Expressions + * A facility for performing regular expression pattern matching. + * @{ + */ + +namespace regex_constants +{ + // [7.5.1] Bitmask Type syntax_option_type + enum __syntax_option + { + _S_icase, + _S_nosubs, + _S_optimize, + _S_collate, + _S_ECMAScript, + _S_basic, + _S_extended, + _S_awk, + _S_grep, + _S_egrep, + _S_syntax_last + }; + + /** + * @brief This is a bitmask type indicating how to interpret the regex. + * + * The @c syntax_option_type is implementation defined but it is valid to + * perform bitwise operations on these values and expect the right thing to + * happen. + * + * A valid value of type syntax_option_type shall have exactly one of the + * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep + * set. + */ + typedef unsigned int syntax_option_type; + + /// Specifies that the matching of regular expressions against a character + /// sequence shall be performed without regard to case. + static const syntax_option_type icase = 1 << _S_icase; + + /// Specifies that when a regular expression is matched against a character + /// container sequence, no sub-expression matches are to be stored in the + /// supplied match_results structure. + static const syntax_option_type nosubs = 1 << _S_nosubs; + + /// Specifies that the regular expression engine should pay more attention to + /// the speed with which regular expressions are matched, and less to the + /// speed with which regular expression objects are constructed. Otherwise + /// it has no detectable effect on the program output. + static const syntax_option_type optimize = 1 << _S_optimize; + + /// Specifies that character ranges of the form [a-b] should be locale + /// sensitive. + static const syntax_option_type collate = 1 << _S_collate; + + /// Specifies that the grammar recognized by the regular expression engine is + /// that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript + /// Language Specification, Standard Ecma-262, third edition, 1999], as + /// modified in tr1 section [7.13]. This grammar is similar to that defined + /// in the PERL scripting language but extended with elements found in the + /// POSIX regular expression grammar. + static const syntax_option_type ECMAScript = 1 << _S_ECMAScript; + + /// Specifies that the grammar recognized by the regular expression engine is + /// that used by POSIX basic regular expressions in IEEE Std 1003.1-2001, + /// Portable Operating System Interface (POSIX), Base Definitions and + /// Headers, Section 9, Regular Expressions [IEEE, Information Technology -- + /// Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. + static const syntax_option_type basic = 1 << _S_basic; + + /// Specifies that the grammar recognized by the regular expression engine is + /// that used by POSIX extended regular expressions in IEEE Std 1003.1-2001, + /// Portable Operating System Interface (POSIX), Base Definitions and Headers, + /// Section 9, Regular Expressions. + static const syntax_option_type extended = 1 << _S_extended; + + /// Specifies that the grammar recognized by the regular expression engine is + /// that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is + /// identical to syntax_option_type extended, except that C-style escape + /// sequences are supported. These sequences are, explicitly, '\\', '\a', + /// '\b', '\f', '\n', '\r', '\t' , '\v', '\"', '\\', and '\ddd' (where ddd is + /// one, two, or three octal digits). + static const syntax_option_type awk = 1 << _S_awk; + + /// Specifies that the grammar recognized by the regular expression engine is + /// that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is + /// identical to syntax_option_type basic, except that newlines are treated + /// as whitespace. + static const syntax_option_type grep = 1 << _S_grep; + + /// Specifies that the grammar recognized by the regular expression engine is + /// that used by POSIX utility grep when given the -E option in + /// IEEE Std 1003.1-2001. This option is identical to syntax_option_type + /// extended, except that newlines are treated as whitespace. + static const syntax_option_type egrep = 1 << _S_egrep; + + + // [7.5.2] Bitmask Type match_flag_type + enum __match_flag + { + _S_not_bol, + _S_not_eol, + _S_not_bow, + _S_not_eow, + _S_any, + _S_not_null, + _S_continuous, + _S_prev_avail, + _S_sed, + _S_no_copy, + _S_first_only, + _S_match_flag_last + }; + + /** + * @brief This is a bitmask type indicating regex matching rules. + * + * Matching a regular expression against a sequence of characters [first, + * last) proceeds according to the rules of the grammar specified for the + * regular expression object, modified according to the effects listed + * below for any bitmask elements set. + * + * The @c match_flag_type is implementation defined but it is valid to + * perform bitwise operations on these values and expect the right thing to + * happen. + */ + typedef std::bitset<_S_match_flag_last> match_flag_type; + + static const match_flag_type match_default = 0; + + /// The first character in the sequence [first, last) is treated as though it + /// is not at the beginning of a line, so the character "^" in the regular + /// expression shall not match [first, first). + static const match_flag_type match_not_bol = 1 << _S_not_bol; + + /// The last character in the sequence [first, last) is treated as though it + /// is not at the end of a line, so the character "$" in the regular + /// expression shall not match [last, last). + static const match_flag_type match_not_eol = 1 << _S_not_eol; + + /// The expression "\b" is not matched against the sub-sequence + /// [first,first). + static const match_flag_type match_not_bow = 1 << _S_not_bow; + + /// The expression "\b" should not be matched against the sub-sequence + /// [last,last). + static const match_flag_type match_not_eow = 1 << _S_not_eow; + + /// If more than one match is possible then any match is an acceptable + /// result. + static const match_flag_type match_any = 1 << _S_any; + + /// The expression does not match an empty sequence. + static const match_flag_type match_not_null = 1 << _S_not_null; + + /// The expression only matchs a sub-sequence that begins at first . + static const match_flag_type match_continuous = 1 << _S_continuous; + + /// --first is a valid iterator position. When this flag is set then the + /// flags match_not_bol and match_not_bow are ignored by the regular + /// expression algorithms 7.11 and iterators 7.12. + static const match_flag_type match_prev_avail = 1 << _S_prev_avail; + + /// When a regular expression match is to be replaced by a new string, the + /// new string is constructed using the rules used by the ECMAScript replace + /// function in ECMA- 262 [Ecma International, ECMAScript Language + /// Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11 + /// String.prototype.replace. In addition, during search and replace + /// operations all non-overlapping occurrences of the regular expression + /// are located and replaced, and sections of the input that did not match + /// the expression are copied unchanged to the output string. + /// + /// Format strings (from ECMA-262 [15.5.4.11]): + /// $$ $ + /// $& The matched substring. + /// $` The portion of string that preceeds the matched substring. + /// $' The portion of string that follows the matched substring. + /// $n The nth capture, where n is in [1,9] and $n is not followed by a + /// decimal digit. If n <= m and the nth capture is undefined, use the + /// empty string + /// instead. If n > m, the result is implementation-defined. + /// $nn The nnth capture, where nn is a two-digit decimal number on [01, 99]. + /// If nn <= m and the nth capture is undefined, use the empty string + /// instead. If nn > m, the result is implementation-defined. + /// + static const match_flag_type format_default = 0; + + /// When a regular expression match is to be replaced by a new string, the + /// new string is constructed using the rules used by the POSIX sed utility + /// in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable + /// Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. + static const match_flag_type format_sed = 1 << _S_sed; + + /// During a search and replace operation, sections of the character + /// container sequence being searched that do not match the regular + /// expression shall not be copied to the output string. + static const match_flag_type format_no_copy = 1 << _S_no_copy; + + /// When specified during a search and replace operation, only the first + /// occurrence of the regular expression shall be replaced. + static const match_flag_type format_first_only = 1 << _S_first_only; + + + // [7.5.3] implementation-defined error type + enum error_type + { + _S_error_collate, + _S_error_ctype, + _S_error_escape, + _S_error_backref, + _S_error_brack, + _S_error_paren, + _S_error_brace, + _S_error_badbrace, + _S_error_range, + _S_error_space, + _S_error_badrepeat, + _S_error_complexity, + _S_error_stack, + _S_error_last + }; + + /// The expression contained an invalid collating element name. + static const error_type error_collate(_S_error_collate); + + /// The expression contained an invalid character class name. + static const error_type error_ctype(_S_error_ctype); + + /// The expression contained an invalid escaped character, or a trailing + /// escape. + static const error_type error_escape(_S_error_escape); + + /// The expression contained an invalid back reference. + static const error_type error_backref(_S_error_backref); + + /// The expression contained mismatched [ and ]. + static const error_type error_brack(_S_error_brack); + + /// The expression contained mismatched ( and ). + static const error_type error_paren(_S_error_paren); + + /// The expression contained mismatched { and } + static const error_type error_brace(_S_error_brace); + + /// The expression contained an invalid range in a {} expression. + static const error_type error_badbrace(_S_error_badbrace); + + /// The expression contained an invalid character range, + /// such as [b-a] in most encodings. + static const error_type error_range(_S_error_range); + + /// There was insufficient memory to convert the expression into a + /// finite state machine. + static const error_type error_space(_S_error_space); + + /// One of *?+{ was not preceded by a valid regular expression. + static const error_type error_badrepeat(_S_error_badrepeat); + + /// The complexity of an attempted match against a regular expression + /// exceeded a pre-set level. + static const error_type error_complexity(_S_error_complexity); + + /// There was insufficient memory to determine whether the + /// regular expression could match the specified character sequence. + static const error_type error_stack(_S_error_stack); +} + + + // [7.8] Class regex_error + /** + * Defines the type of objects thrown as exceptions to report errors from the + * regular expression library. + */ + class regex_error + : public std::runtime_error + { + public: + /** + * @brief constructs a regex_error object. + * + * @param ecode the regex error code. + */ + explicit + regex_error(regex_constants::error_type __ecode) + : std::runtime_error("regex_error"), _M_code(__ecode) + { } + + /** + * @brief gets the regex error code. + * + * @returns the regex error code. + */ + regex_constants::error_type + code() const + { return _M_code; } + + protected: + regex_constants::error_type _M_code; + }; + + + // [7.7] Class regex_traits + /** + * A regular expression traits class that satisfies the requirements of tr1 + * section [7.2]. + * + * The class %regex is parameterized around a set of related types and + * functions used to complete the definition of its semantics. This class + * satisfies the requirements of such a traits class. + */ + template + struct regex_traits + { + public: + typedef _Ch_type char_type; + typedef std::basic_string string_type; + typedef std::locale locale_type; + typedef std::ctype_base::mask char_class_type; + + public: + /** + * @brief Constructs a default traits object. + */ + regex_traits() + { } + + /** + * @brief Gives the length of a C-style string starting at @p __p. + * + * @param __p a pointer to the start of a character sequence. + * + * @returns the number of characters between @p *__p and the first + * default-initialized value of type @p char_type. In other words, uses + * the C-string algorithm for determiining the length of a sequence of + * characters. + */ + static std::size_t + length(const char_type* __p) + { return string_type::traits_type::length(__p); } + + /** + * @brief Performs the identity translation. + * + * @param c A character to the locale-specific character set. + * + * @returns c. + */ + char_type + translate(char_type __c) const + { return __c; } + + /** + * @brief Translates a character into a case-insensitive equivalent. + * + * @param c A character to the locale-specific character set. + * + * @returns the locale-specific lower-case equivalent of c. + * @throws std::bad_cast if the imbued locale does not support the ctype + * facet. + */ + char_type + translate_nocase(char_type __c) const + { + using std::ctype; + using std::use_facet; + return use_facet >(_M_locale).tolower(__c); + } + + /** + * @brief Gets a sort key for a character sequence. + * + * @param first beginning of the character sequence. + * @param last one-past-the-end of the character sequence. + * + * Returns a sort key for the character sequence designated by the + * iterator range [F1, F2) such that if the character sequence [G1, G2) + * sorts before the character sequence [H1, H2) then + * v.transform(G1, G2) < v.transform(H1, H2). + * + * What this really does is provide a more efficient way to compare a + * string to multiple other strings in locales with fancy collation + * rules and equivalence classes. + * + * @returns a locale-specific sort key equivalent to the input range. + * + * @throws std::bad_cast if the current locale does not have a collate + * facet. + */ + template + string_type + transform(_Fwd_iter __first, _Fwd_iter __last) const + { + using std::collate; + using std::use_facet; + const collate<_Ch_type>& __c(use_facet< + collate<_Ch_type> >(_M_locale)); + string_type __s(__first, __last); + return __c.transform(__s.data(), __s.data() + __s.size()); + } + + /** + * @brief Dunno. + * + * @param first beginning of the character sequence. + * @param last one-past-the-end of the character sequence. + * + * Effects: if typeid(use_facet >) == + * typeid(collate_byname<_Ch_type>) and the form of the sort key + * returned by collate_byname<_Ch_type>::transform(first, last) is known + * and can be converted into a primary sort key then returns that key, + * otherwise returns an empty string. WTF?? + * + * @todo Implement this function. + */ + template + string_type + transform_primary(_Fwd_iter __first, _Fwd_iter __last) const + { return string_type(); } + + /** + * @breief Gets a collation element by name. + * + * @param first beginning of the collation element name. + * @param last one-past-the-end of the collation element name. + * + * @returns a sequence of one or more characters that represents the + * collating element consisting of the character sequence designated by + * the iterator range [first, last). Returns an empty string if the + * character sequence is not a valid collating element. + * + * @todo Implement this function. + */ + template + string_type + lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const + { return string_type(); } + + /** + * @brief Maps one or mire characters to a named character + * classification. + * + * @param first beginning of the character sequence. + * @param last one-past-the-end of the character sequence. + * + * @returns an unspecified value that represents the character + * classification named by the character sequence designated by the + * iterator range [first, last). The value returned shall be independent + * of the case of the characters in the character sequence. If the name + * is not recognized then returns a value that compares equal to 0. + * + * At least the following names (or their wide-character equivalent) are + * supported. + * - d + * - w + * - s + * - alnum + * - alpha + * - blank + * - cntrl + * - digit + * - graph + * - lower + * - print + * - punct + * - space + * - upper + * - xdigit + * + * @todo Implement this function. + */ + template + char_class_type + lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const + { return 0; } + + /** + * @brief Determines if @p c is a member of an identified class. + * + * @param c a character. + * @param f a class type (as returned from lookup_classname). + * + * @returns true if the character @p c is a member of the classification + * represented by @p f, false otherwise. + * + * @throws std::bad_cast if the current locale does not have a ctype + * facet. + */ + bool + isctype(_Ch_type __c, char_class_type __f) const + { + using std::ctype; + using std::use_facet; + const ctype<_Ch_type>& __ctype(use_facet< + ctype<_Ch_type> >(_M_locale)); + + if (__ctype.is(__c, __f)) + return true; + + // special case of underscore in [[:w:]] + if (__c == __ctype.widen('_')) + { + const char* const __wb[] = "w"; + char_class_type __wt = this->lookup_classname(__wb, + __wb + sizeof(__wb)); + if (__f | __wt) + return true; + } + + // special case of [[:space:]] in [[:blank:]] + if (__c == __ctype.isspace(__c)) + { + const char* const __bb[] = "blank"; + char_class_type __bt = this->lookup_classname(__bb, + __bb + sizeof(__bb)); + if (__f | __bt) + return true; + } + + return false; + } + + /** + * @brief Converts a digit to an int. + * + * @param ch a character representing a digit. + * @param radix the radix if the numeric conversion (limited to 8, 10, + * or 16). + * + * @returns the value represented by the digit ch in base radix if the + * character ch is a valid digit in base radix; otherwise returns -1. + * + * @todo Implement this function. + */ + int + value(_Ch_type __ch, int __radix) const; + + /** + * @brief Imbues the regex_traits object with a copy of a new locale. + * + * @param loc A locale. + * + * @returns a copy of the previous locale in use by the regex_traits + * object. + * + * @note Calling imbue with a different locale than the one currently in + * use invalidates all cached data held by *this. + */ + locale_type + imbue(locale_type __loc) + { + std::swap(_M_locale, __loc); + return __loc; + } + + /** + * @brief Gets a copy of the current locale in use by the regex_traits + * object. + */ + locale_type + getloc() const + { return _M_locale; } + + protected: + locale_type _M_locale; + }; + + + // [7.8] Class basic_regex + /** + * Objects of specializations of this class represent regular expressions + * constructed from sequences of character type @p _Ch_type. + * + * Storage for the regular expression is allocated and deallocated as + * necessary by the member functions of this class. + */ + template > + class basic_regex + { + public: + // types: + typedef _Ch_type value_type; + typedef regex_constants::syntax_option_type flag_type; + typedef typename _Rx_traits::locale_type locale_type; + typedef typename _Rx_traits::string_type string_type; + + // [7.8.1] constants + static const regex_constants::syntax_option_type icase + = regex_constants::icase; + static const regex_constants::syntax_option_type nosubs + = regex_constants::nosubs; + static const regex_constants::syntax_option_type optimize + = regex_constants::optimize; + static const regex_constants::syntax_option_type collate + = regex_constants::collate; + static const regex_constants::syntax_option_type ECMAScript + = regex_constants::ECMAScript; + static const regex_constants::syntax_option_type basic + = regex_constants::basic; + static const regex_constants::syntax_option_type extended + = regex_constants::extended; + static const regex_constants::syntax_option_type awk + = regex_constants::awk; + static const regex_constants::syntax_option_type grep + = regex_constants::grep; + static const regex_constants::syntax_option_type egrep + = regex_constants::egrep; + + // [7.8.2] construct/copy/destroy + /** + * Constructs a basic regular expression that does not match any + * character sequence. + */ + basic_regex() + : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0) + { _M_compile(); } + + /** + * @brief Constructs a basic regular expression from the sequence + * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the + * flags in @p f. + * + * @param p A pointer to the start of a C-style null-terminated string + * containing a regular expression. + * @param f Flags indicating the syntax rules and options. + * + * @throws regex_error if @p p is not a valid regular expression. + */ + explicit + basic_regex(const _Ch_type* __p, + flag_type __f = regex_constants::ECMAScript) + : _M_flags(__f), _M_pattern(__p), _M_mark_count(0) + { _M_compile(); } + + /** + * @brief Constructs a basic regular expression from the sequence + * [p, p + len) interpreted according to the flags in @p f. + * + * @param p A pointer to the start of a string containing a regular + * expression. + * @param len The length of the string containing the regular expression. + * @param f Flags indicating the syntax rules and options. + * + * @throws regex_error if @p p is not a valid regular expression. + */ + basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f) + : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0) + { _M_compile(); } + + /** + * @brief Copy-contructs a basic regular expression. + * + * @param rhs A @p regex object. + */ + basic_regex(const basic_regex& __rhs) + : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern), + _M_mark_count(__rhs._M_mark_count) + { _M_compile(); } + + /** + * @brief Constructs a basic regular expression from the string + * @p interpreted according to the flags in @p f. + * + * @param p A string containing a regular expression. + * @param f Flags indicating the syntax rules and options. + * + * @throws regex_error if @p p is not a valid regular expression. + */ + template + explicit + basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, + flag_type __f = regex_constants::ECMAScript) + : _M_flags(__f), _M_pattern(__s), _M_mark_count(0) + { _M_compile(); } + + /** + * @brief Constructs a basic regular expression from the range + * [first, last) interpreted according to the flags in @p f. + * + * @param first The start of arange containing a valid regular + * expression. + * @param last The end of a range containing a valid regular + * expression. + * @param f The format flags of the regular expression. + * + * @throws regex_error if @p p is not a valid regular expression. + */ + template + basic_regex(_InputIterator __first, _InputIterator __last, + flag_type __f = regex_constants::ECMAScript) + : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0) + { _M_compile(); } + + /** + * @brief Destroys a basic regular expression. + */ + ~basic_regex() + { } + + /** + * @brief Assigns one regular expression to another. + */ + basic_regex& + operator=(const basic_regex& __rhs) + { return this->assign(__rhs); } + + /** + * @brief Replaces a regular expression with a new one constructed from + * a C-style null-terminated string. + * + * @param A pointer to the start of a null-terminated C-style string + * containing a regular expression. + */ + basic_regex& + operator=(const _Ch_type* __p) + { return this->assign(__p, flags()); } + + /** + * @brief Replaces a regular expression with a new one constructed from + * a string. + * + * @param A pointer to a string containing a regular expression. + */ + template + basic_regex& + operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s) + { return this->assign(__s, flags()); } + + // [7.8.3] assign + /** + * @brief the real assignment operator. + * + * @param that Another regular expression object. + */ + basic_regex& + assign(const basic_regex& __that) + { + basic_regex __tmp(__that); + this->swap(__tmp); + return *this; + } + + /** + * @brief Assigns a new regular expression to a regex object from a + * C-style null-terminated string containing a regular expression + * pattern. + * + * @param p A pointer to a C-style null-terminated string containing + * a regular expression pattern. + * @param flags Syntax option flags. + * + * @throws regex_error if p does not contain a valid regular expression + * pattern interpreted according to @p flags. If regex_error is thrown, + * *this remains unchanged. + */ + basic_regex& + assign(const _Ch_type* __p, + flag_type __flags = regex_constants::ECMAScript) + { return this->assign(string_type(__p), __flags); } + + /** + * @brief Assigns a new regular expression to a regex object from a + * C-style string containing a regular expression pattern. + * + * @param p A pointer to a C-style string containing a + * regular expression pattern. + * @param len The length of the regular expression pattern string. + * @param flags Syntax option flags. + * + * @throws regex_error if p does not contain a valid regular expression + * pattern interpreted according to @p flags. If regex_error is thrown, + * *this remains unchanged. + */ + basic_regex& + assign(const _Ch_type* __p, std::size_t __len, flag_type __flags) + { return this->assign(string_type(__p, __len), __flags); } + + /** + * @brief Assigns a new regular expression to a regex object from a + * string containing a regular expression pattern. + * + * @param s A string containing a regular expression pattern. + * @param flags Syntax option flags. + * + * @throws regex_error if p does not contain a valid regular expression + * pattern interpreted according to @p flags. If regex_error is thrown, + * *this remains unchanged. + */ + template + basic_regex& + assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s, + flag_type __f = regex_constants::ECMAScript) + { + basic_regex __tmp(__s, __f); + this->swap(__tmp); + return *this; + } + + /** + * @brief Assigns a new regular expression to a regex object. + * + * @param first The start of a range containing a valid regular + * expression. + * @param last The end of a range containing a valid regular + * expression. + * @param flags Syntax option flags. + * + * @throws regex_error if p does not contain a valid regular expression + * pattern interpreted according to @p flags. If regex_error is thrown, + * *this remains unchanged. + */ + template + basic_regex& + assign(_InputIterator __first, _InputIterator __last, + flag_type __flags = regex_constants::ECMAScript) + { return this->assign(string_type(__first, __last), __flags); } + + // [7.8.4] const operations + /** + * @brief Gets the number of marked subexpressions within the regular + * expresison. + */ + unsigned int + mark_count() const + { return _M_mark_count; } + + /** + * @brief Gets the flags used to construct the regular expression + * or in the last call to assign(). + */ + flag_type + flags() const + { return _M_flags; } + + // [7.8.5] locale + /** + * @brief Imbues the regular expression object with the given locale. + * + * @param loc A locale. + */ + locale_type + imbue(locale_type __loc) + { return _M_traits.imbue(__loc); } + + /** + * @brief Gets the locale currently imbued in the regular expression + * object. + */ + locale_type + getloc() const + { return _M_traits.getloc(); } + + // [7.8.6] swap + /** + * @brief Swaps the contents of two regular expression obects. + * + * @param rhs Another regular expression object. + */ + void + swap(basic_regex& __rhs) + { + std::swap(_M_flags, __rhs._M_flags); + std::swap(_M_pattern, __rhs._M_pattern); + std::swap(_M_mark_count, __rhs._M_mark_count); + std::swap(_M_traits, __rhs._M_traits); + } + + private: + /** + * @brief Compiles a regular expression pattern into a NFA. + * @todo Implement this function. + */ + void _M_compile() + { } + + protected: + flag_type _M_flags; + string_type _M_pattern; + unsigned int _M_mark_count; + _Rx_traits _M_traits; + }; + + typedef basic_regex regex; +#ifdef _GLIBCXX_USE_WCHAR_T + typedef basic_regex wregex; +#endif + + + // [7.8.6] basic_regex swap + /** + * @brief Swaps the contents of two regular expression objects. + * @param lhs First regular expression. + * @param rhs Second regular expression. + */ + template + inline void + swap(basic_regex<_Ch_type, _Rx_traits>& __lhs, + basic_regex<_Ch_type, _Rx_traits>& __rhs) + { return __lhs.swap(__rhs); } + + + // [7.9] Class template sub_match + /** + * A sequence of characters matched by a particular marked sub-expression. + * + * An object of this class is essentially a pair of iterators marking a + * matched subexpression within a regular expression pattern match. Such + * objects can be converted to and compared with std::basic_string objects + * of a similar base character type as the pattern matched by the regular + * expression. + * + * The iterators that make up the pair are the usual half-open interval + * referencing the actual original pattern matched. + */ + template + class sub_match : public std::pair<_BiIter, _BiIter> + { + public: + typedef typename iterator_traits<_BiIter>::value_type value_type; + typedef typename iterator_traits<_BiIter>::difference_type + difference_type; + typedef _BiIter iterator; + + public: + bool matched; + + /** + * Gets the length of the matching sequence. + */ + difference_type + length() const + { return this->matched ? std::distance(this->first, this->second) : 0; } + + /** + * @brief Gets the matching sequence as a string. + * + * @returns the matching sequence as a string. + * + * This is the implicit conversion operator. It is identical to the + * str() member function except that it will want to pop up in + * unexpected places and cause a great deal of confusion and cursing + * from the unwary. + */ + operator basic_string() const + { + return this->matched + ? std::basic_string(this->first, this->second) + : std::basic_string(); + } + + /** + * @brief Gets the matching sequence as a string. + * + * @returns the matching sequence as a string. + */ + basic_string + str() const + { + return this->matched + ? std::basic_string(this->first, this->second) + : std::basic_string(); + } + + /** + * @brief Compares this and another matched sequence. + * + * @param s Another matched sequence to compare to this one. + * + * @retval <0 this matched sequence will collate before @p s. + * @retval =0 this matched sequence is equivalent to @p s. + * @retval <0 this matched sequence will collate after @p s. + */ + int + compare(const sub_match& __s) const + { return this->str().compare(__s.str()); } + + /** + * @brief Compares this sub_match to a string. + * + * @param s A string to compare to this sub_match. + * + * @retval <0 this matched sequence will collate before @p s. + * @retval =0 this matched sequence is equivalent to @p s. + * @retval <0 this matched sequence will collate after @p s. + */ + int + compare(const basic_string& __s) const + { return this->str().compare(__s); } + + /** + * @brief Compares this sub_match to a C-style string. + * + * @param s A C-style string to compare to this sub_match. + * + * @retval <0 this matched sequence will collate before @p s. + * @retval =0 this matched sequence is equivalent to @p s. + * @retval <0 this matched sequence will collate after @p s. + */ + int + compare(const value_type* __s) const + { return this->str().compare(__s); } + }; + + + typedef sub_match csub_match; + typedef sub_match ssub_match; +#ifdef _GLIBCXX_USE_WCHAR_T + typedef sub_match wcsub_match; + typedef sub_match wssub_match; +#endif + + // [7.9.2] sub_match non-member operators + + /** + * @brief Tests the equivalence of two regular expression submatches. + * @param lhs First regular expression submatch. + * @param rhs Second regular expression submatch. + * @returns true if @a lhs is equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator==(const sub_match<_BiIter>& __lhs, + const sub_match<_BiIter>& __rhs) + { return __lhs.compare(__rhs) == 0; } + + /** + * @brief Tests the inequivalence of two regular expression submatches. + * @param lhs First regular expression submatch. + * @param rhs Second regular expression submatch. + * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator!=(const sub_match<_BiIter>& __lhs, + const sub_match<_BiIter>& __rhs) + { return __lhs.compare(__rhs) != 0; } + + /** + * @brief Tests the ordering of two regular expression submatches. + * @param lhs First regular expression submatch. + * @param rhs Second regular expression submatch. + * @returns true if @a lhs precedes @a rhs, false otherwise. + */ + template + inline bool + operator<(const sub_match<_BiIter>& __lhs, + const sub_match<_BiIter>& __rhs) + { return __lhs.compare(__rhs) < 0; } + + /** + * @brief Tests the ordering of two regular expression submatches. + * @param lhs First regular expression submatch. + * @param rhs Second regular expression submatch. + * @returns true if @a lhs does not succeed @a rhs, false otherwise. + */ + template + inline bool + operator<=(const sub_match<_BiIter>& __lhs, + const sub_match<_BiIter>& __rhs) + { return __lhs.compare(__rhs) <= 0; } + + /** + * @brief Tests the ordering of two regular expression submatches. + * @param lhs First regular expression submatch. + * @param rhs Second regular expression submatch. + * @returns true if @a lhs does not preceed @a rhs, false otherwise. + */ + template + inline bool + operator>=(const sub_match<_BiIter>& __lhs, + const sub_match<_BiIter>& __rhs) + { return __lhs.compare(__rhs) >= 0; } + + /** + * @brief Tests the ordering of two regular expression submatches. + * @param lhs First regular expression submatch. + * @param rhs Second regular expression submatch. + * @returns true if @a lhs succeeds @a rhs, false otherwise. + */ + template + inline bool + operator>(const sub_match<_BiIter>& __lhs, + const sub_match<_BiIter>& __rhs) + { return __lhs.compare(__rhs) > 0; } + + /** + * @brief Tests the equivalence of a string and a regular expression + * submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs is equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator==(const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs == __rhs.str(); } + + /** + * @brief Tests the inequivalence of a string and a regular expression + * submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator!=(const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) + { return __lhs != __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs precedes @a rhs, false otherwise. + */ + template + inline bool + operator<(const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) + { return __lhs < __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs succeeds @a rhs, false otherwise. + */ + template + inline bool + operator>(const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) + { return __lhs > __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs does not preceed @a rhs, false otherwise. + */ + template + inline bool + operator>=(const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) + { return __lhs >= __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs does not succeed @a rhs, false otherwise. + */ + template + inline bool + operator<=(const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs) + { return __lhs <= __rhs.str(); } + + /** + * @brief Tests the equivalence of a regular expression submatch and a + * string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs is equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator==(const sub_match<_Bi_iter>& __lhs, + const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __rhs) + { return __lhs.str() == __rhs; } + + /** + * @brief Tests the inequivalence of a regular expression submatch and a + * string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator!=(const sub_match<_Bi_iter>& __lhs, + const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __rhs) + { return __lhs.str() != __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs precedes @a rhs, false otherwise. + */ + template + inline bool + operator<(const sub_match<_Bi_iter>& __lhs, + const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __rhs) + { return __lhs.str() < __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs succeeds @a rhs, false otherwise. + */ + template + inline bool + operator>(const sub_match<_Bi_iter>& __lhs, + const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __rhs) + { return __lhs.str() > __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs does not preceed @a rhs, false otherwise. + */ + template + inline bool + operator>=(const sub_match<_Bi_iter>& __lhs, + const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __rhs) + { return __lhs.str() >= __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs does not succeed @a rhs, false otherwise. + */ + template + inline bool + operator<=(const sub_match<_Bi_iter>& __lhs, + const basic_string< + typename iterator_traits<_Bi_iter>::value_type, + _Ch_traits, _Ch_alloc>& __rhs) + { return __lhs.str() <= __rhs; } + + /** + * @brief Tests the equivalence of a C string and a regular expression + * submatch. + * @param lhs A C string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs is equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs == __rhs.str(); } + + /** + * @brief Tests the inequivalence of an iterator value and a regular + * expression submatch. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs != __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs precedes @a rhs, false otherwise. + */ + template + inline bool + operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs < __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs succeeds @a rhs, false otherwise. + */ + template + inline bool + operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs > __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs does not preceed @a rhs, false otherwise. + */ + template + inline bool + operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs >= __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs does not succeed @a rhs, false otherwise. + */ + template + inline bool + operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs <= __rhs.str(); } + + /** + * @brief Tests the equivalence of a regular expression submatch and a + * string. + * @param lhs A regular expression submatch. + * @param rhs A pointer to a string? + * @returns true if @a lhs is equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator==(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const* __rhs) + { return __lhs.str() == __rhs; } + + /** + * @brief Tests the inequivalence of a regular expression submatch and a + * string. + * @param lhs A regular expression submatch. + * @param rhs A pointer to a string. + * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator!=(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const* __rhs) + { return __lhs.str() != __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs precedes @a rhs, false otherwise. + */ + template + inline bool + operator<(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const* __rhs) + { return __lhs.str() < __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs succeeds @a rhs, false otherwise. + */ + template + inline bool + operator>(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const* __rhs) + { return __lhs.str() > __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs does not precede @a rhs, false otherwise. + */ + template + inline bool + operator>=(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const* __rhs) + { return __lhs.str() >= __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A string. + * @returns true if @a lhs does not succeed @a rhs, false otherwise. + */ + template + inline bool + operator<=(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const* __rhs) + { return __lhs.str() <= __rhs; } + + /** + * @brief Tests the equivalence of a string and a regular expression + * submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs is equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs == __rhs.str(); } + + /** + * @brief Tests the inequivalence of a string and a regular expression + * submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs != __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs precedes @a rhs, false otherwise. + */ + template + inline bool + operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs < __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs succeeds @a rhs, false otherwise. + */ + template + inline bool + operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs > __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs does not preceed @a rhs, false otherwise. + */ + template + inline bool + operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs >= __rhs.str(); } + + /** + * @brief Tests the ordering of a string and a regular expression submatch. + * @param lhs A string. + * @param rhs A regular expression submatch. + * @returns true if @a lhs does not succeed @a rhs, false otherwise. + */ + template + inline bool + operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, + const sub_match<_Bi_iter>& __rhs) + { return __lhs <= __rhs.str(); } + + /** + * @brief Tests the equivalence of a regular expression submatch and a + * string. + * @param lhs A regular expression submatch. + * @param rhs A const string reference. + * @returns true if @a lhs is equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator==(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const& __rhs) + { return __lhs.str() == __rhs; } + + /** + * @brief Tests the inequivalence of a regular expression submatch and a + * string. + * @param lhs A regular expression submatch. + * @param rhs A const string reference. + * @returns true if @a lhs is not equivalent to @a rhs, false otherwise. + */ + template + inline bool + operator!=(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const& __rhs) + { return __lhs.str() != __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A const string reference. + * @returns true if @a lhs preceeds @a rhs, false otherwise. + */ + template + inline bool + operator<(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const& __rhs) + { return __lhs.str() < __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A const string reference. + * @returns true if @a lhs succeeds @a rhs, false otherwise. + */ + template + inline bool + operator>(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const& __rhs) + { return __lhs.str() > __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A const string reference. + * @returns true if @a lhs does not preceed @a rhs, false otherwise. + */ + template + inline bool + operator>=(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const& __rhs) + { return __lhs.str() >= __rhs; } + + /** + * @brief Tests the ordering of a regular expression submatch and a string. + * @param lhs A regular expression submatch. + * @param rhs A const string reference. + * @returns true if @a lhs does not succeed @a rhs, false otherwise. + */ + template + inline bool + operator<=(const sub_match<_Bi_iter>& __lhs, + typename iterator_traits<_Bi_iter>::value_type const& __rhs) + { return __lhs.str() <= __rhs; } + + /** + * @brief Inserts a matched string into an output stream. + * + * @param os The output stream. + * @param m A submatch string. + * + * @returns the output stream with the submatch string inserted. + */ + template + inline + basic_ostream<_Ch_type, _Ch_traits>& + operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os, + const sub_match<_Bi_iter>& __m) + { return __os << __m.str(); } + + // [7.10] Class template match_results + /** + * A collection of character sequences representing the result of a regular + * expression match. Storage for the collection is allocated and freed as + * necessary by the member functions of class template match_results. + * + * This class satisfies the Sequence requirements, with the exception that + * only the operations defined for a const-qualified Sequence are supported. + * + * The sub_match object stored at index 0 represents sub-expression 0, i.e. + * the whole match. In this case the sub_match member matched is always true. + * The sub_match object stored at index n denotes what matched the marked + * sub-expression n within the matched expression. If the sub-expression n + * participated in a regular expression match then the sub_match member + * matched evaluates to true, and members first and second denote the range + * of characters [first, second) which formed that match. Otherwise matched + * is false, and members first and second point to the end of the sequence + * that was searched. + */ + template > > + class match_results + : private std::vector, _Allocator> + { + private: + typedef std::vector, _Allocator> + _Base_type; + + public: + typedef sub_match<_Bi_iter> value_type; + typedef typename _Allocator::const_reference const_reference; + typedef const_reference reference; + typedef typename _Base_type::const_iterator const_iterator; + typedef const_iterator iterator; + typedef typename iterator_traits<_Bi_iter>::difference_type + difference_type; + typedef typename _Allocator::size_type size_type; + typedef _Allocator allocator_type; + typedef typename iterator_traits<_Bi_iter>::value_type char_type; + typedef basic_string string_type; + + public: + // [7.10.1] construct/copy/destroy + /** + * @brief Constructs a default match_results container. + */ + explicit + match_results(const _Allocator& __a = _Allocator()) + : _Base_type(__a), _M_matched(false) + { } + + /** + * @brief Copy constructs a match_result. + */ + match_results(const match_results& __rhs) + : _Base_type(__rhs), _M_matched(__rhs._M_matched), + _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix) + { } + + /** + * @brief Assigns rhs to *this. + */ + match_results& + operator=(const match_results& __rhs) + { + match_results __tmp(__rhs); + this->swap(__tmp); + } + + /** + * @todo Implement this function. + */ + ~match_results() + { } + + // [7.10.2] size + /** + * @todo Document this function. + */ + size_type + size() const + { return _M_matched ? _Base_type::size() + 1 : 0; } + + /** + * @todo Implement this function. + */ + //size_type + //max_size() const; + using _Base_type::max_size; + + /** + * @todo Document this function. + */ + bool + empty() const + { return size() == 0; } + + // [7.10.3] element access + /** + * @brief Gets the length of the indicated submatch. + * @param sub indicates the submatch. + */ + difference_type + length(size_type __sub = 0) const + { return _M_matched ? this->str(__sub).length() : 0; } + + /** + * @todo Document this function. + */ + difference_type + position(size_type __sub = 0) const + { + return _M_matched ? std::distance(this->prefix().first, + (*this)[__sub].first) : 0; + } + + /** + * @todo Document this function. + */ + string_type + str(size_type __sub = 0) const + { return _M_matched ? (*this)[__sub].str() : string_type(); } + + /** + * @todo Document this function. + */ + const_reference + operator[](size_type __n) const + { return _Base_type::operator[](__n); } + + /** + * @todo Document this function. + */ + const_reference + prefix() const + { return _M_prefix; } + + /** + * @todo Document this function. + */ + const_reference + suffix() const + { return _M_suffix; } + + /** + * @todo Document this function. + */ + const_iterator + begin() const + { return _Base_type::begin(); } + + /** + * @todo Document this function. + */ + const_iterator + end() const + { return _Base_type::end(); } + + // [7.10.4] format + /** + * @todo Implement this function. + */ + template + _Out_iter + format(_Out_iter __out, const string_type& __fmt, + regex_constants::match_flag_type __flags + = regex_constants::format_default) const + { return __out; } + + /** + * @todo Implement this function. + */ + string_type + format(const string_type& __fmt, + regex_constants::match_flag_type __flags + = regex_constants::format_default) const; + + // [7.10.5] allocator + /** + * @todo Document this function. + */ + //allocator_type + //get_allocator() const; + using _Base_type::get_allocator; + + // [7.10.6] swap + /** + * @todo Document this function. + */ + void + swap(match_results& __that) + { + _Base_type::swap(__that); + std::swap(_M_matched, __that._M_matched); + std::swap(_M_prefix, __that._M_prefix); + std::swap(_M_suffix, __that._M_suffix); + } + + private: + bool _M_matched; + value_type _M_prefix; + value_type _M_suffix; + }; + + typedef match_results cmatch; + typedef match_results smatch; +#ifdef _GLIBCXX_USE_WCHAR_T + typedef match_results wcmatch; + typedef match_results wsmatch; +#endif + + // match_results comparisons + /** + * @todo Implement this function. + */ + template + inline bool + operator==(const match_results<_Bi_iter, _Allocator>& __m1, + const match_results<_Bi_iter, _Allocator>& __m2); + + /** + * @todo Implement this function. + */ + template + inline bool + operator!=(const match_results<_Bi_iter, _Allocator>& __m1, + const match_results<_Bi_iter, _Allocator>& __m2); + + // [7.10.6] match_results swap + /** + * @brief Swaps two match results. + * @param lhs A match result. + * @param rhs A match result. + * + * The contents of the two match_results objects are swapped. + */ + template + inline void + swap(match_results<_Bi_iter, _Allocator>& __lhs, + match_results<_Bi_iter, _Allocator>& __rhs) + { return __lhs.swap(__rhs); } + + // [7.11.2] Function template regex_match + /** + * @brief Determines if there is a match between the regular expression @p e + * and all of the character sequence [first, last). + * + * @param first Beginning of the character sequence to match. + * @param last One-past-the-end of the character sequence to match. + * @param m The match results. + * @param re The regular expression. + * @param flags Controls how the regular expression is matched. + * + * @retval true A match exists. + * @retval false Otherwise. + * + * @todo Implement this function. + */ + template + bool + regex_match(_Bi_iter __first, _Bi_iter __last, + match_results<_Bi_iter, _Allocator>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { return false; } + + /** + * @brief Indicates if there is a match between the regular expression @p e + * and all of the character sequence [first, last). + * + * @param first Beginning of the character sequence to match. + * @param last One-past-the-end of the character sequence to match. + * @param re The regular expression. + * @param flags Controls how the regular expression is matched. + * + * @retval true A match exists. + * @retval false Otherwise. + */ + template + bool + regex_match(_Bi_iter __first, _Bi_iter __last, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { + match_results<_Bi_iter> __what; + return regex_match(__first, __last, __what, __re, __flags); + } + + /** + * @brief Determines if there is a match between the regular expression @p e + * and a C-style null-terminated string. + * + * @param s The C-style null-terminated string to match. + * @param m The match results. + * @param re The regular expression. + * @param f Controls how the regular expression is matched. + * + * @retval true A match exists. + * @retval false Otherwise. + */ + template + inline bool + regex_match(const _Ch_type* __s, + match_results& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __f + = regex_constants::match_default) + { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); } + + /** + * @brief Determines if there is a match between the regular expression @p e + * and a string. + * + * @param s The string to match. + * @param m The match results. + * @param re The regular expression. + * @param flags Controls how the regular expression is matched. + * + * @retval true A match exists. + * @retval false Otherwise. + */ + template + inline bool + regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, + match_results::const_iterator, _Allocator>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); } + + /** + * @brief Indicates if there is a match between the regular expression @p e + * and a C-style null-terminated string. + * + * @param s The C-style null-terminated string to match. + * @param re The regular expression. + * @param f Controls how the regular expression is matched. + * + * @retval true A match exists. + * @retval false Otherwise. + */ + template + inline bool + regex_match(const _Ch_type* __s, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __f + = regex_constants::match_default) + { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); } + + /** + * @brief Indicates if there is a match between the regular expression @p e + * and a string. + * + * @param s [IN] The string to match. + * @param re [IN] The regular expression. + * @param flags [IN] Controls how the regular expression is matched. + * + * @retval true A match exists. + * @retval false Otherwise. + */ + template + inline bool + regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { return regex_match(__s.begin(), __s.end(), __re, __flags); } + + // [7.11.3] Function template regex_search + /** + * Searches for a regular expression within a range. + * @param first [IN] The start of the string to search. + * @param last [IN] One-past-the-end of the string to search. + * @param m [OUT] The match results. + * @param re [IN] The regular expression to search for. + * @param flags [IN] Search policy flags. + * @retval true A match was found within the string. + * @retval false No match was found within the string, the content of %m is + * undefined. + * @todo Implement this function. + */ + template + inline bool + regex_search(_Bi_iter __first, _Bi_iter __last, + match_results<_Bi_iter, _Allocator>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { return false; } + + /** + * Searches for a regular expression within a range. + * @param first [IN] The start of the string to search. + * @param last [IN] One-past-the-end of the string to search. + * @param re [IN] The regular expression to search for. + * @param flags [IN] Search policy flags. + * @retval true A match was found within the string. + * @retval false No match was found within the string. + * @todo Document me. + */ + template + inline bool + regex_search(_Bi_iter __first, _Bi_iter __last, + const basic_regex<_Ch_type, _Rx_traits>& __re, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { + match_results<_Bi_iter> __what; + return regex_search(__first, __last, __what, __re, __flags); + } + + /** + * @brief Searches for a regular expression within a C-string. + * @param s [IN] A C-string to search for the regex. + * @param m [OUT] The set of regex mnatches. + * @param e [IN] The regex to search for in @p s. + * @param f [IN] The search flags. + * @retval true A match was found within the string. + * @retval false No match was found within the string, the content of %m is + * undefined. + * @todo Document me. + */ + template + inline bool + regex_search(const _Ch_type* __s, + match_results& __m, + const basic_regex<_Ch_type, _Rx_traits>& __e, + regex_constants::match_flag_type __f + = regex_constants::match_default) + { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); } + + /** + * @brief Searches for a regular expression within a C-string. + * @param s [IN] The C-string to search. + * @param e [IN] The regular expressioon to search for. + * @param f [IN] Search policy flags. + * @retval true A match was found within the string. + * @retval false No match was found within the string. + * @todo Document me. + */ + template + inline bool + regex_search(const _Ch_type* __s, + const basic_regex<_Ch_type, _Rx_traits>& __e, + regex_constants::match_flag_type __f + = regex_constants::match_default) + { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); } + + /** + * @brief Searches for a regular expression within a string. + * @param s [IN] The string to search. + * @param e [IN] The regular expressioon to search for. + * @param flags [IN] Search policy flags. + * @retval true A match was found within the string. + * @retval false No match was found within the string. + * @todo Document me. + */ + template + inline bool + regex_search(const basic_string<_Ch_type, _Ch_traits, + _String_allocator>& __s, + const basic_regex<_Ch_type, _Rx_traits>& __e, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { return regex_search(__s.begin(), __s.end(), __e, __flags); } + + /** + * @brief Searches for a regular expression within a string. + * @param s [IN] A C++ string to search for the regex. + * @param m [OUT] The set of regex mnatches. + * @param e [IN] The regex to search for in @p s. + * @param f [IN] The search flags. + * @retval true A match was found within the string. + * @retval false No match was found within the string, the content of %m is + * undefined. + */ + template + inline bool + regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, + match_results::const_iterator, _Allocator>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __e, + regex_constants::match_flag_type __f + = regex_constants::match_default) + { return regex_search(__s.begin(), __s.end(), __m, __e, __f); } + + // [7.11.4] Function template regex_replace + /** + * @todo Implement this function. + * @todo Document this function. + */ + template + inline _Out_iter + regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, + const basic_regex<_Ch_type, _Rx_traits>& __e, + const basic_string<_Ch_type>& __fmt, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { return __out; } + + /** + * @todo Document me. + */ + template + inline basic_string<_Ch_type> + regex_replace(const basic_string<_Ch_type>& __s, + const basic_regex<_Ch_type, _Rx_traits>& __e, + const basic_string<_Ch_type>& __fmt, + regex_constants::match_flag_type __flags + = regex_constants::match_default) + { + std::string __result; + regex_replace(std::back_inserter(__result), + __s.begin(), __s.end(), __e, __fmt, __flags); + return __result; + } + + // [7.12.1] Class template regex_iterator + /** + * An iterator adaptor that will provide repeated calls of regex_search over + * a range until no more matches remain. + */ + template::value_type, + typename _Rx_traits = regex_traits<_Ch_type> > + class regex_iterator + { + public: + typedef basic_regex<_Ch_type, _Rx_traits> regex_type; + typedef match_results<_Bi_iter> value_type; + typedef std::ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef std::forward_iterator_tag iterator_category; + + public: + /** + * @brief Provides a singular iterator, useful for indicating + * one-past-the-end of a range. + * @todo Implement this function. + * @todo Document this function. + */ + regex_iterator(); + + /** + * Constructs a %regex_iterator... + * @param a [IN] The start of a text range to search. + * @param b [IN] One-past-the-end of the text range to search. + * @param re [IN] The regular expression to match. + * @param m [IN] Policy flags for match rules. + * @todo Implement this function. + * @todo Document this function. + */ + regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, + regex_constants::match_flag_type __m + = regex_constants::match_default); + + /** + * Copy constructs a %regex_iterator. + * @todo Implement this function. + * @todo Document this function. + */ + regex_iterator(const regex_iterator& __rhs); + + /** + * @todo Implement this function. + * @todo Document this function. + */ + regex_iterator& + operator=(const regex_iterator& __rhs); + + /** + * @todo Implement this function. + * @todo Document this function. + */ + bool + operator==(const regex_iterator& __rhs); + + /** + * @todo Implement this function. + * @todo Document this function. + */ + bool + operator!=(const regex_iterator& __rhs); + + /** + * @todo Implement this function. + * @todo Document this function. + */ + const value_type& + operator*(); + + /** + * @todo Implement this function. + * @todo Document this function. + */ + const value_type* + operator->(); + + /** + * @todo Implement this function. + * @todo Document this function. + */ + regex_iterator& + operator++(); + + /** + * @todo Implement this function. + * @todo Document this function. + */ + regex_iterator + operator++(int); + + private: + // these members are shown for exposition only: + _Bi_iter begin; + _Bi_iter end; + const regex_type* pregex; + regex_constants::match_flag_type flags; + match_results<_Bi_iter> match; + }; + + typedef regex_iterator cregex_iterator; + typedef regex_iterator sregex_iterator; +#ifdef _GLIBCXX_USE_WCHAR_T + typedef regex_iterator wcregex_iterator; + typedef regex_iterator wsregex_iterator; +#endif + + // [7.12.2] Class template regex_token_iterator + /** + * Iterates over submatches in a range (or "splits" a text string). + * + * The purpose of this iterator is to enumerate all, or all specified, + * matches of a regular expression within a text range. The dereferenced + * value of an iterator of this class is a std::tr1::sub_match object. + */ + template::value_type, + typename _Rx_traits = regex_traits<_Ch_type> > + class regex_token_iterator + { + public: + typedef basic_regex<_Ch_type, _Rx_traits> regex_type; + typedef sub_match<_Bi_iter> value_type; + typedef std::ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + typedef std::forward_iterator_tag iterator_category; + + public: + /** + * @brief Default constructs a %regex_token_iterator. + * @todo Implement this function. + * + * A default-constructed %regex_token_iterator is a singular iterator + * that will compare equal to the one-past-the-end value for any + * iterator of the same type. + */ + regex_token_iterator(); + + /** + * Constrcts a %regex_token_iterator... + * @param a [IN] The start of the text to search. + * @param b [IN] One-past-the-eend of the text to search. + * @param re [IN] The regular expression to search for. + * @param submatch [IN] Which submatch to return. There are some + * special values for thsi parameter: + * - -1 each enumerated subexpression does NOT + * match the regular expression (aka field + * splitting) + * - 0 the entire string matching the + * subexpression is returned for each match + * within the text. + * - >0 enumerates only the indicated + * subexpression from a match within the text. + * @param m [IN] Policy flags for match rules. + * + * @todo Implement this function. + * @todo Document this function. + */ + regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, + int __submatch = 0, + regex_constants::match_flag_type __m + = regex_constants::match_default); + + /** + * Constrcts a %regex_token_iterator... + * @param a [IN] The start of the text to search. + * @param b [IN] One-past-the-eend of the text to search. + * @param re [IN] The regular expression to search for. + * @param submatches [IN] A list of subexpressions to return for each + * regular expression match within the text. + * @param m [IN] Policy flags for match rules. + * + * @todo Implement this function. + * @todo Document this function. + */ + regex_token_iterator(_Bi_iter __a, _Bi_iter __b, + const regex_type& __re, + const std::vector& __submatches, + regex_constants::match_flag_type __m + = regex_constants::match_default); + + /** + * Constrcts a %regex_token_iterator... + * @param a [IN] The start of the text to search. + * @param b [IN] One-past-the-eend of the text to search. + * @param re [IN] The regular expression to search for. + * @param submatches [IN] A list of subexpressions to return for each + * regular expression match within the text. + * @param m [IN] Policy flags for match rules. + + * @todo Implement this function. + * @todo Document this function. + */ + template + regex_token_iterator(_Bi_iter __a, _Bi_iter __b, + const regex_type& __re, + const int (&__submatches)[_Nm], + regex_constants::match_flag_type __m + = regex_constants::match_default); + + /** + * @brief Copy constructs a %regex_token_iterator. + * @param rhs [IN] A %regex_token_iterator to copy. + * @todo Implement this function. + */ + regex_token_iterator(const regex_token_iterator& __rhs); + + /** + * @brief Assigns a %regex_token_iterator to another. + * @param rhs [IN] A %regex_token_iterator to copy. + * @todo Implement this function. + */ + regex_token_iterator& + operator=(const regex_token_iterator& __rhs); + + /** + * @brief Compares a %regex_token_iterator to another for equality. + * @todo Implement this function. + */ + bool + operator==(const regex_token_iterator& __rhs); + + /** + * @brief Compares a %regex_token_iterator to another for inequality. + * @todo Implement this function. + */ + bool + operator!=(const regex_token_iterator& __rhs); + + /** + * @brief Dereferences a %regex_token_iterator. + * @todo Implement this function. + */ + const value_type& + operator*(); + + /** + * @brief Selects a %regex_token_iterator member. + * @todo Implement this function. + */ + const value_type* + operator->(); + + /** + * @brief Increments a %regex_token_iterator. + * @todo Implement this function. + */ + regex_token_iterator& + operator++(); + + /** + * @brief Postincrements a %regex_token_iterator. + * @todo Implement this function. + */ + regex_token_iterator + operator++(int); + + private: // data members for exposition only: + typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator; + + position_iterator __position; + const value_type* __result; + value_type __suffix; + std::size_t __n; + std::vector __subs; + }; + + typedef regex_token_iterator cregex_token_iterator; + typedef regex_token_iterator sregex_token_iterator; +#ifdef _GLIBCXX_USE_WCHAR_T + typedef regex_token_iterator wcregex_token_iterator; + typedef regex_token_iterator wsregex_token_iterator; +#endif + + /** @} */ // group tr1_regex + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/tuple b/libstdc++-v3/include/tr1_impl/tuple new file mode 100644 index 0000000..52017d6 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/tuple @@ -0,0 +1,430 @@ +// class template tuple -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/tuple + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. +*/ + +// Chris Jefferson +// Variadic Templates support by Douglas Gregor + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + template + class reference_wrapper; + + // Adds a const reference to a non-reference type. + template + struct __add_c_ref + { typedef const _Tp& type; }; + + template + struct __add_c_ref<_Tp&> + { typedef _Tp& type; }; + + // Adds a reference to a non-reference type. + template + struct __add_ref + { typedef _Tp& type; }; + + template + struct __add_ref<_Tp&> + { typedef _Tp& type; }; + + /** + * @if maint + * Contains the actual implementation of the @c tuple template, stored + * as a recursive inheritance hierarchy from the first element (most + * derived class) to the last (least derived class). The @c Idx + * parameter gives the 0-based index of the element stored at this + * point in the hierarchy; we use it to implement a constant-time + * get() operation. + * @endif + */ + template + struct _Tuple_impl; + + /** + * @if maint + * Zero-element tuple implementation. This is the basis case for the + * inheritance recursion. + * @endif maint + */ + template + struct _Tuple_impl<_Idx> { }; + + /** + * @if maint + * Recursive tuple implementation. Here we store the @c Head element + * and derive from a @c Tuple_impl containing the remaining elements + * (which contains the @c Tail). + * @endif + */ + template + struct _Tuple_impl<_Idx, _Head, _Tail...> + : public _Tuple_impl<_Idx + 1, _Tail...> + { + typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited; + + _Head _M_head; + + _Inherited& _M_tail() { return *this; } + const _Inherited& _M_tail() const { return *this; } + + _Tuple_impl() : _Inherited(), _M_head() { } + + explicit + _Tuple_impl(typename __add_c_ref<_Head>::type __head, + typename __add_c_ref<_Tail>::type... __tail) + : _Inherited(__tail...), _M_head(__head) { } + + template + _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in) + : _Inherited(__in._M_tail()), _M_head(__in._M_head) { } + + _Tuple_impl(const _Tuple_impl& __in) + : _Inherited(__in._M_tail()), _M_head(__in._M_head) { } + + template + _Tuple_impl& + operator=(const _Tuple_impl<_Idx, _UElements...>& __in) + { + _M_head = __in._M_head; + _M_tail() = __in._M_tail(); + return *this; + } + + _Tuple_impl& + operator=(const _Tuple_impl& __in) + { + _M_head = __in._M_head; + _M_tail() = __in._M_tail(); + return *this; + } + }; + + template + class tuple : public _Tuple_impl<0, _Elements...> + { + typedef _Tuple_impl<0, _Elements...> _Inherited; + + public: + tuple() : _Inherited() { } + + explicit + tuple(typename __add_c_ref<_Elements>::type... __elements) + : _Inherited(__elements...) { } + + template + tuple(const tuple<_UElements...>& __in) + : _Inherited(__in) { } + + tuple(const tuple& __in) + : _Inherited(__in) { } + + template + tuple& + operator=(const tuple<_UElements...>& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + + tuple& + operator=(const tuple& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + }; + + template<> class tuple<> { }; + + // 2-element tuple, with construction and assignment from a pair. + template + class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2> + { + typedef _Tuple_impl<0, _T1, _T2> _Inherited; + + public: + tuple() : _Inherited() { } + + explicit + tuple(typename __add_c_ref<_T1>::type __a1, + typename __add_c_ref<_T2>::type __a2) + : _Inherited(__a1, __a2) { } + + template + tuple(const tuple<_U1, _U2>& __in) + : _Inherited(__in) { } + + tuple(const tuple& __in) + : _Inherited(__in) { } + + template + tuple(const pair<_U1, _U2>& __in) + : _Inherited(_Tuple_impl<0, + typename __add_c_ref<_U1>::type, + typename __add_c_ref<_U2>::type>(__in.first, + __in.second)) + { } + + template + tuple& + operator=(const tuple<_U1, _U2>& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + + tuple& + operator=(const tuple& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + + template + tuple& + operator=(const pair<_U1, _U2>& __in) + { + this->_M_head = __in.first; + this->_M_tail()._M_head = __in.second; + return *this; + } + }; + + + /// Gives the type of the ith element of a given tuple type. + template + struct tuple_element; + + /** + * @if maint + * Recursive case for tuple_element: strip off the first element in + * the tuple and retrieve the (i-1)th element of the remaining tuple. + * @endif + */ + template + struct tuple_element<__i, tuple<_Head, _Tail...> > + : tuple_element<__i - 1, tuple<_Tail...> > { }; + + /** + * @if maint + * Basis case for tuple_element: The first element is the one we're seeking. + * @endif + */ + template + struct tuple_element<0, tuple<_Head, _Tail...> > + { + typedef _Head type; + }; + + /// Finds the size of a given tuple type. + template + struct tuple_size; + + /// @brief class tuple_size + template + struct tuple_size > + { + static const int value = sizeof...(_Elements); + }; + + template + const int tuple_size >::value; + + template + inline typename __add_ref<_Head>::type + __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) + { + return __t._M_head; + } + + template + inline typename __add_c_ref<_Head>::type + __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) + { + return __t._M_head; + } + + // Return a reference (const reference) to the ith element of a tuple. + // Any const or non-const ref elements are returned with their original type. + template + inline typename __add_ref< + typename tuple_element<__i, tuple<_Elements...> >::type + >::type + get(tuple<_Elements...>& __t) + { + return __get_helper<__i>(__t); + } + + template + inline typename __add_c_ref< + typename tuple_element<__i, tuple<_Elements...> >::type + >::type + get(const tuple<_Elements...>& __t) + { + return __get_helper<__i>(__t); + } + + // This class helps construct the various comparison operations on tuples + template + struct __tuple_compare; + + template + struct __tuple_compare<0, __i, __j, _Tp, _Up> + { + static bool __eq(const _Tp& __t, const _Up& __u) + { + return (get<__i>(__t) == get<__i>(__u) && + __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u)); + } + + static bool __less(const _Tp& __t, const _Up& __u) + { + return ((get<__i>(__t) < get<__i>(__u)) + || !(get<__i>(__u) < get<__i>(__t)) && + __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u)); + } + }; + + template + struct __tuple_compare<0, __i, __i, _Tp, _Up> + { + static bool __eq(const _Tp&, const _Up&) + { return true; } + + static bool __less(const _Tp&, const _Up&) + { return false; } + }; + + template + bool + operator==(const tuple<_TElements...>& __t, + const tuple<_UElements...>& __u) + { + typedef tuple<_TElements...> _Tp; + typedef tuple<_UElements...> _Up; + return (__tuple_compare::value - tuple_size<_Tp>::value, + 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u)); + } + + template + bool + operator<(const tuple<_TElements...>& __t, + const tuple<_UElements...>& __u) + { + typedef tuple<_TElements...> _Tp; + typedef tuple<_UElements...> _Up; + return (__tuple_compare::value - tuple_size<_Tp>::value, + 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u)); + } + + template + bool + operator!=(const tuple<_TElements...>& __t, + const tuple<_UElements...>& __u) + { return !(__t == __u); } + + template + bool + operator>(const tuple<_TElements...>& __t, + const tuple<_UElements...>& __u) + { return __u < __t; } + + template + bool + operator<=(const tuple<_TElements...>& __t, + const tuple<_UElements...>& __u) + { return !(__u < __t); } + + template + bool + operator>=(const tuple<_TElements...>& __t, + const tuple<_UElements...>& __u) + { return !(__t < __u); } + + // Helper which adds a reference to a type when given a reference_wrapper + template + struct __strip_reference_wrapper + { + typedef _Tp __type; + }; + + template + struct __strip_reference_wrapper > + { + typedef _Tp& __type; + }; + + template + struct __strip_reference_wrapper > + { + typedef _Tp& __type; + }; + + template + inline tuple::__type...> + make_tuple(_Elements... __args) + { + typedef tuple::__type...> + __result_type; + return __result_type(__args...); + } + + template + inline tuple<_Elements&...> + tie(_Elements&... __args) + { + return tuple<_Elements&...>(__args...); + } + + // A class (and instance) which can be used in 'tie' when an element + // of a tuple is not required + struct _Swallow_assign + { + template + _Swallow_assign& + operator=(const _Tp&) + { return *this; } + }; + + // TODO: Put this in some kind of shared file. + namespace + { + _Swallow_assign ignore; + }; // anonymous namespace + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/type_traits b/libstdc++-v3/include/tr1_impl/type_traits new file mode 100644 index 0000000..9fa77ca --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/type_traits @@ -0,0 +1,489 @@ +// TR1 type_traits -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/type_traits +* This is an internal header file, included by other library headers. +* You should not attempt to use it directly. +*/ + +#include + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // For use in __is_convertible_simple. + struct __sfinae_types + { + typedef char __one; + typedef struct { char __arr[2]; } __two; + }; + +#define _DEFINE_SPEC_BODY(_Value) \ + : public integral_constant { }; + +#define _DEFINE_SPEC_0_HELPER(_Spec, _Value) \ + template<> \ + struct _Spec \ + _DEFINE_SPEC_BODY(_Value) + +#define _DEFINE_SPEC_1_HELPER(_Spec, _Value) \ + template \ + struct _Spec \ + _DEFINE_SPEC_BODY(_Value) + +#define _DEFINE_SPEC_2_HELPER(_Spec, _Value) \ + template \ + struct _Spec \ + _DEFINE_SPEC_BODY(_Value) + +#define _DEFINE_SPEC(_Order, _Trait, _Type, _Value) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type>, _Value) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const>, _Value) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type volatile>, _Value) \ + _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const volatile>, _Value) + + /// @brief helper classes [4.3]. + template + struct integral_constant + { + static const _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant<_Tp, __v> type; + }; + typedef integral_constant true_type; + typedef integral_constant false_type; + + template + const _Tp integral_constant<_Tp, __v>::value; + + /// @brief primary type categories [4.5.1]. + template + struct is_void + : public false_type { }; + _DEFINE_SPEC(0, is_void, void, true) + + template + struct is_integral + : public false_type { }; + _DEFINE_SPEC(0, is_integral, bool, true) + _DEFINE_SPEC(0, is_integral, char, true) + _DEFINE_SPEC(0, is_integral, signed char, true) + _DEFINE_SPEC(0, is_integral, unsigned char, true) +#ifdef _GLIBCXX_USE_WCHAR_T + _DEFINE_SPEC(0, is_integral, wchar_t, true) +#endif + _DEFINE_SPEC(0, is_integral, short, true) + _DEFINE_SPEC(0, is_integral, unsigned short, true) + _DEFINE_SPEC(0, is_integral, int, true) + _DEFINE_SPEC(0, is_integral, unsigned int, true) + _DEFINE_SPEC(0, is_integral, long, true) + _DEFINE_SPEC(0, is_integral, unsigned long, true) + _DEFINE_SPEC(0, is_integral, long long, true) + _DEFINE_SPEC(0, is_integral, unsigned long long, true) + + template + struct is_floating_point + : public false_type { }; + _DEFINE_SPEC(0, is_floating_point, float, true) + _DEFINE_SPEC(0, is_floating_point, double, true) + _DEFINE_SPEC(0, is_floating_point, long double, true) + + template + struct is_array + : public false_type { }; + + template + struct is_array<_Tp[_Size]> + : public true_type { }; + + template + struct is_array<_Tp[]> + : public true_type { }; + + template + struct is_pointer + : public false_type { }; + _DEFINE_SPEC(1, is_pointer, _Tp*, true) + + template + struct is_reference + : public false_type { }; + + template + struct is_reference<_Tp&> + : public true_type { }; + + template + struct is_member_object_pointer + : public false_type { }; + _DEFINE_SPEC(2, is_member_object_pointer, _Tp _Cp::*, + !is_function<_Tp>::value) + + template + struct is_member_function_pointer + : public false_type { }; + _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*, + is_function<_Tp>::value) + + template + struct is_enum + : public integral_constant + { }; + + template + struct is_union + : public integral_constant + { }; + + template + struct is_class + : public integral_constant + { }; + + template + struct __is_function_helper + : public false_type { }; + + template + struct __is_function_helper<_Res(_ArgTypes...)> + : public true_type { }; + + template + struct __is_function_helper<_Res(_ArgTypes......)> + : public true_type { }; + + template + struct is_function + : public integral_constant::type>::value)> + { }; + + /// @brief composite type traits [4.5.2]. + template + struct is_arithmetic + : public integral_constant::value + || is_floating_point<_Tp>::value)> + { }; + + template + struct is_fundamental + : public integral_constant::value + || is_void<_Tp>::value)> + { }; + + template + struct is_object + : public integral_constant::value + || is_reference<_Tp>::value + || is_void<_Tp>::value)> + { }; + + template + struct is_scalar + : public integral_constant::value + || is_enum<_Tp>::value + || is_pointer<_Tp>::value + || is_member_pointer<_Tp>::value)> + { }; + + template + struct is_compound + : public integral_constant::value> { }; + + template + struct is_member_pointer + : public integral_constant::value + || is_member_function_pointer<_Tp>::value)> + { }; + + /// @brief type properties [4.5.3]. + template + struct is_const + : public false_type { }; + + template + struct is_const<_Tp const> + : public true_type { }; + + template + struct is_volatile + : public false_type { }; + + template + struct is_volatile<_Tp volatile> + : public true_type { }; + + template + struct is_empty + : public integral_constant + { }; + + template + struct is_polymorphic + : public integral_constant + { }; + + template + struct is_abstract + : public integral_constant + { }; + + template + struct has_virtual_destructor + : public integral_constant + { }; + + template + struct alignment_of + : public integral_constant { }; + + template + struct rank + : public integral_constant { }; + + template + struct rank<_Tp[_Size]> + : public integral_constant::value> { }; + + template + struct rank<_Tp[]> + : public integral_constant::value> { }; + + template + struct extent + : public integral_constant { }; + + template + struct extent<_Tp[_Size], _Uint> + : public integral_constant::value> + { }; + + template + struct extent<_Tp[], _Uint> + : public integral_constant::value> + { }; + + /// @brief relationships between types [4.6]. + template + struct is_same + : public false_type { }; + + template + struct is_same<_Tp, _Tp> + : public true_type { }; + + /// @brief const-volatile modifications [4.7.1]. + template + struct remove_const + { typedef _Tp type; }; + + template + struct remove_const<_Tp const> + { typedef _Tp type; }; + + template + struct remove_volatile + { typedef _Tp type; }; + + template + struct remove_volatile<_Tp volatile> + { typedef _Tp type; }; + + template + struct remove_cv + { + typedef typename + remove_const::type>::type type; + }; + + template + struct add_const + { typedef _Tp const type; }; + + template + struct add_volatile + { typedef _Tp volatile type; }; + + template + struct add_cv + { + typedef typename + add_const::type>::type type; + }; + + /// @brief reference modifications [4.7.2]. + template + struct remove_reference + { typedef _Tp type; }; + + template + struct remove_reference<_Tp&> + { typedef _Tp type; }; + + // NB: Careful with reference to void. + template::value + || is_reference<_Tp>::value)> + struct __add_reference_helper + { typedef _Tp& type; }; + + template + struct __add_reference_helper<_Tp, true> + { typedef _Tp type; }; + + template + struct add_reference + : public __add_reference_helper<_Tp> + { }; + + /// @brief array modifications [4.7.3]. + template + struct remove_extent + { typedef _Tp type; }; + + template + struct remove_extent<_Tp[_Size]> + { typedef _Tp type; }; + + template + struct remove_extent<_Tp[]> + { typedef _Tp type; }; + + template + struct remove_all_extents + { typedef _Tp type; }; + + template + struct remove_all_extents<_Tp[_Size]> + { typedef typename remove_all_extents<_Tp>::type type; }; + + template + struct remove_all_extents<_Tp[]> + { typedef typename remove_all_extents<_Tp>::type type; }; + + /// @brief pointer modifications [4.7.4]. +#undef _DEFINE_SPEC_BODY +#define _DEFINE_SPEC_BODY(_Value) \ + { typedef _Tp type; }; + + template + struct remove_pointer + { typedef _Tp type; }; + _DEFINE_SPEC(1, remove_pointer, _Tp*, false) + + template + struct add_pointer + { typedef typename remove_reference<_Tp>::type* type; }; + + /// @brief other transformations [4.8]. + + // Due to c++/19163 and c++/17743, for the time being we cannot use + // the correct, neat implementation :-( + // + // template + // struct aligned_storage + // { typedef char type[_Len] __attribute__((__aligned__(_Align))); } + // + // Temporary workaround, useful for Align up to 32: + template + struct aligned_storage { }; + + template + struct aligned_storage<_Len, 1> + { + union type + { + unsigned char __data[_Len]; + char __align __attribute__((__aligned__(1))); + }; + }; + + template + struct aligned_storage<_Len, 2> + { + union type + { + unsigned char __data[_Len]; + char __align __attribute__((__aligned__(2))); + }; + }; + + template + struct aligned_storage<_Len, 4> + { + union type + { + unsigned char __data[_Len]; + char __align __attribute__((__aligned__(4))); + }; + }; + + template + struct aligned_storage<_Len, 8> + { + union type + { + unsigned char __data[_Len]; + char __align __attribute__((__aligned__(8))); + }; + }; + + template + struct aligned_storage<_Len, 16> + { + union type + { + unsigned char __data[_Len]; + char __align __attribute__((__aligned__(16))); + }; + }; + + template + struct aligned_storage<_Len, 32> + { + union type + { + unsigned char __data[_Len]; + char __align __attribute__((__aligned__(32))); + }; + }; + +#undef _DEFINE_SPEC_0_HELPER +#undef _DEFINE_SPEC_1_HELPER +#undef _DEFINE_SPEC_2_HELPER +#undef _DEFINE_SPEC +#undef _DEFINE_SPEC_BODY + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/type_traitsfwd.h b/libstdc++-v3/include/tr1_impl/type_traitsfwd.h new file mode 100644 index 0000000..1565df0 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/type_traitsfwd.h @@ -0,0 +1,178 @@ +// TR1 type_traitsfwd.h -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/type_traitsfwd.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + /// @brief helper classes [4.3]. + template + struct integral_constant; + typedef integral_constant true_type; + typedef integral_constant false_type; + + /// @brief primary type categories [4.5.1]. + template + struct is_void; + + template + struct is_integral; + + template + struct is_floating_point; + + template + struct is_array; + + template + struct is_pointer; + + template + struct is_reference; + + template + struct is_member_object_pointer; + + template + struct is_member_function_pointer; + + template + struct is_enum; + + template + struct is_union; + + template + struct is_class; + + template + struct is_function; + + /// @brief composite type traits [4.5.2]. + template + struct is_arithmetic; + + template + struct is_fundamental; + + template + struct is_object; + + template + struct is_scalar; + + template + struct is_compound; + + template + struct is_member_pointer; + + /// @brief type properties [4.5.3]. + template + struct is_const; + + template + struct is_volatile; + + template + struct is_empty; + + template + struct is_polymorphic; + + template + struct is_abstract; + + template + struct has_virtual_destructor; + + template + struct alignment_of; + + template + struct rank; + + template + struct extent; + + /// @brief relationships between types [4.6]. + template + struct is_same; + + /// @brief const-volatile modifications [4.7.1]. + template + struct remove_const; + + template + struct remove_volatile; + + template + struct remove_cv; + + template + struct add_const; + + template + struct add_volatile; + + template + struct add_cv; + + /// @brief reference modifications [4.7.2]. + template + struct remove_reference; + + template + struct add_reference; + + /// @brief array modifications [4.7.3]. + template + struct remove_extent; + + template + struct remove_all_extents; + + /// @brief pointer modifications [4.7.4]. + template + struct remove_pointer; + + template + struct add_pointer; + + /// @brief other transformations [4.8]. + template + struct aligned_storage; + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/unordered_map b/libstdc++-v3/include/tr1_impl/unordered_map new file mode 100644 index 0000000..a362296 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/unordered_map @@ -0,0 +1,229 @@ +// TR1 unordered_map -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/unordered_map + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // XXX When we get typedef templates these class definitions + // will be unnecessary. + template, + class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator >, + bool __cache_hash_code = false> + class __unordered_map + : public _Hashtable<_Key, std::pair, _Alloc, + std::_Select1st >, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, false, true> + { + typedef _Hashtable<_Key, std::pair, _Alloc, + std::_Select1st >, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, false, true> + _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + __unordered_map(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), + __eql, std::_Select1st >(), __a) + { } + + template + __unordered_map(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), + __eql, std::_Select1st >(), __a) + { } + }; + + template, + class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator >, + bool __cache_hash_code = false> + class __unordered_multimap + : public _Hashtable<_Key, std::pair, + _Alloc, + std::_Select1st >, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, false, false> + { + typedef _Hashtable<_Key, std::pair, + _Alloc, + std::_Select1st >, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, false, false> + _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + __unordered_multimap(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), + __eql, std::_Select1st >(), __a) + { } + + + template + __unordered_multimap(_InputIterator __f, _InputIterator __l, + typename _Base::size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), + __eql, std::_Select1st >(), __a) + { } + }; + + template + inline void + swap(__unordered_map<_Key, _Tp, _Hash, _Pred, + _Alloc, __cache_hash_code>& __x, + __unordered_map<_Key, _Tp, _Hash, _Pred, + _Alloc, __cache_hash_code>& __y) + { __x.swap(__y); } + + template + inline void + swap(__unordered_multimap<_Key, _Tp, _Hash, _Pred, + _Alloc, __cache_hash_code>& __x, + __unordered_multimap<_Key, _Tp, _Hash, _Pred, + _Alloc, __cache_hash_code>& __y) + { __x.swap(__y); } + + + template, + class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator > > + class unordered_map + : public __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> + { + typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + unordered_map(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { } + + template + unordered_map(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { } + }; + + template, + class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator > > + class unordered_multimap + : public __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> + { + typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + unordered_multimap(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { } + + + template + unordered_multimap(_InputIterator __f, _InputIterator __l, + typename _Base::size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { } + }; + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/unordered_set b/libstdc++-v3/include/tr1_impl/unordered_set new file mode 100644 index 0000000..2292d36 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/unordered_set @@ -0,0 +1,227 @@ +// TR1 unordered_set -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/unordered_set + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + // XXX When we get typedef templates these class definitions + // will be unnecessary. + template, + class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value>, + bool __cache_hash_code = false> + class __unordered_set + : public _Hashtable<_Value, _Value, _Alloc, + std::_Identity<_Value>, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, true, true> + { + typedef _Hashtable<_Value, _Value, _Alloc, + std::_Identity<_Value>, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, true, true> + _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + __unordered_set(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), __eql, + std::_Identity<_Value>(), __a) + { } + + template + __unordered_set(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), __eql, + std::_Identity<_Value>(), __a) + { } + }; + + template, + class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value>, + bool __cache_hash_code = false> + class __unordered_multiset + : public _Hashtable<_Value, _Value, _Alloc, + std::_Identity<_Value>, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, true, false> + { + typedef _Hashtable<_Value, _Value, _Alloc, + std::_Identity<_Value>, _Pred, + _Hash, __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, + __cache_hash_code, true, false> + _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + __unordered_multiset(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), __eql, + std::_Identity<_Value>(), __a) + { } + + + template + __unordered_multiset(_InputIterator __f, _InputIterator __l, + typename _Base::size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), __eql, + std::_Identity<_Value>(), __a) + { } + }; + + template + inline void + swap (__unordered_set<_Value, _Hash, _Pred, + _Alloc, __cache_hash_code>& __x, + __unordered_set<_Value, _Hash, _Pred, + _Alloc, __cache_hash_code>& __y) + { __x.swap(__y); } + + template + inline void + swap(__unordered_multiset<_Value, _Hash, _Pred, + _Alloc, __cache_hash_code>& __x, + __unordered_multiset<_Value, _Hash, _Pred, + _Alloc, __cache_hash_code>& __y) + { __x.swap(__y); } + + + template, + class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value> > + class unordered_set + : public __unordered_set<_Value, _Hash, _Pred, _Alloc> + { + typedef __unordered_set<_Value, _Hash, _Pred, _Alloc> _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + unordered_set(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { } + + template + unordered_set(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { } + }; + + template, + class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value> > + class unordered_multiset + : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc> + { + typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc> _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + + explicit + unordered_multiset(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { } + + + template + unordered_multiset(_InputIterator __f, _InputIterator __l, + typename _Base::size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { } + }; + +_GLIBCXX_END_NAMESPACE_TR1 +} diff --git a/libstdc++-v3/include/tr1_impl/utility b/libstdc++-v3/include/tr1_impl/utility new file mode 100644 index 0000000..42040c9 --- /dev/null +++ b/libstdc++-v3/include/tr1_impl/utility @@ -0,0 +1,98 @@ + +// TR1 utility -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1_impl/utility + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_TR1 + + template class tuple_size; + template class tuple_element; + + // Various functions which give std::pair a tuple-like interface. + template + struct tuple_size > + { static const int value = 2; }; + + template + const int tuple_size >::value; + + template + struct tuple_element<0, std::pair<_Tp1, _Tp2> > + { typedef _Tp1 type; }; + + template + struct tuple_element<1, std::pair<_Tp1, _Tp2> > + { typedef _Tp2 type; }; + + + template struct __pair_get; + + template<> + struct __pair_get<0> + { + template + static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair) + { return __pair.first; } + + template + static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair) + { return __pair.first; } + }; + + template<> + struct __pair_get<1> + { + template + static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair) + { return __pair.second; } + + template + static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair) + { return __pair.second; } + }; + + template + inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& + get(std::pair<_Tp1, _Tp2>& __in) + { return __pair_get<_Int>::__get(__in); } + + template + inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& + get(const std::pair<_Tp1, _Tp2>& __in) + { return __pair_get<_Int>::__const_get(__in); } + +_GLIBCXX_END_NAMESPACE_TR1 +} + diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/value.cc index ac79317..3a1ff3d 100644 --- a/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/value.cc +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_copy_constructor/value.cc @@ -29,7 +29,7 @@ void test01() using std::has_nothrow_copy_constructor; using namespace __gnu_test; - VERIFY( (test_category(true)) ); + // Positive tests. VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); @@ -45,6 +45,9 @@ void test01() VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); + + // Negative tests. + VERIFY( (test_category(false)) ); } int main() diff --git a/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/value.cc index fccbcf7..839b9cc 100644 --- a/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/value.cc +++ b/libstdc++-v3/testsuite/20_util/has_nothrow_default_constructor/value.cc @@ -31,7 +31,7 @@ void test01() using std::has_nothrow_default_constructor; using namespace __gnu_test; - VERIFY( (test_category(true)) ); + // Positive tests. VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); @@ -50,6 +50,9 @@ void test01() VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); + + // Negative tests. + VERIFY( (test_category(false)) ); } int main() diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/value.cc index 2ea418a..98eb81a 100644 --- a/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/value.cc +++ b/libstdc++-v3/testsuite/20_util/has_trivial_copy_constructor/value.cc @@ -31,7 +31,7 @@ void test01() using std::has_trivial_copy_constructor; using namespace __gnu_test; - VERIFY( (test_category(true)) ); + // Positive tests. VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); @@ -47,6 +47,9 @@ void test01() VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); + + // Negative tests. + VERIFY( (test_category(false)) ); } int main() diff --git a/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/value.cc b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/value.cc index fae5ace9..dfb707b 100644 --- a/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/value.cc +++ b/libstdc++-v3/testsuite/20_util/has_trivial_default_constructor/value.cc @@ -31,7 +31,7 @@ void test01() using std::has_trivial_default_constructor; using namespace __gnu_test; - VERIFY( (test_category(true)) ); + // Positive tests. VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); @@ -50,6 +50,9 @@ void test01() VERIFY( (test_category(true)) ); VERIFY( (test_category(true)) ); + + // Negative tests. + VERIFY( (test_category(false)) ); } int main() diff --git a/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc b/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc index baeb71e..37c5a03 100644 --- a/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc +++ b/libstdc++-v3/testsuite/20_util/headers/type_traits/types_std_c++0x_neg.cc @@ -30,8 +30,8 @@ namespace gnu using std::has_nothrow_copy; } -// { dg-error "has not been declared" "" { xfail *-*-* } 27 } -// { dg-error "has not been declared" "" { xfail *-*-* } 28 } -// { dg-error "has not been declared" "" { xfail *-*-* } 29 } -// { dg-error "has not been declared" "" { xfail *-*-* } 30 } +// { dg-error "has not been declared" "" { target *-*-* } 27 } +// { dg-error "has not been declared" "" { target *-*-* } 28 } +// { dg-error "has not been declared" "" { target *-*-* } 29 } +// { dg-error "has not been declared" "" { target *-*-* } 30 } diff --git a/libstdc++-v3/testsuite/20_util/is_signed/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_signed/requirements/explicit_instantiation.cc new file mode 100644 index 0000000..60d18d6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_signed/requirements/explicit_instantiation.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +namespace std +{ + typedef short test_type; + template struct is_signed; +} diff --git a/libstdc++-v3/testsuite/20_util/is_signed/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_signed/requirements/typedefs.cc new file mode 100644 index 0000000..5c7e882 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_signed/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_signed test_type; + typedef test_type::value_type value_type; + typedef test_type::type type; + typedef test_type::type::value_type type_value_type; + typedef test_type::type::type type_type; +} diff --git a/libstdc++-v3/testsuite/20_util/is_signed/value.cc b/libstdc++-v3/testsuite/20_util/is_signed/value.cc new file mode 100644 index 0000000..fcf84e7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_signed/value.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_signed; + using namespace __gnu_test; + + VERIFY( (test_category(false)) ); + + VERIFY( (test_category(char(-1) < char(0))) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( (test_category(wchar_t(-1) < wchar_t(0))) ); +#endif + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); + + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(true)) ); + + // Sanity check. + VERIFY( (test_category(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc new file mode 100644 index 0000000..2cef363 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/explicit_instantiation.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 2007-04-30 Benjamin Kosnik + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +namespace std +{ + typedef short test_type; + template struct is_unsigned; +} diff --git a/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/typedefs.cc new file mode 100644 index 0000000..14f3846 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_unsigned/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::is_unsigned test_type; + typedef test_type::value_type value_type; + typedef test_type::type type; + typedef test_type::type::value_type type_value_type; + typedef test_type::type::type type_type; +} diff --git a/libstdc++-v3/testsuite/20_util/is_unsigned/value.cc b/libstdc++-v3/testsuite/20_util/is_unsigned/value.cc new file mode 100644 index 0000000..d924163 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_unsigned/value.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } +// 2005-01-24 Paolo Carlini +// +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::is_unsigned; + using namespace __gnu_test; + + VERIFY( (test_category(false)) ); + + VERIFY( (test_category(char(-1) > char(0))) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( (test_category(wchar_t(-1) > wchar_t(0))) ); +#endif + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(true)) ); + + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); + + // Sanity check. + VERIFY( (test_category(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc index 063c12eb..044f979 100644 --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc @@ -49,8 +49,8 @@ void test01() // { dg-error "instantiated from here" "" { target *-*-* } 41 } // { dg-error "instantiated from here" "" { target *-*-* } 43 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 291 } -// { dg-error "declaration of" "" { target *-*-* } 253 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 424 } +// { dg-error "declaration of" "" { target *-*-* } 390 } // { dg-excess-errors "At global scope" } // { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc index 79277a7..f12d941 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc @@ -49,8 +49,8 @@ void test01() // { dg-error "instantiated from here" "" { target *-*-* } 41 } // { dg-error "instantiated from here" "" { target *-*-* } 43 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 208 } -// { dg-error "declaration of" "" { target *-*-* } 170 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 345 } +// { dg-error "declaration of" "" { target *-*-* } 311 } // { dg-excess-errors "At global scope" } // { dg-excess-errors "In instantiation of" } diff --git a/libstdc++-v3/testsuite/20_util/tuple/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/tuple/requirements/explicit_instantiation.cc index cdead8f..55afcc8 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/requirements/explicit_instantiation.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/requirements/explicit_instantiation.cc @@ -30,4 +30,4 @@ #include -template class std::tuple; +template class std::tr1::tuple; diff --git a/libstdc++-v3/testsuite/tr1/headers.cc b/libstdc++-v3/testsuite/tr1/headers.cc deleted file mode 100644 index 633b8fb..0000000 --- a/libstdc++-v3/testsuite/tr1/headers.cc +++ /dev/null @@ -1,64 +0,0 @@ -// { dg-do compile } - -// 2006-02-02 Paolo Carlini -// -// Copyright (C) 2006, 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/libstdc++-v3/testsuite/tr1/headers/all.cc b/libstdc++-v3/testsuite/tr1/headers/all.cc new file mode 100644 index 0000000..633b8fb --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/headers/all.cc @@ -0,0 +1,64 @@ +// { dg-do compile } + +// 2006-02-02 Paolo Carlini +// +// Copyright (C) 2006, 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/libstdc++-v3/testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc b/libstdc++-v3/testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc new file mode 100644 index 0000000..0d74636 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/headers/c++200x/using_namespace_std_tr1.cc @@ -0,0 +1,27 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include + +namespace gnu +{ + using namespace std::tr1; +} diff --git a/libstdc++-v3/testsuite/tr1/headers/using_namespace_std_tr1.cc b/libstdc++-v3/testsuite/tr1/headers/using_namespace_std_tr1.cc new file mode 100644 index 0000000..21fc682 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/headers/using_namespace_std_tr1.cc @@ -0,0 +1,26 @@ +// { dg-do compile } + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include + +namespace gnu +{ + using namespace std::tr1; +} diff --git a/libstdc++-v3/testsuite/tr1/using_namespace_std_tr1.cc b/libstdc++-v3/testsuite/tr1/using_namespace_std_tr1.cc deleted file mode 100644 index 21fc682..0000000 --- a/libstdc++-v3/testsuite/tr1/using_namespace_std_tr1.cc +++ /dev/null @@ -1,26 +0,0 @@ -// { dg-do compile } - -// Copyright (C) 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -#include - -namespace gnu -{ - using namespace std::tr1; -} -- cgit v1.1