1/* { dg-do compile } */ 2 3#include<cassert> 4#include<new> 5#include<utility> 6 7namespace boost { 8 9template<class T> 10class optional; 11 12class aligned_storage 13{ 14 char data[ 1000 ]; 15 public: 16 void const* address() const { return &data[0]; } 17 void * address() { return &data[0]; } 18} ; 19 20 21template<class T> 22class optional_base 23{ 24 protected : 25 optional_base(){} 26 optional_base ( T const& val ) 27 { 28 construct(val); 29 } 30 31 template<class U> 32 void assign ( optional<U> const& rhs ) 33 { 34 if (!is_initialized()) 35 if ( rhs.is_initialized() ) 36 construct(T()); 37 } 38 39 public : 40 41 bool is_initialized() const { return m_initialized ; } 42 43 protected : 44 45 void construct ( T const& val ) 46 { 47 new (m_storage.address()) T(val) ; 48 } 49 50 T const* get_ptr_impl() const 51 { return static_cast<T const*>(m_storage.address()); } 52 53 private : 54 55 bool m_initialized ; 56 aligned_storage m_storage ; 57} ; 58 59 60template<class T> 61class optional : public optional_base<T> 62{ 63 typedef optional_base<T> base ; 64 65 public : 66 67 optional() : base() {} 68 optional ( T const& val ) : base(val) {} 69 optional& operator= ( optional const& rhs ) 70 { 71 this->assign( rhs ) ; 72 return *this ; 73 } 74 75 T const& get() const ; 76 77 T const* operator->() const { assert(this->is_initialized()) ; return this->get_ptr_impl() ; } 78 79} ; 80 81 82} // namespace boost 83 84 85namespace std 86{ 87 88 template<typename _Tp, std::size_t _Nm> 89 struct array 90 { 91 typedef _Tp value_type; 92 typedef const value_type* const_iterator; 93 94 value_type _M_instance[_Nm]; 95 96 }; 97} 98 99 100class NT 101{ 102 double _inf, _sup; 103}; 104 105 106template < typename T > inline 107std::array<T, 1> 108make_array(const T& b1) 109{ 110 std::array<T, 1> a = { { b1 } }; 111 return a; 112} 113 114class V 115{ 116 typedef std::array<NT, 1> Base; 117 Base base; 118 119public: 120 V() {} 121 V(const NT &x) 122 : base(make_array(x)) {} 123 124}; 125 126using boost::optional ; 127 128optional< std::pair< NT, NT > > 129 linsolve_pointC2() ; 130 131optional< V > construct_normal_offset_lines_isecC2 ( ) 132{ 133 optional< std::pair<NT,NT> > ip; 134 135 ip = linsolve_pointC2(); 136 137 V a(ip->first) ; 138 return a; 139} 140 141 142 143