[fusion] getting type of attribute_proxy for BOOST_FUSION_ADAPT_ADT
Hello,
Code below, first what I'm trying to do is...
assign a value to a adapted struct (BOOST_FUSION_ADAPT_ADT), which works fine if both are of the same type or convertible:
template
On 03/03/2016 9:43 AM, Jens Weller wrote:
Hello,
Code below, first what I'm trying to do is... assign a value to a adapted struct (BOOST_FUSION_ADAPT_ADT), which works fine if both are of the same type or convertible:
template
typename std::enable_if< std::is_convertible< typename fusion::result_of::at_c ::type, V>::value ,void>::type assign(Seq& s, V& v) { fusion::get<I>(s) = v; } Some of my input is string, and the struct member is bool, unsigned int etc. In this case I'd need to know the type to convert from string.
boost::fusion::get returns the attribute_proxy for the adapted struct, so does at_c<>::type.
template
typename std::enable_if< !std::is_convertible< typename fusion::result_of::at_c ::type, V>::value /*&& !std::is_same ::value*/ ,void>::type assign(Seq& s, V& v) { std::stringstream ss; ss << v; ss >> fusion::get<I>(s); } Obviously this does not compile. Is there any trick to get to the type of the proxy?
One idea I have is decltype(fusion::get<I>(s).get()), but not sure if I can get this to work in an enable_if...
Hi Jens, Try attribute_proxy::type. It's documented here: http://www.boost.org/doc/libs/1_50_0/libs/fusion/doc/html/fusion/notes.html#... Regards, -- Joel de Guzman http://www.ciere.com http://boost-spirit.com http://www.cycfi.com/
Gesendet: Donnerstag, 03. März 2016 um 03:12 Uhr Von: "Joel de Guzman"
An: boost@lists.boost.org Betreff: Re: [boost] [fusion] getting type of attribute_proxy for BOOST_FUSION_ADAPT_ADT On 03/03/2016 9:43 AM, Jens Weller wrote:
Hello,
Code below, first what I'm trying to do is... assign a value to a adapted struct (BOOST_FUSION_ADAPT_ADT), which works fine if both are of the same type or convertible:
template
typename std::enable_if< std::is_convertible< typename fusion::result_of::at_c ::type, V>::value ,void>::type assign(Seq& s, V& v) { fusion::get<I>(s) = v; } Some of my input is string, and the struct member is bool, unsigned int etc. In this case I'd need to know the type to convert from string.
boost::fusion::get returns the attribute_proxy for the adapted struct, so does at_c<>::type.
template
typename std::enable_if< !std::is_convertible< typename fusion::result_of::at_c ::type, V>::value /*&& !std::is_same ::value*/ ,void>::type assign(Seq& s, V& v) { std::stringstream ss; ss << v; ss >> fusion::get<I>(s); } Obviously this does not compile. Is there any trick to get to the type of the proxy?
One idea I have is decltype(fusion::get<I>(s).get()), but not sure if I can get this to work in an enable_if...
Hi Jens,
Try attribute_proxy::type. It's documented here: http://www.boost.org/doc/libs/1_50_0/libs/fusion/doc/html/fusion/notes.html#...
Hi Joel,
great!
Is there a generic way to detect which sort of Adapted struct it is?
typename fusion::result_of::at_c
On 03/03/2016 6:16 PM, Jens Weller wrote:
Gesendet: Donnerstag, 03. März 2016 um 03:12 Uhr Von: "Joel de Guzman"
An: boost@lists.boost.org Betreff: Re: [boost] [fusion] getting type of attribute_proxy for BOOST_FUSION_ADAPT_ADT [snip]
Hi Jens,
Try attribute_proxy::type. It's documented here: http://www.boost.org/doc/libs/1_50_0/libs/fusion/doc/html/fusion/notes.html#...
Hi Joel,
great!
Is there a generic way to detect which sort of Adapted struct it is? typename fusion::result_of::at_c
::type::type t; Will probably only work for proxies, which would be fine for my code.
Hmmm, well adt_attribute_proxy only happens, erm with proxies. So I guess the more relevant question is, how do you easily detect if at_c or any iterator function returns a proxy(?). Alas, there's no easy way at the moment. It's easy to add one and perhaps that might be a good idea. Please file a ticket and I'll see what I can do. Regards, -- Joel de Guzman http://www.ciere.com http://boost-spirit.com http://www.cycfi.com/
[snip]
Hi Jens,
Try attribute_proxy::type. It's documented here: http://www.boost.org/doc/libs/1_50_0/libs/fusion/doc/html/fusion/notes.html#...
Hi Joel,
great!
Is there a generic way to detect which sort of Adapted struct it is? typename fusion::result_of::at_c
::type::type t; Will probably only work for proxies, which would be fine for my code. Hmmm, well adt_attribute_proxy only happens, erm with proxies. So I guess the more relevant question is, how do you easily detect if at_c or any iterator function returns a proxy(?). Alas, there's no easy way at the moment. It's easy to add one and perhaps that might be a good idea. Please file a ticket and I'll see what I can do.
Ticket created under:
https://svn.boost.org/trac/boost/ticket/12041
Which brings me to another fusion question/improvement:
ADT structs don't know their member names, which can be fixed with such a construct:
#define ADT_MEMBER_NAME(CLASS, INDEX, MEMBER) \
template <> struct struct_member_name
On 04/03/2016 17:32, Jens Weller wrote:
[snip] Ticket created under: https://svn.boost.org/trac/boost/ticket/12041
Which brings me to another fusion question/improvement: ADT structs don't know their member names, which can be fixed with such a construct: #define ADT_MEMBER_NAME(CLASS, INDEX, MEMBER) \ template <> struct struct_member_name
{ typedef char const *type; static type call() { return #MEMBER; } }; namespace boost { namespace fusion { namespace extension { ADT_MEMBER_NAME(ListEntry, 0, text) ... ADT_MEMBER_NAME(ListEntry, 6, published) } } }
Could that be integrated into the BOOST_FUSION_ADAPT_STRUCT_ADT etc. macros?
thanks,
Jens Weller
Hi Jens, I'm aware of this problem, as well for the name, as for detecting whether a proxy is in use or not. Additionally the proxies objects are suboptimal, they were long wrongly implemented, in that that the Fusion user had to know by adapting an ADT the internal fusion proxy prefix : https://github.com/boostorg/fusion/commit/b5018586aad1475652702a41d4f317f449... Since that point I wanted to bring better support for proxied member, and now you gave me the motivation and the occasion. I'll come up back soon with some fixes for this. Cheers, -- Damien Buhl (alias daminetreg)
participants (3)
-
Damien Buhl
-
Jens Weller
-
Joel de Guzman