diff --git a/cpp/type/tuple.hpp.erb b/cpp/type/tuple.hpp.erb index 397f660b..13d4bd76 100644 --- a/cpp/type/tuple.hpp.erb +++ b/cpp/type/tuple.hpp.erb @@ -32,36 +32,48 @@ template , typename A<%=i% struct tuple; template -struct tuple_type; +struct tuple_element; template -struct const_tuple_type; +struct const_tuple_element; template -struct tuple_element { +struct tuple_type { typedef T type; - tuple_element(T& x) : _x(x) {} - type& get() { return _x; } - const type& get() const { return _x; } -private: - type& _x; + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef const T& transparent_reference; }; template -struct const_tuple_element { +struct tuple_type { typedef T type; - const_tuple_element(const T& x) : _x(x) {} - const type& get() const { return _x; } -private: - const type& _x; + typedef T& value_type; + typedef T& reference; + typedef const T& const_reference; + typedef T& transparent_reference; +}; + +template +struct tuple_type { + typedef T type; + typedef T& value_type; + typedef T& reference; + typedef const T& const_reference; + typedef const T& transparent_reference; }; <%0.upto(GENERATION_LIMIT) {|i|%> <%0.upto(i) {|j|%> template , typename A<%=k%><%}%>> -struct tuple_type, A<%=k%><%}%>>, <%=j%>> : tuple_element> { - tuple_type(tuple, A<%=k%> <%}%>>& x) : tuple_element>(x.a<%=j%>) {} +struct tuple_element, A<%=k%><%}%>>, <%=j%>> : tuple_type> { + tuple_element(tuple, A<%=k%> <%}%>>& x) : _x(x.a<%=j%>) {} + typename tuple_type>::reference get() { return _x; } + typename tuple_type>::const_reference get() const { return _x; } +private: + typename tuple_type>::reference _x; }; <%}%> <%}%> @@ -70,8 +82,11 @@ struct tuple_type, A<%=k%><%}%>>, <%=j%>> : tuple_ele <%0.upto(GENERATION_LIMIT) {|i|%> <%0.upto(i) {|j|%> template , typename A<%=k%><%}%>> -struct const_tuple_type, A<%=k%><%}%>>, <%=j%>> : const_tuple_element> { - const_tuple_type(const tuple, A<%=k%><%}%>>& x) : const_tuple_element>(x.a<%=j%>) {} +struct const_tuple_element, A<%=k%><%}%>>, <%=j%>> : tuple_type> { + const_tuple_element(const tuple, A<%=k%><%}%>>& x) : _x(x.a<%=j%>) {} + typename tuple_type>::const_reference get() const { return _x; } +private: + typename tuple_type>::const_reference _x; }; <%}%> <%}%> @@ -79,7 +94,7 @@ struct const_tuple_type, A<%=k%><%}%>>, <%=j%>> : con <%0.upto(GENERATION_LIMIT) {|i|%> template , typename A<%=j%><%}%>> -tuple, A<%=j%><%}%>> make_tuple(const A0& a0<%1.upto(i) {|j|%>, const A<%=j%>& a<%=j%><%}%>) +tuple, A<%=j%><%}%>> make_tuple(typename tuple_type::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type>::transparent_reference a<%=j%><%}%>) { return tuple, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>); } @@ -92,14 +107,15 @@ struct tuple<> { <%0.upto(GENERATION_LIMIT) {|i|%> template , typename A<%=j%><%}%>> struct tuple, A<%=j%><%}%>> { + typedef tuple, A<%=j%><%}%>> value_type; tuple() {} - tuple(const A0& _a0<%1.upto(i) {|j|%>, const A<%=j%>& _a<%=j%><%}%>) : - a0(_a0) <%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {} + tuple(typename tuple_type::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type>::transparent_reference _a<%=j%><%}%>) : + a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {} tuple(object o) { convert(*this, o); } - template typename tuple_type, A<%=j%><%}%>>, N>::type& get() - { return tuple_type, A<%=j%><%}%>>, N>(*this).get(); } - template const typename const_tuple_type, A<%=j%><%}%>>, N>::type& get() const - { return const_tuple_type, A<%=j%><%}%>>, N>(*this).get(); } + template typename tuple_element::reference get() + { return tuple_element(*this).get(); } + template typename const_tuple_element::const_reference get() const + { return const_tuple_element(*this).get(); } <%0.upto(i) {|j|%> A<%=j%> a<%=j%>;<%}%> }; @@ -148,37 +164,6 @@ const packer& operator<< ( <%}%> -// FIXME -/* -template -struct tuple_just; - -template -struct tuple_just { - A0 a0; - static inline void convert(object o, tuple_just& v) - { - if(o.type != type::ARRAY) { throw type_error(); } - if(o.v.container.size != 1) { throw type_error(); } - msgpack::convert(o.v.container.ptr[0], v.a0); - } -}; - -template -struct tuple_just { - A0 a0; - A1 a1; - static inline void convert(object o, tuple_just& v) - { - if(o.type != type::ARRAY) { throw type_error(); } - if(o.v.container.size != 2) { throw type_error(); } - msgpack::convert(o.v.container.ptr[0], v.a0); - msgpack::convert(o.v.container.ptr[1], v.a1); - } -}; -*/ - - } // namespace msgpack #endif /* msgpack/type/tuple.hpp */