Групы Малюнкі Пераклад Сеціва Абнаўленьні
Недавно посещенные группы | Help | Sign in
Главная страница Google Groups
Variant and Fusion
В данный момент в этой группе слишком много тем, которые должны показываться в первую очередь. Чтобы эта тема показывалась в первую очередь, измените этот параметр для какой-то другой темы.
При обработке Вашего запроса произошла ошибка. Повторите попытку.
пометка
  Сообщений: 7 - Свернуть все  -  Перевести все на Переведено (просмотреть все оригиналы)
Сообщение будет отправлено в группу Usenet. Когда Вы отправляете сообщения в такие группы, Ваш адрес электронной почты публикуется в Интернете.
Ваш ответ не был отправлен.
Сообщение отправлено успешно.
 
Автор:
Кому:
Копия:
В ответ на:
Добавить копию | Добавить заголовок "В ответ на" | Изменить тему
Тема:
Утверждение:
Для подтверждения введите символы, изображенные на картинке ниже, или цифры, которые вы услышите, нажав на значок упрощенного доступа. Слушайте и вводите услышанные числа
 
Matthias Vallentin  
Просмотреть профиль   Перевести на Переведено (просмотреть оригинал)
 Дополнительные параметры 10 мар, 23:37
Автор: Matthias Vallentin <vallen...@icsi.berkeley.edu>
Дата: Wed, 10 Mar 2010 13:37:14 -0800
Местное время: Ср. 10 мар 2010 23:37
Тема: [Boost-users] Variant and Fusion
Hi,

there used to be a variant adapter for fusion sequences, but it has
been rightfully removed:

on Wed Dec 19 2007, Joel de Guzman <joel-AT-boost-consulting.com> wrote:

> I intend to remove the variant adapter from fusion. After thorough
> investigation, I think now that the move to make variant a
> fusion sequence is rather quirky. A variant will always
> have a size==1 regardless of the number of types it can contain
> and there's no way to know at compile time what it contains.
> Iterating over its types is simply wrong. All these imply that
> the variant is *not* a fusion sequence.

Let's say I have a recursive variant and would like to flatten the
variant to create some sort of heterogeneous sequence from it.
Particularly, I would like to chop the variant into multiple disjunct
Fusion sequences, each of which are handed to generic component that
operates with Fusion sequences. The above suggests that Fusion is not
the right tool. What would be a better approach to handle this problem?

Should I split the variant into smaller variants instead? What made
Fusion so attractive is the notion of tiers, i.e., light-weight views of
references to the actual data. Is there a variant equivalent of tiers?

   Matthias
--
Matthias Vallentin
vallen...@icsi.berkeley.edu
http://www.icir.org/matthias
_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


    Переслать  
Чтобы отправлять сообщения, сначала необходимо Войти.
Чтобы отправлять сообщения, сначала необходимо присоединиться к группе.
Перед отправкой сообщения обновите свой псевдоним на странице Настройки подписки.
У вас нет разрешения на отправку сообщений.
Steven Watanabe  
Просмотреть профиль   Перевести на Переведено (просмотреть оригинал)
 Дополнительные параметры 10 мар, 23:46
Автор: Steven Watanabe <watanab...@gmail.com>
Дата: Wed, 10 Mar 2010 13:46:30 -0800
Местное время: Ср. 10 мар 2010 23:46
Тема: Re: [Boost-users] Variant and Fusion
AMDG

I'm not sure that I really understand what
you want.  Can you give an example of the kind
of recursive variant and the sequence(s) that you
want to get out of it?  In particular how are the
runtime values of the elements of the sequence
to be determined?

Depending on what you're doing, you might
be able to use the nested types typedef of
variant, which is an MPL sequence.

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


    Переслать  
Чтобы отправлять сообщения, сначала необходимо Войти.
Чтобы отправлять сообщения, сначала необходимо присоединиться к группе.
Перед отправкой сообщения обновите свой псевдоним на странице Настройки подписки.
У вас нет разрешения на отправку сообщений.
Matthias Vallentin  
Просмотреть профиль   Перевести на Переведено (просмотреть оригинал)
 Дополнительные параметры 11 мар, 02:45
Автор: Matthias Vallentin <vallen...@icsi.berkeley.edu>
Дата: Wed, 10 Mar 2010 16:45:23 -0800
Местное время: Чт. 11 мар 2010 02:45
Тема: Re: [Boost-users] Variant and Fusion

On Wed, Mar 10, 2010 at 01:46:30PM -0800, Steven Watanabe wrote:
> Can you give an example of the kind of recursive variant and the
> sequence(s) that you want to get out of it?  

Let this be the variant type

    typedef boost::make_recursive_variant<
        int,
        double,
        std::vector<boost::recursive_variant_>
    >::type variant;

and this an instance of it

    std::vector<variant> vec;
    vec.push_back(42);
    vec.push_back(4.2);
    vec.push_back(vec);
    variant v = vec;

> In particular how are the runtime values of the elements of the
> sequence to be determined?

Conceptually, I am thinking of a visitor that goes over the variant and
flattens it.  In the above example, the corresponding sequence would be

    [42, 4.2, 42, 4.2]

which corresponds to a fusion::vector<int, double, int, double>.
Practically, I don't see a way how to get the type of the vector at
runtime unless knowing in advance the type of the fusion vector (which
could be a potential assumption).

I was also talking about "chopping" the variant in disjunct sequences.
By this, I mean that a visitor goes over the variant and creates several
sequences, say

    [42]
    [4.2, 42]
    [42]

for the above example. That's the scenario I ultimately target. Ideally,
these sequences are only views (tiers) of the original variant.

> Depending on what you're doing, you might be able to use the nested
> types typedef of variant, which is an MPL sequence.

Are you referring to the variant<T>::types MPL sequence?

   Matthias
--
Matthias Vallentin
vallen...@icsi.berkeley.edu
http://www.icir.org/matthias
_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


    Переслать  
Чтобы отправлять сообщения, сначала необходимо Войти.
Чтобы отправлять сообщения, сначала необходимо присоединиться к группе.
Перед отправкой сообщения обновите свой псевдоним на странице Настройки подписки.
У вас нет разрешения на отправку сообщений.
Steven Watanabe  
Просмотреть профиль   Перевести на Переведено (просмотреть оригинал)
 Дополнительные параметры 11 мар, 03:25
Автор: Steven Watanabe <watanab...@gmail.com>
Дата: Wed, 10 Mar 2010 17:25:02 -0800
Местное время: Чт. 11 мар 2010 03:25
Тема: Re: [Boost-users] Variant and Fusion
AMDG

Matthias Vallentin wrote:
>> In particular how are the runtime values of the elements of the
>> sequence to be determined?

> Conceptually, I am thinking of a visitor that goes over the variant and
> flattens it.  In the above example, the corresponding sequence would be

>     [42, 4.2, 42, 4.2]

> which corresponds to a fusion::vector<int, double, int, double>.
> Practically, I don't see a way how to get the type of the vector at
> runtime unless knowing in advance the type of the fusion vector (which
> could be a potential assumption).

You have to know the type of the vector at compile time.

> I was also talking about "chopping" the variant in disjunct sequences.
> By this, I mean that a visitor goes over the variant and creates several
> sequences, say

>     [42]
>     [4.2, 42]
>     [42]

I think the easiest way is probably to create a runtime
iterator that walks over the vector and recurses into
any variants that it contains.  Then you can use fusion's
algorithms to iterate over the fusion::vector and the
vector in parallel.

> for the above example. That's the scenario I ultimately target. Ideally,
> these sequences are only views (tiers) of the original variant.

If you want it to be a view, you can use a fusion vector of references.

>> Depending on what you're doing, you might be able to use the nested
>> types typedef of variant, which is an MPL sequence.

> Are you referring to the variant<T>::types MPL sequence?

Yes.

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


    Переслать  
Чтобы отправлять сообщения, сначала необходимо Войти.
Чтобы отправлять сообщения, сначала необходимо присоединиться к группе.
Перед отправкой сообщения обновите свой псевдоним на странице Настройки подписки.
У вас нет разрешения на отправку сообщений.
Matthias Vallentin  
Просмотреть профиль   Перевести на Переведено (просмотреть оригинал)
 Дополнительные параметры 11 мар, 09:14
Автор: Matthias Vallentin <vallen...@icsi.berkeley.edu>
Дата: Wed, 10 Mar 2010 23:14:30 -0800
Местное время: Чт. 11 мар 2010 09:14
Тема: Re: [Boost-users] Variant and Fusion

On Wed, Mar 10, 2010 at 05:25:02PM -0800, Steven Watanabe wrote:
> You have to know the type of the vector at compile time.

Even if I know the type of the vector at compile time, how could I
create the fusion vector incrementally from the variant? Since push_back
always returns a new type, I don't know how to do this with a visitor.

> >I was also talking about "chopping" the variant in disjunct sequences.
> >By this, I mean that a visitor goes over the variant and creates several
> >sequences, say

> >    [42]
> >    [4.2, 42]
> >    [42]

> I think the easiest way is probably to create a runtime
> iterator that walks over the vector and recurses into
> any variants that it contains.  

> Then you can use fusion's
> algorithms to iterate over the fusion::vector and the
> vector in parallel.

I'm not sure if I can follow. If I start with the variant and have some
plan to partition it into sequences, how would I use an iterator rather
a visitor? Would you mind illustrating your idea with a small code
snippet?

   Matthias
--
Matthias Vallentin
vallen...@icsi.berkeley.edu
http://www.icir.org/matthias
_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


    Переслать  
Чтобы отправлять сообщения, сначала необходимо Войти.
Чтобы отправлять сообщения, сначала необходимо присоединиться к группе.
Перед отправкой сообщения обновите свой псевдоним на странице Настройки подписки.
У вас нет разрешения на отправку сообщений.
Steven Watanabe  
Просмотреть профиль   Перевести на Переведено (просмотреть оригинал)
 Дополнительные параметры 11 мар, 20:33
Автор: Steven Watanabe <watanab...@gmail.com>
Дата: Thu, 11 Mar 2010 10:33:39 -0800
Местное время: Чт. 11 мар 2010 20:33
Тема: Re: [Boost-users] Variant and Fusion
AMDG

Matthias Vallentin wrote:
>> I think the easiest way is probably to create a runtime
>> iterator that walks over the vector and recurses into
>> any variants that it contains.  

>> Then you can use fusion's
>> algorithms to iterate over the fusion::vector and the
>> vector in parallel.

> I'm not sure if I can follow. If I start with the variant and have some
> plan to partition it into sequences, how would I use an iterator rather
> a visitor? Would you mind illustrating your idea with a small code
> snippet?

Actually making an iterator is rather a pain.  It's probably easiest to copy
the variant into a flattened vector like this.

#include <boost/variant.hpp>
#include <vector>
#include <algorithm>

template<class Iter>
class visitor {
public:
    typedef void result_type;
    visitor(Iter& iter) : out(&iter) {}
    template<class T>
    void operator()(T& t) const {
        *(*out)++ = &t;
    }
    template<class T>
    void operator()(std::vector<T>& v) const {
        std::for_each(v.begin(), v.end(), boost::apply_visitor(*this));
    }
    Iter* out;

};

template<class V, class Iter>
Iter flatten_variant(V& v, Iter out) {
    boost::apply_visitor(visitor<Iter>(out), v);
    return out;

}

int main() {
    boost::make_recursive_variant<
        int,
        double,
        std::vector<boost::recursive_variant_>
    >::type v;
    std::vector<boost::variant<int*, double*> > temp;
    flatten_variant(v, std::back_inserter(temp));

}

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


    Переслать  
Чтобы отправлять сообщения, сначала необходимо Войти.
Чтобы отправлять сообщения, сначала необходимо присоединиться к группе.
Перед отправкой сообщения обновите свой псевдоним на странице Настройки подписки.
У вас нет разрешения на отправку сообщений.
Matthias Vallentin  
Просмотреть профиль   Перевести на Переведено (просмотреть оригинал)
 Дополнительные параметры 21 мар, 23:45
Автор: Matthias Vallentin <vallen...@icsi.berkeley.edu>
Дата: Sun, 21 Mar 2010 14:45:19 -0700
Местное время: Вс. 21 мар 2010 23:45
Тема: Re: [Boost-users] Variant and Fusion

On Thu, Mar 11, 2010 at 10:33:39AM -0800, Steven Watanabe wrote:
> Actually making an iterator is rather a pain.  It's probably easiest to copy
> the variant into a flattened vector like this.

I like this solution, thanks.

   Matthias
--
Matthias Vallentin
vallen...@icsi.berkeley.edu
http://www.icir.org/matthias
_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


    Переслать  
Чтобы отправлять сообщения, сначала необходимо Войти.
Чтобы отправлять сообщения, сначала необходимо присоединиться к группе.
Перед отправкой сообщения обновите свой псевдоним на странице Настройки подписки.
У вас нет разрешения на отправку сообщений.
Конец сообщений
« Назад к обсуждениям « Следующая тема     Предыдущая тема »

Создать группу - Группы Google - Главная страница Google - Условия предоставления услуг - Политика конфиденциальности
©2010 Google