_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 } // TR1 cstdint -*- C++ -*- // Copyright (C) 2007, 2008, 2009 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. */ #pragma GCC system_header #if _GLIBCXX_USE_C99_STDINT_TR1 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 // 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()); } template _RAIter __lower_bound(_RAIter __first, _RAIter __last, const _Tp& __val) { typedef typename std::iterator_traits<_RAIter>::difference_type _DType; _DType __len = __last - __first; while (__len > 0) { _DType __half = __len >> 1; _RAIter __middle = __first + __half; if (*__middle < __val) { __first = __middle; ++__first; __len = __len - __half - 1; } else __len = __half; } return __first; } // 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 princR/S/T/U/V/W/X/Y/Z/[/\/]/^/_/iple 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) : _M_max_load_factor(__z), _M_growth_factor(2.f), _M_next_resize(0) { } float max_load_factor() const { return _M_max_load_factor; } // 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; enum { _S_n_primes = sizeof(unsigned long) != 8 ? 256 : 256 + 48 }; float _M_max_load_factor; float _M_growth_factor; mutable std::size_t _M_next_resize; }; extern const unsigned long __prime_list[]; // XXX This is a hack. There's no good reason for any of // _Prime_rehash_policy's member functions to be inline. // 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* __p = __lower_bound(__prime_list, __prime_list + _S_n_primes, __n); _M_next_resize = static_cast(__builtin_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 float __min_bkts = __n / _M_max_load_factor; const unsigned long* __p = __lower_bound(__prime_list, __prime_list + _S_n_primes, __min_bkts); _M_next_resize = static_cast(__builtin_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* __p = __lower_bound(__prime_list, __prime_list + _S_n_primes, __min_bkts); _M_next_resize = static_cast (__builtin_ceil(*__p * _M_max_load_factor)); return std::make_pair(true, *__p); } else { _M_next_resize = static_cast (__builtin_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 } // 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 // 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 template typename uniform_int<_IntType>::result_type uniform_int<_IntType>:: _M_call(_UniformRandomNumberGenerator& __urng, result_type __min, result_type __max, true_type) { // XXX Must be fixed to work well for *arbitrary* __urng.max(), // __urng.min(), __max, __min. Currently works fine only in the // most common case __urng.max() - __urng.min() >= __max - __min, // with __urng.max() > __urng.min() >= 0. typedef typename __gnu_cxx::__add_unsigned::__type __urntype; typedef typename __gnu_cxx::__add_unsigned::__type __utype; typedef typename __gnu_cxx::__conditional_type<(sizeof(__urntype) > sizeof(__utype)), __urntype, __utype>::__type __uctype; result_type __ret; const __urntype __urnmin = __urng.min(); const __urntype __urnmax = __urng.max(); const __urntype __urnrange = __urnmax - __urnmin; const __uctype __urange = __max - __min; const __uctype __udenom = (__urnrange <= __urange ? 1 : __urnrange / (__urange + 1)); do __ret = (__urntype(__urng()) - __urnmin) / __udenom; while (__ret > __max - __min); return __ret + __min; } 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. * *