| 
									
										
										
										
											2012-11-07 14:42:10 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  | Copyright 2012-2015 Glen Joseph Fernandes | 
					
						
							|  |  |  | (glenjofe@gmail.com) | 
					
						
							| 
									
										
										
										
											2012-11-07 14:42:10 +00: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
										 |  |  | */ | 
					
						
							|  |  |  | #include <boost/smart_ptr/make_shared.hpp>
 | 
					
						
							| 
									
										
										
										
											2024-09-25 18:08:57 +03:00
										 |  |  | #include <boost/core/lightweight_test.hpp>
 | 
					
						
							|  |  |  | #include <boost/config.hpp>
 | 
					
						
							| 
									
										
										
										
											2015-11-09 22:35:34 -05: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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 22:35:34 -05:00
										 |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-07 14:42:10 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<int[][2]> result = | 
					
						
							|  |  |  |             boost::allocate_shared<int[][2]>(creator<int>(), 2, {0, 1}); | 
					
						
							|  |  |  |         BOOST_TEST(result[0][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[0][1] == 1); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][1] == 1); | 
					
						
							| 
									
										
										
										
											2012-11-07 14:42:10 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-11-11 19:14:50 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         boost::shared_ptr<int[2][2]> result = | 
					
						
							|  |  |  |             boost::allocate_shared<int[2][2]>(creator<int>(), {0, 1}); | 
					
						
							|  |  |  |         BOOST_TEST(result[0][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[0][1] == 1); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][1] == 1); | 
					
						
							| 
									
										
										
										
											2012-11-11 19:14:50 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											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<const int[][2]>(creator<>(), 2, {0, 1}); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result[0][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[0][1] == 1); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][1] == 1); | 
					
						
							| 
									
										
										
										
											2012-11-11 19:14:50 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											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<const int[2][2]>(creator<>(), {0, 1}); | 
					
						
							| 
									
										
										
										
											2017-03-06 01:18:16 -05:00
										 |  |  |         BOOST_TEST(result[0][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[0][1] == 1); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][0] == 0); | 
					
						
							|  |  |  |         BOOST_TEST(result[1][1] == 1); | 
					
						
							| 
									
										
										
										
											2012-11-11 19:14:50 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-11-07 14:42:10 +00:00
										 |  |  |     return boost::report_errors(); | 
					
						
							|  |  |  | } |