Boost logo

Boost :

Subject: Re: [boost] [fusion] getting type of attribute_proxy for BOOST_FUSION_ADAPT_ADT
From: Jens Weller (JensWeller_at_[hidden])
Date: 2016-03-03 05:16:24


> Gesendet: Donnerstag, 03. März 2016 um 03:12 Uhr
> Von: "Joel de Guzman" <djowel_at_[hidden]>
> An: boost_at_[hidden]
> 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<int I, class Seq, class V>
> > typename std::enable_if< std::is_convertible< typename fusion::result_of::at_c<Seq, I>::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<int I, class Seq, class V>
> > typename std::enable_if< !std::is_convertible< typename fusion::result_of::at_c<Seq, I>::type, V>::value /*&& !std::is_same<typename std::decay<V>::type,std::string>::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#fusion.notes.adt_attribute_proxy

Hi Joel,

great!

Is there a generic way to detect which sort of Adapted struct it is?
typename fusion::result_of::at_c<Seq, I>::type::type t;
Will probably only work for proxies, which would be fine for my code.

thanks,

Jens Weller


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk