is there a boost "storable_type"?

Hi, I am wondering if there is a construct in boost which, given a type T, returns the underlying "storable" type - say if T is int & the "storable_type" should be int. I'm not sure if the word "storable" is the best word... The scenario I am facing is making a function call that takes a parameter of type T, where I need to prepare the parameter before calling (specifically, deserializing it from an archive). Hence, as far as I can tell, I need to declare a variable of the underlying storable type, and get the right value inside it. So far, I've been using: template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>::type > {}; but I'm not sure if that cuts it in all situations. In any case, I figured the right thing might be in Boost already and I just haven't found it. Any suggestions? Thanks! Stjepan

--- Stjepan Rajko wrote:
Hi,
Hello.
I am wondering if there is a construct in boost which, given a type T, returns the underlying "storable" type - say if T is int & the "storable_type" should be int. I'm not sure if the word "storable" is the best word...
I was thinking "data" type.
The scenario I am facing is making a function call that takes a parameter of type T, where I need to prepare the parameter before calling (specifically, deserializing it from an archive). Hence, as far as I can tell, I need to declare a variable of the underlying storable type, and get the right value inside it.
So far, I've been using:
template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>::type > {};
but I'm not sure if that cuts it in all situations.
In my automata library, I defined a data_type metafunction that removes const, pointer, reference, volatile, and [] qualifiers from the input type.
In any case, I figured the right thing might be in Boost already and I just haven't found it.
Any suggestions?
FWIW, I should be asking the same question. I'm curious myself. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Hello,
So far, I've been using:
template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>:
:type > {};
I've done the same for the same reason, but with the less inventive name remove_const_reference. FWIW, I would have appreciated something in type_traits to solve this more elegantly.
In my automata library, I defined a data_type metafunction that removes const, pointer, reference, volatile, and [] qualifiers from the input type.
Could you post the function here? Or would it be possible to eventually have it added to the type_traits library? Thanks, Christian On 17/04/07, Cromwell Enage <sponage@yahoo.com> wrote:
--- Stjepan Rajko wrote:
Hi,
Hello.
I am wondering if there is a construct in boost which, given a type T, returns the underlying "storable" type - say if T is int & the "storable_type" should be int. I'm not sure if the word "storable" is the best word...
I was thinking "data" type.
The scenario I am facing is making a function call that takes a parameter of type T, where I need to prepare the parameter before calling (specifically, deserializing it from an archive). Hence, as far as I can tell, I need to declare a variable of the underlying storable type, and get the right value inside it.
So far, I've been using:
template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>::type > {};
but I'm not sure if that cuts it in all situations.
In my automata library, I defined a data_type metafunction that removes const, pointer, reference, volatile, and [] qualifiers from the input type.
In any case, I figured the right thing might be in Boost already and I just haven't found it.
Any suggestions?
FWIW, I should be asking the same question. I'm curious myself.
Cromwell D. Enage
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi Cromwell, On 4/17/07, Cromwell Enage <sponage@yahoo.com> wrote:
In my automata library, I defined a data_type metafunction that removes const, pointer, reference, volatile, and [] qualifiers from the input type.
In my case, I think I need to keep the pointers as pointers. Serialization should take care of getting the right thing into memory and pointed to by the pointer. So there might be two things that we're after - one thing that gets the underlying data type, and one thing that gets the underlying storable (or whatever) type. Stjepan

--- Christian Holmquist wrote:
--- Cromwell Enage wrote:
In my automata library, I defined a data_type metafunction that removes const, pointer, reference, volatile, and [] qualifiers from the input type.
Could you post the function here? Or would it be possible to eventually have it added to the type_traits library?
The automata library is available from the Boost Vault in the Data Structures directory, but for convenience, here are the contents of the header file in question: // Copyright (C) 2007 Cromwell D. Enage // Distributed under the Boost Software License, // Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_DETAIL_METAFUNCTION_DATA_TYPE_HPP_INCLUDED #define BOOST_DETAIL_METAFUNCTION_DATA_TYPE_HPP_INCLUDED #include <boost/type_traits/remove_const.hpp> #include <boost/type_traits/remove_reference.hpp> #include <boost/type_traits/remove_pointer.hpp> #include <boost/type_traits/remove_volatile.hpp> #include <boost/type_traits/remove_all_extents.hpp> #include <boost/mpl/aux_/lambda_support.hpp> namespace boost { namespace detail { template <typename T> struct data_type : remove_const< typename remove_reference< typename remove_pointer< typename remove_volatile< typename remove_all_extents<T>::type >::type >::type >::type > { BOOST_MPL_AUX_LAMBDA_SUPPORT(1,data_type,(T)) }; }} // namespace boost::detail #endif // BOOST_DETAIL_METAFUNCTION_DATA_TYPE_HPP_INCLUDED HTH, Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Stjepan Rajko wrote:
I am wondering if there is a construct in boost which, given a type T, returns the underlying "storable" type - say if T is int & the "storable_type" should be int. I'm not sure if the word "storable" is the best word...
The scenario I am facing is making a function call that takes a parameter of type T, where I need to prepare the parameter before calling (specifically, deserializing it from an archive). Hence, as far as I can tell, I need to declare a variable of the underlying storable type, and get the right value inside it.
So far, I've been using:
template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>::type > {};
but I'm not sure if that cuts it in all situations. In any case, I figured the right thing might be in Boost already and I just haven't found it.
No we don't have that one, well there had to be one :-) Your code will only work for class types right? If that's an acceptable limitation then it will do what you want, or did you mean: template<typename T> struct storable { typedef typename boost::remove_const<typename boost::remove_reference<T>::type > type; }; ??? Which would work for just about everything except function types (may need to be degraded to pointer-to-function), and abstract types. HTH, John.

--- John Maddock wrote:
Stjepan Rajko wrote:
So far, I've been using:
template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>::type > {};
[snip]
Your code will only work for class types right? If that's an acceptable limitation then it will do what you want, or did you mean:
template<typename T> struct storable { typedef typename boost::remove_const<typename boost::remove_reference<T>::type > type; };
I thought both class definitions would be equivalent from a user's perspective, e.g.: BOOST_STATIC_ASSERT(( boost::is_same< storable<int const&>::type , int >::value )); I've been using the first style (the one Stjepan presented) on primitive types without problems. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Cromwell Enage wrote:
--- John Maddock wrote:
Stjepan Rajko wrote:
So far, I've been using:
template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>::type > {};
[snip]
Your code will only work for class types right? If that's an acceptable limitation then it will do what you want, or did you mean:
template<typename T> struct storable { typedef typename boost::remove_const<typename boost::remove_reference<T>::type > type; };
I thought both class definitions would be equivalent from a user's perspective, e.g.:
BOOST_STATIC_ASSERT(( boost::is_same< storable<int const&>::type , int >::value ));
???? There's no nested ::type member in the first version.
I've been using the first style (the one Stjepan presented) on primitive types without problems.
Don't you end up inheriting from the primitive type in that case???? Confused yours, John.

On Thu, 19 Apr 2007 11:21:08 +0200, John Maddock <john@johnmaddock.co.uk> wrote:
Cromwell Enage wrote:
--- John Maddock wrote:
Stjepan Rajko wrote:
So far, I've been using:
template<typename T> struct storable : public boost::remove_const<typename boost::remove_reference<T>::type > {};
[snip]
Your code will only work for class types right? If that's an acceptable limitation then it will do what you want, or did you mean:
template<typename T> struct storable { typedef typename boost::remove_const<typename boost::remove_reference<T>::type > type; };
I thought both class definitions would be equivalent from a user's perspective, e.g.:
BOOST_STATIC_ASSERT(( boost::is_same< storable<int const&>::type , int >::value ));
???? There's no nested ::type member in the first version.
I've been using the first style (the one Stjepan presented) on primitive types without problems.
Don't you end up inheriting from the primitive type in that case????
Confused yours, John.
Maybe there is only a qui pro quo: form #1 isn't template<typename T> struct storable : public typename boost::remove_const < typename boost::remove_reference<T>::type >::type {}; that would imply storable<const int &> : public int but it's template<typename T> struct storable : public boost::remove_const < typename boost::remove_reference<T>::type > {}; that leads to : storable< const int & > : public boost::remove_const< const int > and so: typename storable< const int & >::type is equal to int Marco -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Marco wrote:
but it's
template<typename T> struct storable : public boost::remove_const < typename boost::remove_reference<T>::type > {};
that leads to : storable< const int & > : public boost::remove_const< const int >
and so: typename storable< const int & >::type is equal to int
Doh! Embarrassed yours, John.
participants (5)
-
Christian Holmquist
-
Cromwell Enage
-
John Maddock
-
Marco
-
Stjepan Rajko