| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | Copyright 2012-2015 Glen Joseph Fernandes | 
					
						
							|  |  |  | (glenjofe@gmail.com) | 
					
						
							| 
									
										
										
										
											2015-11-09 22:35:34 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | Distributed under the Boost Software License, Version 1.0. | 
					
						
							|  |  |  | (http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2015-11-09 22:35:34 -05:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | #include <boost/align/is_aligned.hpp>
 | 
					
						
							| 
									
										
										
										
											2015-11-09 22:35:34 -05:00
										 |  |  | #include <boost/core/lightweight_test.hpp>
 | 
					
						
							|  |  |  | #include <boost/smart_ptr/make_shared.hpp>
 | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  | #include <boost/smart_ptr/weak_ptr.hpp>
 | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  | #include <type_traits>
 | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  | template<class T = void> | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | struct creator { | 
					
						
							|  |  |  |     typedef T value_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<class U> | 
					
						
							|  |  |  |     struct rebind { | 
					
						
							|  |  |  |         typedef creator<U> other; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     creator() { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<class U> | 
					
						
							|  |  |  |     creator(const creator<U>&) { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     T* allocate(std::size_t size) { | 
					
						
							|  |  |  |         return static_cast<T*>(::operator new(sizeof(T) * size)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void deallocate(T* ptr, std::size_t) { | 
					
						
							|  |  |  |         ::operator delete(ptr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> | 
					
						
							|  |  |  | inline bool | 
					
						
							|  |  |  | operator==(const creator<T>&, const creator<U>&) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, class U> | 
					
						
							|  |  |  | inline bool | 
					
						
							|  |  |  | operator!=(const creator<T>&, const creator<U>&) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  | class type { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     static unsigned instances; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     type() | 
					
						
							|  |  |  |         : value_(0.0) { | 
					
						
							|  |  |  |         ++instances; | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |     ~type() { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         --instances; | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void set(long double value) { | 
					
						
							|  |  |  |         value_ = value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     long double get() const { | 
					
						
							|  |  |  |         return value_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  | private: | 
					
						
							|  |  |  |     type(const type&); | 
					
						
							|  |  |  |     type& operator=(const type&); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     long double value_; | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | unsigned type::instances = 0; | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 22:35:34 -05:00
										 |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<int[]> result = | 
					
						
							|  |  |  |             boost::allocate_shared_noinit<int[]>(creator<int>(), 3); | 
					
						
							|  |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<int[3]> result = | 
					
						
							|  |  |  |             boost::allocate_shared_noinit<int[3]>(creator<int>()); | 
					
						
							|  |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<int[][2]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<int[][2]>(creator<>(), 2); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<int[2][2]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<int[2][2]>(creator<>()); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<const int[]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<const int[]>(creator<>(), 3); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<const int[3]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<const int[3]>(creator<>()); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<const int[][2]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<const int[][2]>(creator<>(), 2); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<const int[2][2]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<const int[2][2]>(creator<>()); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<int>::value)); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         boost::shared_ptr<type[]> result = | 
					
						
							|  |  |  |             boost::allocate_shared_noinit<type[]>(creator<type>(), 3); | 
					
						
							|  |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 3); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<type[]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<type[3]> result = | 
					
						
							|  |  |  |             boost::allocate_shared_noinit<type[3]>(creator<type>()); | 
					
						
							|  |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 3); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<type[3]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<type[][2]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<type[][2]>(creator<>(), 2); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 4); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<type[][2]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<type[2][2]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<type[2][2]>(creator<>()); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 4); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<type[2][2]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<const type[]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<const type[]>(creator<>(), 3); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 3); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<const type[]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<const type[3]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<const type[3]>(creator<>()); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 3); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<const type[3]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<const type[][2]> result = | 
					
						
							|  |  |  |             boost::allocate_shared_noinit<const | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |                 type[][2]>(creator<>(), 2); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 4); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<const type[][2]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<const type[2][2]> result = | 
					
						
							| 
									
										
										
										
											2017-06-20 20:03:52 -04:00
										 |  |  |             boost::allocate_shared_noinit<const type[2][2]>(creator<>()); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result.get() != 0); | 
					
						
							|  |  |  |         BOOST_TEST(result.use_count() == 1); | 
					
						
							|  |  |  |         BOOST_TEST(boost::alignment::is_aligned(result.get(), | 
					
						
							| 
									
										
										
										
											2024-10-06 18:57:30 +03:00
										 |  |  |             std::alignment_of<type>::value)); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 4); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::weak_ptr<const type[2][2]> other = result; | 
					
						
							|  |  |  |         result.reset(); | 
					
						
							| 
									
										
										
										
											2014-01-23 20:40:46 -08:00
										 |  |  |         BOOST_TEST(type::instances == 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return boost::report_errors(); | 
					
						
							|  |  |  | } |